So i am developing an Desktop cleaner which moves the items depending on the extension to an specific directory (the one that is being cleaned)
The user defines the names of the folder which the items will be placed.
But the code to move the files doesn’t work properly.
Private Sub FlowButton1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FlowButton1.Click
If CheckBox1.Checked Then
Dim folderPathTextBox = options.TextBox1.Text
Dim files() As String
files = System.IO.Directory.GetFiles(options.FolderBrowserDialog1.SelectedPath, "*.txt")
For Each file As String In files
System.IO.File.Copy(file, options.TextBox1.Text & options.TextBox8.Text & options.TextBox2.Text & System.IO.Path.GetFileName(file))
Next
Else
End If
-
options.TextBox1.Text= Directory selected using Folder dialog E.G: “C:\directory” -
options.TextBox8.Text= slash to separate = “C:\directory\” -
options.TextBox2.Text= Folder name determined by user E.G Images = “C:\directory\images”
I also want the code to check if the folder exist if not create it .
Thanks any help is appreciated
Some ideas to help you organize/simplify your code:
TextBox‘es properly. If you cannot do it, declare meaningful local variables and use that in code. It would greatly improve readability.C:\directoryandImagestogether. Get rid ofTextBox8.I think you can safely dropSystem.IO.Path.GetFileName(file)part as well, should be able to just use directory as a copy target.File.Copyexpects a file name as a second parameter. You would need to usePath.Combineoverload that accepts 3 parameters, and combine base path + user specified folder + the file name.Overwriting a file of the same name is not allowed.