Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

BAT file 'for each' command

  • 07-02-2008 06:31PM
    #1
    Registered Users, Registered Users 2 Posts: 2,364 ✭✭✭


    I want to copy every text file from one directory to another then delete all the files in the original directory
    This will do it:
    copy "E:\dirA\*.txt" "E:\dirB\"
    del "E:\dirA\*.txt"

    but if any .txt files get put into dirA between the two commands then they will be lost as they wouldn't be copied.
    So I really need to copy and delete them one at a time. Anyone have any ideas how to go about doing that?


Comments

  • Registered Users, Registered Users 2 Posts: 1,346 ✭✭✭carveone


    I want to copy every text file from one directory to another then delete all the files in the original directory
    This will do it:
    copy "E:\dirA\*.txt" "E:\dirB\"
    del "E:\dirA\*.txt"

    but if any .txt files get put into dirA between the two commands then they will be lost as they wouldn't be copied.
    So I really need to copy and delete them one at a time. Anyone have any ideas how to go about doing that?

    Windows XP has extended the batch file command set rather but...
    The old way would be:

    cd e:\dirA
    for %a in (*.txt) do c:\temp\copydel %a e:\dirB

    and then have a batch file called copydel.bat that takes two
    arguments etc etc...

    Or just use "move"!!!

    move e:\dira\*.txt e:\dirb

    Conor.


  • Registered Users, Registered Users 2 Posts: 2,364 ✭✭✭Mr. Flibble


    Cheers carveone. I was copying over different drives so I just presumed move would copy them. But it does delete the old files too, so that works great. Thanks.


Advertisement