Public Sub Move_Files_To_Matching_Folder()
Dim sourceFolder As String, destMainFolder As String, destSubfolder As String
Dim FSO As Object
Dim FSfile As Object
Dim FSsourceFolder As Object
sourceFolder = Environ$("USERPROFILE") & "\Downloads\"
destMainFolder = Environ$("USERPROFILE") & "\Pictures\"
If Right(sourceFolder, 1) <> "\" Then sourceFolder = sourceFolder & "\"
If Right(destMainFolder, 1) <> "\" Then destMainFolder = destMainFolder & "\"
Set FSO = CreateObject("Scripting.FileSystemObject")
Set FSsourceFolder = FSO.GetFolder(sourceFolder)
For Each FSfile In FSsourceFolder.Files
destSubfolder = destMainFolder & Left(FSfile.Name, InStrRev(FSfile.Name, ".") - 1) & "\"
If FSO.FolderExists(destSubfolder) Then
If FSO.FileExists(destSubfolder & FSfile.Name) Then FSO.DeleteFile destSubfolder & FSfile.Name, True
FSfile.Move destSubfolder
End If
Next
End Sub
this script give me john this is perfctly working but i have a some problm i want to change the desination folder how i can chage beacuse i'll try like this destMainFolder = Environ$("USERPROFILE") & "\Employee file\" but this not working any body help me
Dim sourceFolder As String, destMainFolder As String, destSubfolder As String
Dim FSO As Object
Dim FSfile As Object
Dim FSsourceFolder As Object
sourceFolder = Environ$("USERPROFILE") & "\Downloads\"
destMainFolder = Environ$("USERPROFILE") & "\Pictures\"
If Right(sourceFolder, 1) <> "\" Then sourceFolder = sourceFolder & "\"
If Right(destMainFolder, 1) <> "\" Then destMainFolder = destMainFolder & "\"
Set FSO = CreateObject("Scripting.FileSystemObject")
Set FSsourceFolder = FSO.GetFolder(sourceFolder)
For Each FSfile In FSsourceFolder.Files
destSubfolder = destMainFolder & Left(FSfile.Name, InStrRev(FSfile.Name, ".") - 1) & "\"
If FSO.FolderExists(destSubfolder) Then
If FSO.FileExists(destSubfolder & FSfile.Name) Then FSO.DeleteFile destSubfolder & FSfile.Name, True
FSfile.Move destSubfolder
End If
Next
End Sub
this script give me john this is perfctly working but i have a some problm i want to change the desination folder how i can chage beacuse i'll try like this destMainFolder = Environ$("USERPROFILE") & "\Employee file\" but this not working any body help me