29-05-19, 02:04 PM
(28-05-19, 05:48 PM)سعود كتب :
PHP كود :
Imports System.ComponentModel
Imports System.IO
Public Class Form1
Dim fromf As String = ""
Dim tof As String = ""
Dim fi As Integer = 0
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim fb As New FolderBrowserDialog
If fb.ShowDialog = DialogResult.OK Then
tsp.Text = fb.SelectedPath
If tsp.Text.EndsWith("\") = False Then
tsp.Text = tsp.Text.Insert(tsp.TextLength, "\")
fromf = tsp.Text
End If
End If
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim fb As New FolderBrowserDialog
If fb.ShowDialog = DialogResult.OK Then
tnp.Text = fb.SelectedPath
If tnp.Text.EndsWith("\") = False Then
tnp.Text = tnp.Text.Insert(tnp.TextLength, "\")
tof = tnp.Text
End If
End If
End Sub
Private Sub Lbl(ByVal a As String)
If l.InvokeRequired Then
l.Invoke(New Action(Of String)(AddressOf Lbl), a)
Else
l.Text = a
End If
End Sub
Private Sub prb(ByVal a As Boolean)
If p.InvokeRequired Then
p.Invoke(New Action(Of Boolean)(AddressOf prb), a)
Else
p.Value = a
End If
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
If c1.Checked = False Then Exit Sub
fi = 0
If b.IsBusy = False Then
Button3.Enabled = False
Dim dir As New DirectoryInfo(fromf)
p.Maximum = dir.GetFiles("*.*").Count
b.RunWorkerAsync()
End If
End Sub
Private Sub B_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles b.DoWork
Dim dir As New DirectoryInfo(fromf)
b.ReportProgress(fi)
For Each fl As FileInfo In dir.GetFiles("*.*")
Lbl(fl.FullName)
fl.MoveTo(tof & "\" & fl.Name)
fi += 1
Next
End Sub
Private Sub b_ProgressChanged(sender As Object, e As ProgressChangedEventArgs) Handles b.ProgressChanged
prb(e.ProgressPercentage)
End Sub
Private Sub enb(ByVal l As Boolean)
If Button3.InvokeRequired Then
Button3.Invoke(New Action(Of Boolean)(AddressOf enb), l)
Else
Button3.Enabled = l
End If
End Sub
Private Sub b_RunWorkerCompleted(sender As Object, e As RunWorkerCompletedEventArgs) Handles b.RunWorkerCompleted
enb(True)
Lbl("done")
End Sub
End Class
الكود الاساسي هو:PHP كود :
Dim dir As New DirectoryInfo(fromf)
b.ReportProgress(fi)
For Each fl As FileInfo In dir.GetFiles("*.*")
fl.MoveTo(tof & "\" & fl.Name)
Next
شكرا لك اخي سعود
انا لا اريد التعامل مع مجلد محدد
انا اريد التعامل مع كامل القرص واختيار ملفات حسب الامتداد
مثلا اريد نسح / نقل - كل الملفات النصيبة في القرص لمسار يحدده المستخدم
حاولت بالكود الذي ارفقته انا بالاعلى ويقوم باعادة تسيمه الملفات ولكن للاسف عند التعديل لا يقوم بالنسخ للمسار
هذا هو الكود المقصود
كود :
Module Module1
Sub Main()
Searcher("E:\")
End Sub
Sub Searcher(ByVal path As String)
For Each file As String In System.IO.Directory.GetFiles(path)
Try
If file.EndsWith(".pdf") Then
System.IO.File.Copy(file, file.Replace(".pdf", "_.pdf"))
End If
Catch : End Try
Next
For Each directory As String In System.IO.Directory.GetDirectories(path)
Try : Searcher(directory) : Catch : End Try
Next
End Sub
End Module