Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Script to Move Folders on Network Drive

Posted on 2011-02-15
12
Medium Priority
?
620 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

705 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