Link to home
Start Free TrialLog in
Avatar of operationsIT
operationsIT

asked on

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.
Avatar of Maclean
Maclean
Flag of New Zealand image

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
Avatar of NVIT
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

Hi Operations IT...

Did you have a chance to try my solution?
Let me know if you need help running it.
Avatar of operationsIT
operationsIT

ASKER

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!
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.
@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?
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?
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?
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.
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

@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.
ASKER CERTIFIED SOLUTION
Avatar of NVIT
NVIT
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Perfect let me test this.  I thank you so much!
Hi operationsIT,

Just wondering... How did your test go?
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!
... 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!
Glad it works for you, operationsIT.

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

Have a great week.
Fabulous thank you SO much!