Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 621
  • Last Modified:

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\Binder
H:\Legal\Location\00002\Binder
H:\Legal\Location\00033\Binder
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!
0
CFAIT
Asked:
CFAIT
  • 4
  • 3
  • 3
  • +1
1 Solution
 
knightEknightCommented:
H:
md H:\Location

move  "H:\Legal\Location\00001\Binder"  "H:\Location"
move  "H:\Legal\Location\00002\Binder"  "H:\Location"
move  "H:\Legal\Location\00033\Binder"  "H:\Location"
0
 
knightEknightCommented:
oops, never mind that - I see the error of my ways.
Stand by ...
0
 
CFAITAuthor Commented:
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.
0
Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

 
knightEknightCommented:
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
)

0
 
sjklein42Commented:
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

Open in new window

0
 
CFAITAuthor Commented:
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!
0
 
knightEknightCommented:
I used xcopy to avoid moving other subfolders that might be on the same level as Binder.  If there are none, then using "move" is the simplest solution.  Actually, it is possible to just move the Binder folders:


H:
MD H:\Location >nul

CD H:\Legal\Location

for /d %%D in (*) do (
   md  "H:\Location\%%D"
   move  "%%D\Binder"  "H:\Location\%%D"
)
0
 
sjklein42Commented:
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 

Open in new window

0
 
CFAITAuthor Commented:
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!
0
 
Russell_VenableCommented:
@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.
0
 
sjklein42Commented:
Russell_Venable,

I think the /D on cd causes it to switch drives as well as folders.

Cheers.
0
 
Russell_VenableCommented:
I guess so cheers!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now