Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi,
I was hoping someone could help me with my request? I'm looking for a VBScript that would perform the following:
Scan files (with exact full file name) in "FirstFolder" and if duplicate is found in archive folder "SecondFolder" then a
window pops up with a message dictating so and with a "created on" field of when (date and time) the file was originally created in archive (SecondFolder) folder. Does anyone have any scripts already created for something like this? Any help would be greatly appreciated.Thank you!

This is what I have, it's close, but doesn't quite do what I need above:
Dim fso, rootfolder, subfolder, subfolders
Dim objRegEx' Create FileSystemObject
Set fso = CreateObject("Scripting.FileSystemObject")'Get the Starting Folder
Set rootfolder= fso.GetFolder("c:\temp") 'Change the file location'Get All the SubFolders in Root
Set subfolders = rootfolder.SubFolders
Set objRegEx = CreateObject("VBScript.RegExp")
objRegEx.Pattern = "^\D+\d+$" 'I'm not sure the correct syntax for all characters in filename
objRegEx.IgnoreCase = True
objRegEx.Global = False'Loop through all the folders
For Each subfolder in subfolders
if objRegEx.Test(subfolder.Name) then
WScript.Echo "Code would delete " & subfolder.Name
'subfolder.Delete
end if
Next'Clean up
Set objRegEx = Nothing
Set fso = Nothing

Well, it's a nice first attempt.
const fromDir = "c:\FirstFolder" const toDir = "c:\SecondFolder" WScript.Quit Main() Sub FindFiles(ByRef list, fso, path, basePathLen) If basePathLen = 0 Then basePathLen = Len(path) + 1 If Right(path, 1) <> "\" Then _ basePathLen = basePathLen + 1 End If For Each f In fso.GetFolder(path).Files list.Add Mid(f.Path, basePathLen), f.DateCreated Next 'f For Each d In fso.GetFolder(path).SubFolders FindFiles list, fso, d.Path, basePathLen Next 'd End Sub Function Main Main = 1 Set fso = CreateObject("Scripting.FileSystemObject") Set fromList = CreateObject("Scripting.Dictionary") Set toList = CreateObject("Scripting.Dictionary") FindFiles fromList, fso, fromDir, 0 FindFiles toList, fso, toDir, 0 For Each f In fromList If toList.Exists(f) Then _ WScript.Echo "Code would delete " & f & " (Created: " & toList(f) & ")" Next 'f Main = 0 End Function

This works perfectly Razor! One last thing, what if the files in "firstfolder" do not match any files in "secondfolder" and because they don't match I want to move the files from "firstfolder" to let's say "thirdfolder"? I was trying to do an "else" or "elseif" after "If toList.Exists(f) Then _" but I'm thinking that didn't work because I'm inside a Function?

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |