A script for copying certain files in sub-folders to a new location RRS feed

  • Question

  • Hi,

    I found this great script on to your site but is there anyway you can make the source path a variable i.e C:\CDData\7300000001 so the the 7300000001 can be the part read from the file as this changes each day.

    Also can it search sub-folders aswell as the primary folder e.g C:\CDData\7300000001\001, C:\CDData\7300000001\002 etc

    Below is the code I found, any help will be appricaited.

    OptionExplicit' The source path for the copy operation.Const strSourceFolder = "H:"' The target path for the copy operation.Const strTargetFolder = "C:\Temp\Target\"

    ' The list of files to copy. Should be a text file with one file on each row. No paths - just file name.
    Const strFileList = "C:\filelist.txt"' Should files be overwriten if they already exist? TRUE or FALSE.Const blnOverwrite = FALSE

    objFSO Set objFSO = CreateObject("Scripting.FileSystemObject") Const ForReading = 1 Dim objFileList Set objFileList = objFSO.OpenTextFile(strFileList, ForReading, False) Dim strFileToCopy, strSourceFilePath, strTargetFilePath OnErrorResumeNextDoUntil objFileList.AtEndOfStream ' Read next line from file list and build filepaths strFileToCopy = objFileList.Readline strSourceFilePath = objFSO.BuildPath(strSourceFolder, strFileToCopy) strTargetFilePath = objFSO.BuildPath(strTargetFolder, strFileToCopy)
    ' Copy file to specified target folder. Err.Clear objFSO.CopyFile strSourceFilePath, strTargetFilePath, blnOverwrite If Err.Number = 0 Then
    ' File copied successfully
    ' Error copying file Wscript.Echo "Error " & Err.Number & " (" & Err.Description & "). Copying " & strFileToCopy EndIf


    • Moved by Bill_Stewart Monday, July 30, 2018 1:46 PM This is not "scripts on demand"
    Monday, June 11, 2018 6:19 AM