| 1. |
Solve : Zipping files using batch file? |
|
Answer» Is there a way to: You're making this harder than it has to be. You had all the pseudo-code laid out, all you needed to do was code it up: That's just it, the cscript and vbs stuff is completely foreign to me. Coding it up was not possible so I would need expernal programs like pkzip and batch file for a time delay... I do appreciate your work and will let you know how it turns out. ThanksI have run the code(bat & vbs) and encountered some problems: There is the code I am using at present: Code: [Select]@echo off md c:\docume~1\brianb~1\desktop\TEXTZ\ cd /d i:\ for /f "tokens=* delims=" %%x in ('dir /s /b /a:-d *.txt') do ( copy "%%x" C:\docume~1\brianb~1\desktop\TEXTZ\ ) cscript grabnzip.vbs rd C:\docume~1\brianb~1\desktop\TEXTZ\ /s/q As a test I altered the code to copy some txt files... The first problem I had was that a folder was not created, but rather a file with no extension. So I added the line to make a directory. I also changed the folder path to be the same as the .zip destination. Code: [Select]strTargetFile = "C:\docume~1\brianb~1\desktop\TEXTZ.zip" Set fso = CreateObject("Scripting.FileSystemObject") Set zip = fso.CreateTextFile(strTargetFile) zip.Write Chr(80) & Chr(75) & Chr(5) & Chr(6) & String(18, 0) zip.Close WScript.Sleep 500 Set objShell = CreateObject("Shell.Application") Set objFile = objShell.NameSpace(strTargetFile) Set src = objShell.NameSpace("C:\docume~1\brianb~1\desktop\TEXTZ\") objFile.CopyHere src WScript.Sleep 30000 After all the code ran I did get a folder created and the txt files(15) were copied to the folder. Then the folder was deleted, but there was no zip file created. It seems that at this point I might as well use pkzip as I can't achieve my goal with a single batch file. So if I use a .vbs file or pkzip.exe makes no difference. You're also ignoring how powerful PKZip is/was...it went outside of DOS/batch limitations in ALOT of ways way before it's time and it would be a good learning experience to do some more research along with the link i provided... XTree Gold is another example of batch/scripting on steroids but takes some getting used to...actually that's innaccurate. It's not a batch/script tool rather a powerful DOS shell.Using PKZip is a fine alternative. I only posted because you originally wanted to use the built-in capabilities of Windows. When I tested my original code, it worked fine! I'm very surprised the TEXTZ.zip file did not end up in C:\docume~1\brianb~1\desktop. I'm going to take it on faith that brianb~1 is your account. Good luck. Quote from: patio on January 04, 2008, 02:01:59 PM You're also ignoring how powerful PKZip is/was...it went outside of DOS/batch limitations in alot of ways way before it's time and it would be a good learning experience to do some more research along with the link i provided... I will take the time to read the pkzip documentation. It's not a short doc but like you said it may be all I need.Quote from: Sidewinder on January 04, 2008, 02:44:47 PM When I tested my original code, it worked fine! I'm very surprised the TEXTZ.zip file did not end up in C:\docume~1\brianb~1\desktop. I'm going to take it on faith that brianb~1 is your account. At first it did not. After using PKZip.exe it did, but it contained files other than the ones from the TEXTZ folder. The trouble I was having was that I refferenced a thumb drive for the test(I:\) and once there it could not change directories back to the hard drive(C:\). Not that I found this out the original code you wrote might work. I am going to revisit it. Yes brianb~1 is my account. I also searched all drives for the file but found nothing. P.S. What does the "/d" after the CD command designate? It doesn't show up as syntax for the DOS CD command reference. Sidewinder, I got your code to run. as wel as a PKZip version. It might be possible for PKZip to do it all by itself, but for now I am satisfied. This is the code that worked for me: Code: [Select]cd /d d:\ md TEXTZ cd /d d:\testfold\ for /f "tokens=* delims=" %%x in ('dir /s /b /a:-d *.txt') do ( copy "%%x" d:\TEXTZ\ ) CD /d C:\Docume~1\brianb~1\desktop\ cscript grabnzip.vbs rd d:\TEXTZ /s/q exit Code: [Select]strTargetFile = "C:\docume~1\brianb~1\desktop\TEXTZ.zip" Set fso = CreateObject("Scripting.FileSystemObject") Set zip = fso.CreateTextFile(strTargetFile) zip.Write Chr(80) & Chr(75) & Chr(5) & Chr(6) & String(18, 0) zip.Close WScript.Sleep 1000 Set objShell = CreateObject("Shell.Application") Set objFile = objShell.NameSpace(strTargetFile) Set src = objShell.NameSpace("D:\TEXTZ\") objFile.CopyHere src WScript.Sleep 15000 I'd still like to know what CD /d means... Thanks for your help. patio, thanks for your insite as well. I will be examining the POWER of pkzip soon! Forgot...here is the batch file code using pkzip. Code: [Select]@echo off cd /d d:\ md TEXTZ cd /d d:\testfold\ for /f "tokens=* delims=" %%x in ('dir /s /b /a:-d *.txt') do ( copy "%%x" d:\TEXTZ\ ) call PKZIP c:\docume~1\brianb~1\desktop\TXTZ.ZIP d:\TEXTZ\*.* pause rd d:\TEXTZ /s /q exit Brian |
|