IT_newbie01
asked on
batch file to zip files
Morning all,
Im looking to modify code to copy a file from 1 drive location and copy it over to another location zipped. The files collectively exceed 600 gig and i only have half of that available. Ultimately I want to copy to the new location and delete all the original files. If you can think of a better option im also open to suggestion.
Thanks in advance!
Im looking to modify code to copy a file from 1 drive location and copy it over to another location zipped. The files collectively exceed 600 gig and i only have half of that available. Ultimately I want to copy to the new location and delete all the original files. If you can think of a better option im also open to suggestion.
Thanks in advance!
echo off
setlocal EnableDelayedExpansion
set src=C:\pst_files
set dst=c:\test
for /F "tokens=*" %%F in ('dir /s/b/a:-d %src%\*.pst') do (
set folder=%%~dpF
set folder=!folder:~0,-1!
for %%D in ("!folder!") do set folder=%%~nxD
copy "%%~F" "%dst%\%%~nF.!folder!%%~xF
)
>>> "The files collectively exceed 600 gig and i only have half of that available." <<<
You mean that you only have half the storage capacity of the source files as your destination for them, hence the need to zip them up?
Risky business, I would say. I would never risk copying files and deleting as I went without some solid verification in place. Even then, the potential for loss if the system froze or you suffered a power outage could leave you in a real mess.
There is also the issue that you cannot reasonably anticipate what the compressed size of all the source files will be if they are in various file formats. Some files like text-based files zip up to a fraction of the original file size, while others don't compress at all.
Whatever you do test, I would urge you to use the appropriate command line switch that SIMULATES the command and would give an advanced indication whether it would fail.
To be honest, I am hesitant to even make a suggestion here in case something does go horribly wrong and you lose 300 GB of files, especially while large capacity hard drives are fairly affordable these days.
You mean that you only have half the storage capacity of the source files as your destination for them, hence the need to zip them up?
Risky business, I would say. I would never risk copying files and deleting as I went without some solid verification in place. Even then, the potential for loss if the system froze or you suffered a power outage could leave you in a real mess.
There is also the issue that you cannot reasonably anticipate what the compressed size of all the source files will be if they are in various file formats. Some files like text-based files zip up to a fraction of the original file size, while others don't compress at all.
Whatever you do test, I would urge you to use the appropriate command line switch that SIMULATES the command and would give an advanced indication whether it would fail.
To be honest, I am hesitant to even make a suggestion here in case something does go horribly wrong and you lose 300 GB of files, especially while large capacity hard drives are fairly affordable these days.
ASKER
Im researching 7zip and im liking what im seeing. The code above is a batch file and was written in the command line. Is it accurate to say that i can that code in the command line of 7zip. I will need a loop and evaluation statement to get exactly what im looking for??
ASKER
@BillDL: Much thanks for the concern. I am only testing, i am not looking to deploy this solution until im solid it works and i have backed everything up. I only state that i have half of the storage space and insight on why im persuing this project. I will be adding memory next week but that's only a quick fix i want to zip files on a weekly basis as a long term solution. Again thanks for you concern
You already have the loop, right?
You only need to add the command to compress, and the rest is very easy: copy and delete.
Regarding the concerns, if you know your tons of GB contain text (repeated throughout the file), then the compression ratio will be good enough to turn those files into just a few hundred MB.
Here's a snippet of what I use in my servers:
SET SEVENZIP=C:\progra~1\7-zip \7z.exe
SET TPATH=c:\temp
SET DAT=C:\Bkup\sh11.dat
SET ZIP=sh11.zip
%SEVENZIP% a %TPATH%\%ZIP% %DAT%
DEL /Q %DAT%
You only need to add the command to compress, and the rest is very easy: copy and delete.
Regarding the concerns, if you know your tons of GB contain text (repeated throughout the file), then the compression ratio will be good enough to turn those files into just a few hundred MB.
Here's a snippet of what I use in my servers:
SET SEVENZIP=C:\progra~1\7-zip
SET TPATH=c:\temp
SET DAT=C:\Bkup\sh11.dat
SET ZIP=sh11.zip
%SEVENZIP% a %TPATH%\%ZIP% %DAT%
DEL /Q %DAT%
Do you still want each PST file to be a separate ZIP file, or do you want all files to be in the same ZIP?
~bp
~bp
ASKER
id like each .pst file to be individual zipped and placed in a single folder. But because you mentioned it could I get both? If not that fine as well.
Thanks for any help..!!
Thanks for any help..!!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
To zip them all into a single ZIP it should be pretty simple, like:
@echo off
7z a -tzip c:\test\archive.zip -r c:\pst_files\*.pst
~bp
Looks like you have the best solutions to your problem IT_newbie01. Sorry to be a killjoy earlier. I was very concerned about how much storage you had available. Out of curiosity I zipped up a couple of test *.PST files using 7-Zip on "maximum" compression. It applied compression ratios ranging between 39 and 50%, which is to say that the zip files ended up on average about 36% the file size of the original *.pst files. If that is a standard result, your 600GB worth of PST files might only need about 235GB storage when zipped. You might just get away with the destination storage you have at the moment.
ASKER
@t-max: Im testing now and will get back to you with results.
@billprew: thanks for the info.
@BillDL: Thanks for the concern; i honestly appreciate your concern and following up with testing compression ratios.
YOU ALL ROCK!!
@billprew: thanks for the info.
@BillDL: Thanks for the concern; i honestly appreciate your concern and following up with testing compression ratios.
YOU ALL ROCK!!
ASKER
t-max: The zipping is working correctly (actually really good ration), but the file is storing in the sub-directories. Im looking to centralize all the files. That's why im changing the name of the file so that i dont have files naming errors. Please advise.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Sorry, my mistake. t-max's batch file DID copy the Zip files to the C:\Test folder, but applied the *.PST extension to the copies instead of the *.ZIP extension. I hadn't noticed the file size differences.
Yes it seems I forgot to add the ".zip" to the copied files. Sorry :)
About centralizing the files, If I'm not compiling the code in my head wrong, all files are stored inside %dst%, right?
We have:
"%dst%\%%~nF.!folder!%%~xF
Which should be:
c:\test\<file-name>.<folde r-name>pst
If that's not what you want, tell us what file name pattern do you need.
Personally I'll do it like this: c:\test\<folder name>.<full file name>.zip
Max
About centralizing the files, If I'm not compiling the code in my head wrong, all files are stored inside %dst%, right?
We have:
"%dst%\%%~nF.!folder!%%~xF
Which should be:
c:\test\<file-name>.<folde
If that's not what you want, tell us what file name pattern do you need.
Personally I'll do it like this: c:\test\<folder name>.<full file name>.zip
copy "%%~F.zip" "%dst%\!folder!.%%~sF.zip"
Max
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Oh DAMN!! Sorry t-max, the page wasn't refreshed until I posted my comment. I was watching for you returning.
ASKER
Im testing all solution. Dont want anyone to think ive not involved! I appreciate all the HELP!!!
Yeah, that happens from time to time. I learned to refresh the page before I post, just in case.
BTW Bill, thanks for your comment, but I just added the zipping command, and some error checking. All the credit goes to the poster.
BTW Bill, thanks for your comment, but I just added the zipping command, and some error checking. All the credit goes to the poster.
Thank you IT_newbie01.
The 7zip command line syntax is easy. If you need any help with any of this, post back.