I am making application that sends all the programs (.exe) into a created folder on the current directory.
The application is setup by first creating a folder at the push of a button.
Next, a try catch is used to send all of the .exe files into the new folder.

Below is some of the source code, I want to know how make an exception for this running application .

Any hints?

Dim myPathsix As String = IO.Path.Combine(My.Computer.FileSystem.CurrentDirectory, "Cleanup/Programs")
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")
count = ++count

My.Computer.FileSystem.MoveFile(foundFile2, myPathsix & "/" & IO.Path.GetFileName(foundFile2))

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| (All Files (*.*)|*.*"

End If
End Try
'I want to add another Try/Catch or a nested Try/Catch to catch the currently running program " WHATEVER.exe" 'or this application' as an exception, so it does not move from its currently stationed directory

Member Avatar

do you want him to look for what .exe he is moving or?

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.