Solved

Script to Move Folders on Network Drive

Posted on 2011-02-15
12
618 Views
Last Modified: 2012-08-13
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
Comment
Question by:CFAIT
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 3
  • +1
12 Comments
 
LVL 33

Expert Comment

by:knightEknight
ID: 34897190
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
 
LVL 33

Expert Comment

by:knightEknight
ID: 34897200
oops, never mind that - I see the error of my ways.
Stand by ...
0
 

Author Comment

by:CFAIT
ID: 34897218
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 33

Expert Comment

by:knightEknight
ID: 34897241
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
 
LVL 16

Expert Comment

by:sjklein42
ID: 34897250
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
 

Author Comment

by:CFAIT
ID: 34897674
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
 
LVL 33

Accepted Solution

by:
knightEknight earned 500 total points
ID: 34897731
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
 
LVL 16

Expert Comment

by:sjklein42
ID: 34897782
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
 

Author Comment

by:CFAIT
ID: 34909230
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
 
LVL 15

Expert Comment

by:Russell_Venable
ID: 34912499
@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
 
LVL 16

Expert Comment

by:sjklein42
ID: 34912528
Russell_Venable,

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

Cheers.
0
 
LVL 15

Expert Comment

by:Russell_Venable
ID: 34912754
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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
I'm trying to understand this simple vb code! 2 46
batch file or script 4 66
VB script to continue despite error 2 78
VB.NET Parsing UDP Bytes 15 36
This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question