batch file request


  1. Posts : 6
    Windows 7 Ultimate X64
       #1

    batch file request


    Hi, don't know if anyone has any ideas on this, but here goes - I have a removeable drive with over 100,000 karaoke zip files. Currently, a typical path is "T:\karaoke\soundchoice\100x". That folder may contain 1000's of zip files, and may even be broken down into more folders. I want all the zip files to be on the path "T:\example.zip" so that I can set up my own filing system and also edit files where needed. This involves moving the zip files out of their current folder (ex - "T:\karaoke\soundchoice\100x") and putting them directly onto the "T:" path, then deleting the now empty folders.

    I would like a batch file to do the above. Thank you.
      My Computer


  2. Posts : 6,285
    Windows 10 Pro X64
       #2

    First, are you sure there are no naming conflicts? If any of them have the same name then they can't both be in the same folder.

    If you are sure that is okay, I believe xcopy from a Command Prompt can do what you want.

    xcopy t:\*.zip t:\example.zip\ /s/r/i/k/e

    Enter xcopy /? from a Command Prompt to see what the options mean and what others are available.

    I've not tested this but I believe it will work. Give it a try. To test, add /p so it will prompt you before creating each destination file.
      My Computer


  3. Posts : 6
    Windows 7 Ultimate X64
    Thread Starter
       #3

    Thanks, this did work. I had to change directory because copying to same folder gave me a "cannot cyclic copy" error, but at least I got all the files out and could then copy just the zips back to the original directory. It is too bad that the MOVE command is not as versatile as xcopy, I could have used that. Again, thanks.
      My Computer


  4. Posts : 6
    Windows 7 Ultimate X64
    Thread Starter
       #4

    ok, I'm back - copy finished. The cmd utility copied all the zip files that I already had under T:\, but it copied all the directories and subs (which I now see per the switches, this is what I was asking it to do) I need the directories and subs to NOT be copied, just the zip files. Any further ideas?
      My Computer


  5. Posts : 6,285
    Windows 10 Pro X64
       #5

    I have an idea for a batch file. Playing with it now, will post in a little while.
      My Computer


  6. Posts : 6,285
    Windows 10 Pro X64
       #6

    Okay, here is what I've come up with. I tested it and it works for me.
    Code:
    @echo off
    rem %1 - root to start copying from
    rem %2 - target to copy files to
    rem
    rem
    rem Uses dir /b /s parm1 > copydown.txt to create list of files to be copied
    rem Reads the file one record at a time and copies each file listed to Pam2
    
    if .%1 equ . goto :help
    if .%2 equ . goto :help
    
    rem Get list of files to be copied. /b tosses all header info
    dir /b /s %1% > copydown.txt
    
    for /f "tokens=*" %%a in (copydown.txt) do (
     echo copy "%%a" "%2%"
          copy "%%a" "%2%"
    )
    
    goto :done
    
    :help
    echo This command requires two parameters, P1 and P2
    echo P1 is the root of the source driectory tree you want to copy files (not folders) from.
    echo P2 is the target you want the files copied to.
    echo .
    echo copydown p1 p2
    echo .
    echo Example:   copydown d:\temp\*.* d:\tmp2\
    echo .
    echo Note the trailing slash at the end of P2, it's required.
    echo P1 and P2 can not point to the same directory.
    echo .
    echo This will copy all files in d:\temp and all it's subdirectories to d:\tmp2
    echo Sub-directories are disacrded, only the files are copied.
    
    :done
    Copy the above and paste it into copydown.bat.
    From a Command Prompt, enter copydown with no parameters to see the very brief help.

    I tried it exactly as shown. In d:\temp I have 41 directories and a total of 207 files.
    d:\tmp2 is empty.
    After running the batch file, d:\tmp2 has 207 files and no directories.
      My Computer


  7. Posts : 6
    Windows 7 Ultimate X64
    Thread Starter
       #7

    Thank you very much, this worked perfectly. I appreciate that someone with a lot of tech know-how spent the time to figure this out for someone else.

    Since I am also trying to learn, would you mind explaining the programming? I get the "dir" cmd, to bring up the files and get rid of the headers and send to copydown.txt. Could you break down the "for" cmd remarks? Especially the first line, I get that after that you are copying what came up to the screen and the destination. I also read "for" help, I just would like it explained a bit more in layman terms so I can understand more of what it is doing. Again, thank you.
      My Computer


  8. Posts : 6,285
    Windows 10 Pro X64
       #8

    Read this article, see if it helps. Batch files - The FOR command: Windows NT 4/Windows 2000 Syntax

    Basically though, tokens=* means the entire line of data is passed to the body of the FOR loop.
    tokens=1,2* would mean the first delimited word frm the line would be the first token, the second the second and the rest the third.

    At least I think that's how it works.
      My Computer


  9. Posts : 6
    Windows 7 Ultimate X64
    Thread Starter
       #9

    Just wanted to say a final thank you, this helped me solve the problem and understand how to solve similar problems in the future on my own.
      My Computer


  10. Posts : 6,285
    Windows 10 Pro X64
       #10

    You're welcome. AS I said, this is fun to me. Glad you problem is solved.

    Peace
      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 09:11.
Find Us