I had a previous question where I needed to search a single folder for the 3 latest files in that folder then copy those 3 files to a new folder - this question got answered and the thread can be found here:
The next issue I have now is:
1) I have a main folder with 20 sub-folders
2) Everyday around 7AM, a new csv extract is added to each sub-folder
2) I need to search through each individual sub-folder and find the latest (the current days) file added to that sub-folder
3) I then need to copy each individual file from its respective sub-folder and place ALL the files in ONE folder - there's no chance of the filenames ever being the same
4) The filename structure is Date_Filename
The code in the link above can solve my issue, but then I would have 20 scripts to run which I think is really unnecessary.
I found the code below that could help with what I need to do but I do not know how to amend the code so that I can simply double click to run the vbs file instead of having to use cscipt in cmd to execute it. As of yet, I havent been able to test this code either...
The next issue I have now is:
1) I have a main folder with 20 sub-folders
2) Everyday around 7AM, a new csv extract is added to each sub-folder
2) I need to search through each individual sub-folder and find the latest (the current days) file added to that sub-folder
3) I then need to copy each individual file from its respective sub-folder and place ALL the files in ONE folder - there's no chance of the filenames ever being the same
4) The filename structure is Date_Filename
The code in the link above can solve my issue, but then I would have 20 scripts to run which I think is really unnecessary.
I found the code below that could help with what I need to do but I do not know how to amend the code so that I can simply double click to run the vbs file instead of having to use cscipt in cmd to execute it. As of yet, I havent been able to test this code either...
Code:
'Variables -----
'"\Desktop\3rd Party\" ' Folder Source to check for recent files to copy FROM
'"\Desktop\3rd Party\New folder\" ' Destination Folder where to copy files TO
Const ForReading = 1
Const ForWriting = 2
Set objArgs = WScript.Arguments
If objArgs.Count < 2 Then
MsgBox "Missing argument <source_path> <target_path>"
WScript.Quit
End If
strSrcPath = objArgs(0)
strDestPath = objArgs(1)
Call CopyFolderRecursively(strSrcPath, strDestPath)
msgbox "done"
Sub CopyFolderRecursively(strSrcPath, strDestPath)
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objCurrentFolder = objFSO.GetFolder(strSrcPath)
For Each objFile In objCurrentFolder.Files
' Create new folder if it's not there
If Not objFSO.FolderExists(strDestPath) Then objFSO.CreateFolder(strDestPath)
strDestFile = strDestPath & "\" & objFile.Name
' do a direct copy here
objFSO.CopyFile objFile, strDestFile
Next
For Each objFolder In objCurrentFolder.subFolders
Call CopyFolderRecursively(objFolder, strDestPath & "\" & objFolder.Name)
Next
End Sub