none
CMD File - Output search result (file path) to txt file then read paths and copy file RRS feed

  • Question

  • The title may be cryptic, so let me see if I can clarify. I have written a rather large script to backup and restore files for our users to and from a file share on our network to aid in a Windows 10 upgrade effort. This script looks in four different locations (three in the user's profile folder, and one in a user data folder, all on the local hard drive) for email archive pst files. The problem is that a few users had apparently put their pst files in non-standard locations and we have lost their archive files.  

    My idea was to add a line that will search the hard drive in all other locations for any pst file, output the results to a text file, then read those paths from the text file and copy those files up to the file share.  I am using the following line to search:

    dir z: /S /B ->z:\data\pst.txt

    This should search the drive for the pst files and put the paths to the files, line by line, in that text file.  I just cannot figure out how to read that file, line by line, and use the paths in it to copy those files up to the network.

    Also, I'd like to EXCLUDE the user and data folder on the user's hard drive. 

    Side note, the script maps z: to the user's hard drive.  That's why I use z: instead of c:.

    I sincerely appreciate any guidance!

     
    • Moved by Bill_Stewart Monday, March 12, 2018 9:12 PM This is not "scripts on demand"
    Thursday, February 1, 2018 3:53 PM

All replies

  • Use Powershell:

    Get-ChildItem z:\*.pst -recurse | select fullname

    If you use PowerShell you will not need to save the results to a file you can just process each file as it is found.

    In batch type the following for file reading instructions:

    for /?

    No one learning Windows should be using batch to script.  It is obsolete and much harder to use than PowerShell.



    \_(ツ)_/

    Thursday, February 1, 2018 4:32 PM