Solved

Script to Move Folders on Network Drive

Posted on 2011-02-15
12
613 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
  • 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
 
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

757 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now