Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ' Specify the source and target paths and the file format
- Dim sourcePath, targetPath, fileFormat
- sourcePath = "C:\source\path"
- targetPath = "D:\target\path"
- fileFormat = "*.png"
- ' Create FileSystemObject
- Dim fso
- Set fso = CreateObject("Scripting.FileSystemObject")
- ' Ensure target directory exists
- If Not fso.FolderExists(targetPath) Then
- fso.CreateFolder(targetPath)
- End If
- ' Function to recursively search and process files
- Sub ProcessFolder(folder)
- Dim subFolder
- For Each subFolder In folder.SubFolders
- ProcessFolder subFolder
- Next
- Dim file, fileName, targetFile
- For Each file In folder.Files
- If LCase(fso.GetExtensionName(file.Name)) = "png" Then
- counter = counter + 1
- fileName = counter & ".png"
- targetFile = fso.BuildPath(targetPath, fileName)
- file.Move targetFile
- End If
- Next
- End Sub
- ' Counter for file renaming
- Dim counter
- counter = 0
- ' Start processing
- Dim rootFolder
- Set rootFolder = fso.GetFolder(sourcePath)
- ProcessFolder rootFolder
- WScript.Echo "Files transferred and renamed."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement