Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 9th Feb 2010, 10:03 PM   #1
Senior Warrior Member
War Room Member
 
Frank Bruno's Avatar
 
Join Date: 2003
Location: USA
Posts: 1,004
Thanks: 6
Thanked 86 Times in 65 Posts
Blog Entries: 1
Default
Anybody know .Bat syntax to move files and folders?
Share on: 
fb share twitter share gplus share more share

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
Frank Bruno is offline  
Unread 9th Feb 2010, 10:44 PM   #2
Senior Warrior Member
War Room Member
 
Frank Bruno's Avatar
 
Join Date: 2003
Location: USA
Posts: 1,004
Thanks: 6
Thanked 86 Times in 65 Posts
Blog Entries: 1
Default
Re: Anybody know .Bat syntax to move files and folders?
Share on: 
fb share twitter share gplus share more share

Oh forgo, this would be for a windows XP OS

Frank Bruno
Frank Bruno is offline  
Unread 17th Feb 2010, 05:29 AM   #3
HyperActive Warrior
 
Join Date: 2008
Location: USA
Posts: 250
Thanks: 9
Thanked 29 Times in 27 Posts
Blog Entries: 22
Default
Re: Anybody know .Bat syntax to move files and folders?
Share on: 
fb share twitter share gplus share more share

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.

awesometbn is offline  
Unread 17th Feb 2010, 10:46 PM   #4
Advanced Warrior
War Room Member
 
Bruce Hearder's Avatar
 
Join Date: 2004
Location: Perth, Australia.
Posts: 724
Thanks: 6
Thanked 184 Times in 136 Posts
Default
Re: Anybody know .Bat syntax to move files and folders?
Share on: 
fb share twitter share gplus share more share

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
Bruce Hearder is offline  
Closed Thread


Bookmarks

Tags
bat, files, folders, move, syntax


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 01:40 PM.