hello experts i need your help please understand my problem i have thousand of file with diffrents extention like (jpg.pdf.chrome.outloolk mail) and i want to move them into the folder with the match of first 5 to 6 digit code to the folder.
my file name are like this..
09437 experience letter
04298 experience letter
07897 contract letter
00058 Bsc dgree
CO4298 experience letter
C02142 certificate
my folder name are like this
09437 john
04298 alberto
07897 micheal
00058 christopher
C04298 jackson
C02142 polard
iam try this code but its not working fine this script create new folder with same name of file but i have already created i want just read this code not read full name if file code match with folder code then move file into the folder.
script are given below..
Sub CopyFiles()
'Declare variables
Dim FSO As Object
Dim SourceFolder As Object
Dim DestinationFolder As Object
Dim File As Object
'Set the source and destination folders
Set FSO = CreateObject("Scripting.FileSystemObject")
Set SourceFolder = FSO.GetFolder("c:\users\employee.records\desktop\shariq")
Set DestinationFolder = FSO.GetFolder("D:\employee.records\desktop\back up by immad")
'Loop through all the files in the source folder
For Each File In SourceFolder.Files
'Extract the file name without the extension
Dim FileNameWithoutExtension As String
FileNameWithoutExtension = FSO.GetBaseName(File.Name)
'If a folder with the same name as the file doesn't exist in the destination folder, create it
If Not FSO.FolderExists(DestinationFolder & "\" & FileNameWithoutExtension) Then
Set DestinationSubFolder = FSO.CreateFolder(DestinationFolder & "\" & FileNameWithoutExtension)
Else
'If the folder already exists, set it as the destination folder
Set DestinationSubFolder = FSO.GetFolder(DestinationFolder & "\" & FileNameWithoutExtension)
End If
'Copy the file to the destination folder
File.Copy DestinationSubFolder & "\" & File.Name
Next
End Sub
my file name are like this..
09437 experience letter
04298 experience letter
07897 contract letter
00058 Bsc dgree
CO4298 experience letter
C02142 certificate
my folder name are like this
09437 john
04298 alberto
07897 micheal
00058 christopher
C04298 jackson
C02142 polard
iam try this code but its not working fine this script create new folder with same name of file but i have already created i want just read this code not read full name if file code match with folder code then move file into the folder.
script are given below..
Sub CopyFiles()
'Declare variables
Dim FSO As Object
Dim SourceFolder As Object
Dim DestinationFolder As Object
Dim File As Object
'Set the source and destination folders
Set FSO = CreateObject("Scripting.FileSystemObject")
Set SourceFolder = FSO.GetFolder("c:\users\employee.records\desktop\shariq")
Set DestinationFolder = FSO.GetFolder("D:\employee.records\desktop\back up by immad")
'Loop through all the files in the source folder
For Each File In SourceFolder.Files
'Extract the file name without the extension
Dim FileNameWithoutExtension As String
FileNameWithoutExtension = FSO.GetBaseName(File.Name)
'If a folder with the same name as the file doesn't exist in the destination folder, create it
If Not FSO.FolderExists(DestinationFolder & "\" & FileNameWithoutExtension) Then
Set DestinationSubFolder = FSO.CreateFolder(DestinationFolder & "\" & FileNameWithoutExtension)
Else
'If the folder already exists, set it as the destination folder
Set DestinationSubFolder = FSO.GetFolder(DestinationFolder & "\" & FileNameWithoutExtension)
End If
'Copy the file to the destination folder
File.Copy DestinationSubFolder & "\" & File.Name
Next
End Sub