File folder management of directories question on deleting and retaining data

Hello EE,
We have a folder G:\Data\Manuals\Release which has several folders in it i.e. G:\Data\Manuals\Release\A
and G:\Data\Manuals\Release\Block, etc.  In each of these folders there is a Documents folder.  I am wondering if there is a script I can run to move the Documents folder from within these folders to another location so I can delete the rest of the obsolete data.
operationsITAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MacleanSystem EngineerCommented:
My workaround for this some years back in a similar situation was to use a tool named Karens Replicator
Inside the tool you can setup a filter/mast to search for particular folder or file names, and have it replicate to another location.

Once replicated, backup the old directory to USB or Tape, and delete it (Upon confirming that the data indeed did replicate)

http://www.majorgeeks.com/files/details/karens_replicator.html
NVITEnd-user supportCommented:
Here's a .bat file to do this. Nothing else to install.
Note:
- Adjust DirTgt and FNLog to your needs
- It copies the data instead of moving it. You can easily delete the source manually once you've confirmed the copy is good.

To run it:
- Save the code below to a file like CopyDocsDir.bat.
- Open a CMD window.
- Type CopyDocsDir


@echo off
set DirSrc=G:\Data\Manuals\Release
set DirTgt=G:\Backup
set FNLog=G:\Backup\log.txt
for /d %%a in (%DirSrc%\*) do (
   echo %date% %time% START "%%a\Documents">>%FNLog%
   if exist "%%a\Documents" (
      md "%DirTgt%\%%~na"
      xcopy /e /y "%%a\Documents" "%DirTgt%\%%~na\Documents\" && echo %date% %time% END "%%a\Documents">>%FNLog%
   )
)

Open in new window

NVITEnd-user supportCommented:
Hi Operations IT...

Did you have a chance to try my solution?
Let me know if you need help running it.
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

operationsITAuthor Commented:
The guy I needed to demo pushed the meeting to tomorrow so will prove tomorrow and will let you know if I need help.  Thank you so much can't wait to try!
NVITEnd-user supportCommented:
Thanks for the update, _.

BTW, I know your original request is "...to move the Documents folder...". The solution I presented copies the files instead. I find it's safer that way. With this, you delete the files you want and the the now copied Documents folder.
operationsITAuthor Commented:
@NewVillageIT

I am trying to test this before I do production so I have created a test drive U:\test with folders Docs, Release and Work.
In my scenario I want to copy the docs to U:Backup and edited your script to reflect

set DirSrc=U:\test
set DirTgt=U:\Backups

I changed the "Documents" to Docs and ran it and the log shows
Tue 03/10/2015  9:28:33.55 START "U:\Test\Docs\Docs"
Tue 03/10/2015  9:28:33.55 START "U:\Test\Release\Docs"
Tue 03/10/2015  9:28:33.55 START "U:\Test\Work\Docs"
But the docs folder under U:\Test\Docs was not copied to backup so I could delete Release and Work.  In my scenario under test there are 100 folders with different names and some have docs under them and some don't.  I want to copy anything with Docs and files out so I can just easily delete everything else.  What am I missing?
NVITEnd-user supportCommented:
I'll make a revised version when I get to work.

I changed the "Documents" to Docs...

100 folders with different names and some have docs under them and some don't

Please clarify:
Are some named Docs and some named Documents?
NVITEnd-user supportCommented:
I'm a bit confused regarding your folder structure. Your original post seems to differ from your last post.

Would you please give an example of a set folder names and what must happen to each?
operationsITAuthor Commented:
Sorry, I was doing a test before I went to production, but yes not to confuse you, in my test I'll use the same layout so I don't have to alter the code you are so kindly assisting me with.  

My actual file is G:\Data\Manuals\Release.  Under it I have folders called:
A
Block
Close 2011
Close 2012
Close 2013
Marketing
Sold
Engineering
and so on as there are about 50 some or more.  What I am looking to do:

Several of these folders contain a folder called documents.  I would like to retain these folders from each of the above and delete everything else as the data is outdated but the docs are critical to hold onto as they contain release information.  If I manually go through that many folders it would take forever.  Obviously I can't copy all of documents folders into a folder as they all have the same name so I am looking for your help.  I thank you already for assisting.
NVITEnd-user supportCommented:
Just clarifying your requirements...

- G:\Data\Manuals\Release is the main folder.
- In the main folder, you want to process all the subfolders.
- If a subfolder has a Documents folder, move it to another location.

Several of these folders contain a folder called documents.
So, just for example, folders Block and Engineering but not the rest, may have a Documents folder?

I'm thinking what the target folder should look like... Assuming the above is true, maybe something like:
G:\Data\MovedDocsFolders\Block
G:\Data\MovedDocsFolders\Engineering
...

Open in new window

operationsITAuthor Commented:
@NewVillageIT
Yes - main folder
Yes- process subfolders
Yes move the sub folder called documents out of Block for example to a target called Z:\Backup
Others as you indicate may not contain a folder called documents so there maybe nothing to move.
However if Block and Engineering in your example have "documents" they need something in the Z:\Backup as you can't have two with the same name.
NVITEnd-user supportCommented:
@echo off
SETLOCAL ENABLEDELAYEDEXPANSION

REM Starting at subfolder level 4, copies subfolder Documents to target Level4FolderName_Documents

REM Assumptions:
REM - Subfolder level 5 contains, if any, the Documents folder

set DirSrc=G:\Data\Manuals\Release
set DirTgt=Z:\Backup
set FNLog=%temp%\log.txt
set FNDocDirs=%temp%\DocDirs.txt

echo %date% %time% START>>%FNLog%
dir /b/s "Documents">%FNDocDirs%
for /f "tokens=1-6 delims=\" %%A in (%FNDocDirs%) do (
   set SrcDir=%%A\%%B\%%C\%%D\%%E\%%F
   set TgtDir=%DirTgt%\%%E_%%F
   echo !SrcDir!
   xcopy /i/e/y "!SrcDir!" "!TgtDir!\">>%FNLog%
)
echo %date% %time% END>>%FNLog%
goto :eof

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
operationsITAuthor Commented:
Perfect let me test this.  I thank you so much!
NVITEnd-user supportCommented:
Hi operationsIT,

Just wondering... How did your test go?
operationsITAuthor Commented:
OMG IT WORKED!!!!!  Sorry I've been playing around with it as I had it on my C:
Now that I put the .bat file in the appropriate directory it DID it.
May I ask a question for future use as I note you indicate sub folder level 4.  What would I have to change for example in the future if I wanted to look at subfolder level 2 for folders named in level 3 for example?

YOU ARE SOOOO KIND!
NVITEnd-user supportCommented:
... I wanted to look at subfolder level 2 for folders named in level 3 for example?
I'm not at a computer right now so can't test. To guess, it's in this line:
set DirSrc=G:\Data\Manuals\Release

Open in new window


Change it to a 2nd level folder name. Using same example:
set DirSrc=G:\Data\Manuals

Open in new window


Be sure to test first!
NVITEnd-user supportCommented:
Glad it works for you, operationsIT.

I'd appreciate it if you would please close the question accordingly.

Have a great week.
operationsITAuthor Commented:
Fabulous thank you SO much!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
File Sharing Software

From novice to tech pro — start learning today.