Andrews Posted December 24, 2011 Posted December 24, 2011 I want to use 7zip for its usual function, but with individually compressed files in their folders and original names. 7zip, unlike WinRar with the option Put each file to a separate archive, only does this with the -o switch when decompressing, not compressing.I found a batch file at SourceForge (original version quoted at the bottom) that does it exactly as I need, but for a little difference: it leaves the compressed files and directories mixed on the original directory to where I copy the batch file and launch it. Not quite a problem if compressing only a handful of files, but when there are thousands of directories and files it requires a very long time to separate them, and as some are not compressed it can become a real headache, waste of time and patience.I placed a redirection after the operation (added in green), but is doesn't work. The result at the end of the command is Access is denied. It is a trial directory and also a trial path. I tried the path for the new existing directory both with and without quotes with the same result.Obviously, my problem is ignorance and that is what makes me ask for help. I searched the internet and found many tutorials, searched them, but not what I am looking for.How can I redirect the output of the 7zip compressed files and directories to another directory, or maybe better, make the batch file make a new one and redirect the output of 7zip into it?Any suggestions will be most welcome. Thank you.Best wishes for Christmas and New Year.@echo off:beginfor /f "delims=" %%i in ('dir /b /ad') do (call :zipdir "%%i")goto end:zipdir"C:\Program Files\7-Zip\7z.exe" a -t7z %1.7z %1\if errorlevel 1 goto error"C:\Program Files\7-Zip\7z.exe" t %1.7z >> "C:\Users\Administrator\Desktop\Compressed"if errorlevel 1 goto errorecho rmdir /S /Q %1\goto :eof:errorgoto :eof:end
jaclaz Posted December 24, 2011 Posted December 24, 2011 I am not sure to get what you are asking. Can you post a short examples of the files and dir as they are and the way you want them compressed?jaclaz
Yzöwl Posted December 24, 2011 Posted December 24, 2011 The only logical way of doing this without potentially deleting something which failed to be added to a working compressed archive is:Compress Directory Contents to Archive (in a temporary location)If successfulTest Archive integrityIf successfulExtract Archive (to another temporary location)If successfulCompare extracted files with originalsIf successfulDelete originals and temporary onesMove archive to Original Directory
Andrews Posted December 24, 2011 Author Posted December 24, 2011 Thank you jaclaz fpr coming on rescue once more.What I want to do is simple. I want to compress many directories with files. They are in branches (or trees) like as they normally appear on Windows Explorer.After compression I want them organised the same way as before compression (similar trees) keeping the same order and individually comperessed. For instance, you have a tree with directories and files and compress them. After compressing they are in an identical tree, but compressed.The batch file does it exactly that way. You can try it and see the result. I put the batch file on the directory I want to compress, double click and it and it does the job. The only problem is that it saves the compressed directories and files on the original directory where the files to compress are. I want to redirect its output somewhere else and not mix up everything.I hope I explained better now, but if you try the batch you will see exactly what I mean.
Andrews Posted December 24, 2011 Author Posted December 24, 2011 Thank you for trying to help Wise Owl. I am starting to believe that the more I try to explain what I want, the more I mix it up.What you say is very complicated end endless when having lots of files. That batch does the job already. So all I need is only to add some code to the batch, so that it outputs its job (the compressed directories with files) to another directory and NOT into the original directory where the uncompressed directories and files already are.
jaclaz Posted December 25, 2011 Posted December 25, 2011 (edited) Let's see if I understand. I normally understand by examples.Let alone for the moment the multi-file/multifolder issue.You have a single file:C:\myfiles\mydir\mysinglefile.extyou want to use 7-zip (which BTW is NOT IMHO the best choice for single file archiving) to have it compress that file to:C:\Users\Administrator\Desktop\Compressed\myfiles\mydir\mysinglefile.7zIs this what you want? BTW, to output to stdout in 7zip you use the -so (write data to stdout) switchbut this WON'T HELP you unless you first create the target tree.jaclaz Edited December 25, 2011 by jaclaz
Yzöwl Posted December 25, 2011 Posted December 25, 2011 I thought that they had the following:SourceDir \SubFolder \ChildDir1 File789.ext Filexyz.ext File1.ext File2.ext File3.ext \SecondSub \ChildFolder File123.ext Fileabc.ext File7.ext File8.ext File9.ext ThisScript.cmdWhen they execute ThisScript.cmd they wish it to produce two 7z files, (in a folder named 'Compressed' on the Desktop), %UserProfile%\Desktop\Compressed\SubFolder\SubFolder.7z and %UserProfile%\Desktop\Compressed\SecondSub\SecondSub.7z.However I see little point in recreating the top level structure since 7-zip will compress the directories SubFolder and SecondSub not just their contents.I would probably suggest something like this, (untested):@ECHO OFF &SETLOCAL ENABLEEXTENSIONS DISABLEDELAYEDEXPANSION(SET COMPDIR=%USERPROFILE%\DESKTOP\Compressed)FOR %%# IN (%COMPDIR%) DO (SET _=%%~dp#)IF /I "%_%"=="%~dp0" GOTO :EOF(SET UTILDIR=%PROGRAMFILES%\7-ZIP)IF /I NOT "%CD%\"=="%~dp0" PUSHD %~dp0FOR /D %%# IN (*) DO ( IF NOT EXIST "%COMPDIR%" MD "%COMPDIR%" "%UTILDIR%\7Z.EXE" A -T7Z "%COMPDIR%\%%#.7z" "%%#")You should be able to add the integrity verification command line to the above as required.
Andrews Posted December 26, 2011 Author Posted December 26, 2011 Thank you both.jaclazThe –so switch, if I used it right, did not redirect the compressed files and directories. It just placed them on the same directory with the originally not compressed.To see an easy example as you suggest try the following please.Make a new folder on your desktop.Copy a directory with sub-directories and subs and files.Put the batch file on my first post in this directory and double click it.See the result.You will find the original structure compressed where you put the batch, starting with that directory.That is what I get and nearly what I want.What I want is 7zip to redirect is the compressed structure to another directory. Just this.You say 7zip is NOT IMHO the best choice for single file archiving. What would you choose that would be simple?YsöwlYes, the structure is as you wrote on the first part of you post.Your script works as I need and it can even create a new directory if it doesn’t already exist. All I have to do is to change the path or the name if I need. Thank you very much again.
jaclaz Posted December 26, 2011 Posted December 26, 2011 (edited) The gzip format was born with this idea of a single compressed archive for each source file.gzip allows streaming and thus piping and redirection, something that 7z compression may not.Try (still following my previous example):"C:\Program Files\7-Zip\7z.exe" a dummy -tgzip -so C:\myfiles\mydir\mysinglefile.ext >C:\Users\Administrator\Desktop\Compressed\myfiles\mydir\mysinglefile.gz(of course the target directory must exist)Basically you fell for the chocolate covered banana :http://homepages.tesco.net/J.deBoynePollard/FGA/put-down-the-chocolate-covered-banana.htmljaclaz Edited December 26, 2011 by jaclaz
Andrews Posted December 26, 2011 Author Posted December 26, 2011 sorry, can't write for few days. small operation to finger tendon.
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now