Help batch file to move files in list to created subdirectory


  1. Posts : 5
    w10
       #1

    Help batch file to move files in list to created subdirectory


    Please excuse me in advance because I am not very experienced making batch files. I'm not asking for a free lunch and would gladly paypal someone some cash for a working batch file.

    I have a parent folder that contains several subfolders. Each subfolder has several files in them. I need a batch file to search all the folders starting from the parent folder for files contained in a list.txt file and if it finds a match create a new folder where each file was found and move the found file to that folder.

    File names in list.txt: (no extension)

    test1
    test2

    Before batch run:

    Parent
    |--Sub
    | |--test1.zip
    | |--foo.zip
    | |--foo1.zip
    | |--foo2.zip
    |
    |--Sub2
    | |--test2.zip
    | |--foo.zip
    | |--foo1.zip
    | |--foo2.zip

    After batch run:

    Parent
    |--Sub1
    | |--NewSub
    | | |--test1.zip
    | |
    | |--foo0.zip
    | |--foo1.zip
    | |--foo2.zip
    |
    |--Sub2
    | |--NewSub
    | | |--test2.zip
    | |
    | |--foo0.zip
    | |--foo1.zip
    | |--foo2.zip

    I have made every effort to do this on my own and keep failing.

    Thanks in advance.


    I've managed to get this to work but would like to make it create subfolders where the files are found. I would also like to use move instead of xcopy if possible.

    Code:
    for /f "delims=" %%i in (list.txt) do xcopy "C:\Users\BEAZLEYBUB\Desktop\New folder\New folder\%%i?" "C:\Users\BEAZLEYBUB\Desktop\New folder\Copied" /i /z /y /s
    pause
    Last edited by beazleybub; 18 Nov 2015 at 21:58.
      My Computer


  2. Posts : 721
    Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
       #2

    ​Hi Beazleybub, and welcome to SevenForums,

    Well I have just the batch file for you. Recently, another member asked for something similar: a batch script that would find a bunch of files given their filenames, in the form of a new-line separated text file list, and do something with those files.

    The script can be found here, post #2, and I'll give you a hint regarding what sort of options you should use:
    Code:
    set "output_folder=.\NewSub"
    set "default_mode=MOVE"
    set "include_folders=FALSE"
    set "silence_errors=FALSE"
    set "adapt_current_directory=TRUE"
    The rest should be self explanatory. One thing to note though, each filename entry in your text file list must have an extension, unlike in your example 'list.txt'.

    Good luck, Beazleybub.
      My Computer


  3. Posts : 5
    w10
    Thread Starter
       #3

    Hey, that's pretty nifty!!! I really think the adjustable options make the script very flexible! I really appreciate your help!

    I have one small issue though. Some of my filenames have spaces in them. Could you modify the script to allow this?

    :):):):) Cheers, Beazleybub
    Last edited by beazleybub; 19 Nov 2015 at 21:06.
      My Computer


  4. Posts : 721
    Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
       #4

    beazleybub said:
    I have one small issue though. Some of my filenames have spaces in them. Could you modify the script to allow this?
    The script already fully supports parsing filenames and manipulating files that have spaces in their name. Did you happen to find an issue relating to this? If so, please provide details.
      My Computer


  5. Posts : 5
    w10
    Thread Starter
       #5

    In my file list I have a filename called "foo bar.txt" and the first time I tried to run it the screen just blinked. I added a pause to your script to see what was going on. The message displayed was...

    Item 'foo' could not be located

    0 items were copied to directory '.\NewSub'
    Press any key to continue . . .

    It was missing the "bar"


    Thanks
      My Computer


  6. Posts : 721
    Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
       #6

    ​I was able to replicate and fix the issue you found, which was only a display issue with that particular error message. The script would still be unable to locate your file "foo bar.txt".

    Make certain the filenames listed in your text file list have extensions, for instance, specify "foo bar.txt" and not just "foo bar", or you may use wildcards, e.g. "foo bar.*".
      My Computer


  7. Posts : 5
    w10
    Thread Starter
       #7

    I'm sorry your response is a little confusing. You said you fixed the issue but, then say there can be no spaces in the filenames. I see no reason your script couldn't be edited to parse the list file with filenames that contain spaces. Anyhow, I still appreciate your input and script, they both were very useful.
      My Computer


  8. Posts : 721
    Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
       #8

    beazleybub said:
    You said [...] there can be no spaces in the filenames. I see no reason your script couldn't be edited to parse the list file with filenames that contain spaces.
    Nowhere in any post did I ever say or even come close to implying that my script doesn't support filenames containing space characters. I do recall, however, saying the exact opposite. In my post #4, I mention that filenames with spaces are fully supported by the script. Zero strings attached there, I assure you.

    To be crystal clear, in my previous post I had merely pointed out that there was a minor display error with one of the error messages, to which I've now fixed. This correction did not effect the algorithm of the script whatsoever.

    In your example where the script failed to find the file "foo bar.txt", the script genuinely could not locate a file named "foo bar.txt" on your filesystem, despite what the error message said about not being able to find "foo". The function that outputs the error message got passed the full name "foo bar.txt", but the function was instructed to only print the first argument (arguments delimited by space character). This is the 'issue' I have fixed.
      My Computer


  9. Posts : 5
    w10
    Thread Starter
       #9

    That is exactly what you said!

    From post #4...
    The script already fully supports parsing filenames and manipulating files that have spaces in their name.
    From post #6...
    Make certain the filenames listed in your text file list have extensions, for instance, specify "foo bar.txt" and not just "foo bar", or you may use wildcards, e.g. "foo bar.*".
    Do you not think the filename "foo bar" has a space in it?
    Stop ranting like a contestant from Project Runway and breathe.

    (wipes hands)
    Last edited by beazleybub; 21 Nov 2015 at 12:28.
      My Computer


  10. Posts : 721
    Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
       #10

    beazleybub said:
    That is exactly what you said!
    What is? Please be coherent.

    beazleybub said:
    Do you not think the filename "foo bar" has a space in it?
    You've got to be kidding, right? This shouldn't need to be questioned. There is a single, empty, well defined space between "foo" and "bar.txt", and as obvious as this appears, I can, if you wish, manage the effort to ask others to confirm this for you if you are truly unsure.

    Filenames and files with names containing spaces work just as flawlessly now with the script as files lacking space characters. What is with your disagreement in post #7?


    beazleybub said:
    Stop ranting like a contestant from Project Runway and breathe.
    I take all my works and projects seriously. I would not allow for anyone to experience an error caused by my mistake without a subsequent, apt explanation. If you are unsatisfied with practical solutions or other aid given to you, you should spend time gathering details and propose at least a constructive, meaningful response instead of insulting the person giving you assistance and wasting time engineering hypothetical similes to help your intentionally provoking endeavour. It wasn't 'rant' it was making a point clear, which clearly failed.

    beazleybub said:
    (wipes hands)
    Uber act of rudeness. I hope you enjoy your 100% free help.
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 05:56.
Find Us