Dim myPathsix As String = IO.Path.Combine(My.Computer.FileSystem.CurrentDirectory, "Cleanup/Programs")
IO.Directory.CreateDirectory(myPathsix)
Dim count As Integer = 1
If Not IO.Directory.Exists(myPathsix) Then IO.Directory.CreateDirectory(myPathsix) '// create if it does not exist.
For Each foundFile2 As String In My.Computer.FileSystem.GetFiles _
(My.Computer.FileSystem.CurrentDirectory, _
FileIO.SearchOption.SearchTopLevelOnly, "*.exe" & "*.pl" & "*.jar" & "*.zip" & "*.rar")
count = ++count
Try
My.Computer.FileSystem.MoveFile(foundFile2, myPathsix & "/" & IO.Path.GetFileName(foundFile2))
Catch
If My.Computer.FileSystem.FileExists(foundFile2) Then
MsgBox("File: " & foundFile2 & " already belongs to the: " & myPathsix & " directory. Please, choose a directory to move it to")
SaveFileDialog1.InitialDirectory = myPath
SaveFileDialog1.FileName = foundFile2.Replace(".exe", ++count & ".exe")
SaveFileDialog1.Filter = "Programs (*.exe)|*.exe| (*.jar)|*.jar|(*.pl)|*.pl|(*.rar)|*.rar|(*.zip)|*.zip| (All Files (*.*)|*.*"
SaveFileDialog1.ShowDialog()
My.Computer.FileSystem.DeleteFile(foundFile2)
End If
End Try
'**************************************************************************************
'I want to add another Try/Catch to catch the currently running program " WHATEVER.exe" 'or [B]this application[/B]
'as an exception, so it does not move from its currently stationed directory
'**************************************************************************************
Next
m1234ike 0 Light Poster
Huntondoom
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.