Anybody know .Bat syntax to move files and folders?

3 replies
Hey techie programming gurus....

Was hoping one of you would chime in here with your wisdom to assist a dumbass warrior...

I have about 400 folders with a text file called Final.txt residing in each folder.


C:\Folder\birds\Final.txt
C:\Folder\cats\Final.txt
C:\Folder\dogs\Final.txt
C:\Folder\mouse\Final.txt
C:\Folder\tiger\Final.txt

I need to make a copy of each Final.txt file and rename this file so it correspond to each folder name and have these folders saved in another location.

Like this...

C:\FolderB\birds\birds-Final.txt
C:\FolderB\cats\cats-Final.txt
C:\FolderB\dogs\dogs-Final.txt
C:\FolderB\mouse\mouse-Final.txt
C:\FolderB\tiger\tiger-Final.txt

Does anybody know the syntax to use in a .bat dos file to do this?

Thanks guys!
Frank Bruno
#bat #files #folders #move #syntax
  • Profile picture of the author Frank Bruno
    Oh forgo, this would be for a windows XP OS

    Frank Bruno
    {{ DiscussionBoard.errors[1733317].message }}
  • Profile picture of the author awesometbn
    Take a look at the "for in do" loop. Since your folder names become the new file names, you can create a variable as a placeholder for each folder and file. You can take this in stages or enter all 400 names at once. It will look something like this . . .

    Code:
    @echo off
    cls
    echo.
    echo Copying files now . . .
    echo.
    for %a in (birds cats dogs mouse tiger) do copy C:\Folder\%a\Final.txt C:\FolderB\%a\%a-Final.txt
    echo.
    echo Done!
    But you'll have to research further to get the exact syntax. IIRC you might have to enter the variable like %%a instead of %a. Let us know what you figure out. Thanks.
    {{ DiscussionBoard.errors[1762264].message }}
  • Profile picture of the author Bruce Hearder
    If you want to move files from one location to another, you could try the

    MV command instead of COPY in the above example.

    Take care

    Bruce
    {{ DiscussionBoard.errors[1765465].message }}

Trending Topics