CFAIT
asked on
Script to Move Folders on Network Drive
I need to be able to move (not copy) over a thousand folders and their contents to another network location with a script.
Right now, the folders are set up like this:
H:\Legal\Location\00001\Bi nder
H:\Legal\Location\00002\Bi nder
H:\Legal\Location\00033\Bi nder
and so on...
I need to be able to move each Binder folder and its contents to a new location on the network, so that the new folder structure will look like this:
H:\Location\00001\Binder
H:\Location\00002\Binder
H:\Location\00033\Binder
and so on.
I need to leave the original folder structure and files intact, only moving the Binder folder to a new location.
Any assistance would be much appreciated! Thank you!
Right now, the folders are set up like this:
H:\Legal\Location\00001\Bi
H:\Legal\Location\00002\Bi
H:\Legal\Location\00033\Bi
and so on...
I need to be able to move each Binder folder and its contents to a new location on the network, so that the new folder structure will look like this:
H:\Location\00001\Binder
H:\Location\00002\Binder
H:\Location\00033\Binder
and so on.
I need to leave the original folder structure and files intact, only moving the Binder folder to a new location.
Any assistance would be much appreciated! Thank you!
oops, never mind that - I see the error of my ways.
Stand by ...
Stand by ...
ASKER
The source folders that are numerical will change and there is no pattern to them. I need to have a wildcard entry for those, and also keep the same numerical folder names in the destination directory.
H:
MD H:\Location >nul
CD H:\Legal\Location
for /d %%D in (*) do (
md "H:\Location\%%D\Binder"
pushd "%%D\Binder"
xcopy/e * "H:\Location\%%D\Binder"
del/s/q *
popd
)
MD H:\Location >nul
CD H:\Legal\Location
for /d %%D in (*) do (
md "H:\Location\%%D\Binder"
pushd "%%D\Binder"
xcopy/e * "H:\Location\%%D\Binder"
del/s/q *
popd
)
Put in a batch file and execute:
REM moveFilesAndFolders.bat
cd /d h:\legal\Location\
for /d %%i in (*) do call :moveOneFolder %%i
goto:EOF
:moveOneFolder
mkdir h:\Location\%1\Binder
cd h:\legal\Location\%1\Binder\
for %%j in (*) do move /-Y %%j h:\Location\%1\Binder\
cd h:\legal\Location\
goto:EOF
ASKER
Thank you for your responses - knightEknight, I would rather not use xcopy, and instead use 'move' because of the large amounts of data that we are working with on the network.
sjklein42: This is almost perfect - but I also need to move the contents of the Binder folder to the new location and remove the Binder folder and its contents from the old location.
Thank you again!
sjklein42: This is almost perfect - but I also need to move the contents of the Binder folder to the new location and remove the Binder folder and its contents from the old location.
Thank you again!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
It should already be moving the contents of the Binder folder. I added the rmdir line to delete the old Binder folder after contents have been moved.
REM moveFilesAndFolders.bat
cd /d h:\legal\Location\
for /d %%i in (*) do call :moveOneFolder %%i
move
goto:EOF
:moveOneFolder
mkdir h:\Location\%1\Binder
cd h:\legal\Location\%1\Binder\
for %%j in (*) do move /-Y %%j h:\Location\%1\Binder\
cd h:\legal\Location\
rmdir h:\legal\Location\%1\Binder\
goto:EOF
ASKER
knightEknight - thank you, that worked perfectly!
sjklein42 - for some reason, that script did not copy the contents of the Binder folder down.
Thank you both so much!
sjklein42 - for some reason, that script did not copy the contents of the Binder folder down.
Thank you both so much!
@sjklein42: Your script does not switch to the H: drive. You forgot to change the drive letter after "cd" to just H: then simply "CD" after the fact.
Russell_Venable,
I think the /D on cd causes it to switch drives as well as folders.
Cheers.
I think the /D on cd causes it to switch drives as well as folders.
Cheers.
I guess so cheers!
md H:\Location
move "H:\Legal\Location\00001\B
move "H:\Legal\Location\00002\B
move "H:\Legal\Location\00033\B