.bat file (move folders)

Soldato
Joined
28 Sep 2004
Posts
3,128
Location
Devon, UK
Hi, I'm wanting to create a .bat file to move folders from a directory on one pc to another directory on another pc thats on the network. Everything is shared that needs to be.

What I want to be able to do is have this .bat file so when I click on it I enter the name of the folder or wildcard (e.g folder is called Time of day and i'd enter something like Time of*) that I want to move across the network and then it does it for me.

I know it might seem lazy but when you have loads of folders to move its just something to make life abit easier.

Any ideas or scripts please? Have searched around but not been able to find anything on the 'enter name' bit

Thanks,
Mark
 
Here you go. Change 'C:\' to your network path. It loops so you can move multiple fiolders without having to run the file again and again, press 'x' to exit.

It doesn't work with wildcards, however if you press TAB it will auto-complete the folder name for you. Let me know if you have any problems.

@Echo OFF
:START
CLS
SET Choice =
SET /P Choice=Enter the folder name to move or x to Exit:
IF NOT '%Choice%'=='' MOVE %Choice% C:\
IF '%Choice%'=='x' GOTO END
GOTO START
:END
 
Thanks for that, but for some reason when I enter the folder name and press enter nothing happens :confused:

Cheers for the script though :)
 
I would instead, have a seperate .txt file with the folders you wish to move. the code is assuming the BAT file is in the same directory as the folder, but can obviously be changed in the *.txt file.

For the example i am assuming you already have network share access, if you don't you will need to add a net use * command to auth first.

Simply add the folder name(s) to the text file, and run the script. It even outputs it's errors/successful to Results.txt.

Code:
@echo off
for /f %%i in (FoldersToMove.txt) do (
   Echo Moving Folder %%i >>Results.txt
   Move C:\myfolder \\computer2\c$\myfolder >>Results.txt
   Echo.
)
 
Last edited:
Thanks will try that!

Not to be awkward but really was looking for an on the fly transfer. Else its quicker for me to Cut and Paste the folder.

RobH's would have been perfect but it doesn't seem to work :(
 
MarkLP said:
Thanks will try that!

Not to be awkward but really was looking for an on the fly transfer. Else its quicker for me to Cut and Paste the folder.

RobH's would have been perfect but it doesn't seem to work :(

Are you running the batch file from the same folder your moving stuff from? Because a folder called "New Folder" is only valid in the context of the working directory.

If that is not the case you'd need to change the the following line:

IF NOT '%Choice%'=='' MOVE C:\WorkingDirectory\%Choice% C:\

where "C:\WorkingDirectory\" is the path to the folder containing the folders you want to move.
 
RobH said:
Are you running the batch file from the same folder your moving stuff from? Because a folder called "New Folder" is only valid in the context of the working directory.

If that is not the case you'd need to change the the following line:

IF NOT '%Choice%'=='' MOVE C:\WorkingDirectory\%Choice% C:\

where "C:\WorkingDirectory\" is the path to the folder containing the folders you want to move.
I've changed that Thanks!! But still nothing happens after I press enter :(
 
Open up the command prompt and browse to the directory where the batch file is. Try and type the command manually and see what it does.

EG: move "new folder" d:\somefolder\somesubfolder\

It should tell you if something goes wrong.
 
Back
Top Bottom