Saved Bookmarks
| 1. |
Solve : Trying to write a batch file? |
|
Answer» I have to write a AUTOMATED batch file that will grab logs (ex05051500.log) that I want to zip up and move to another DIRECTORY. need to be able to grab certain files depending on their file name to be zipped What is the criteria for selecting a file? And finally can you script this instead of using batch? Let US know. it is WinXp, and using Winzip 9.0Ok! here we go: First we need a list of the files to select, I'm gonna assume they are *.log files. for /f %%i "delims=. tokens=1-2" in ('dir /b *.log') do ( Next we need to parse out the first 8 characters of the file name (be sure this doesn't create dups) set /p Fname8 = %%i :~0,8% Then it's time to zip them: wzcline drive:\path\%Fname8%.zip %%i.%%j wzcline is the batch version of WinZip Okay!, shut it down with ) If you read between the lines, it's all it front of you. Good luck. I greatly appreciate your help, I have been so lost the past few weeks trying to figure this out, but once agian i'm stuck with your script. I am getting an error. This is how I wrote it in the batch file: For /F "tokens=1-2 delims=." %%i in ('E:\logs\test /b *.log') do "set /p Fname8 = %%i :~0,8% wzcline E:\logs\test %Fname8%.zip %%i.%%j" any ideas? I get this error: The filename, directory name, or volume label syntax is incorrect.For /F "tokens=1-2 delims=." %%i in ('dir /b E:\logs\test\*.log') do ( set /p Fname8 = %%i :~0,8% wzcline E:\logs\test\%Fname8%.zip %%i.%%j ) I'm a LITTLE unsure about the set statement; it may need an addtional % after the equals sign. You can play around with it. I can't emphasize enough to consider script for these types of tasks. The above code is nearly unreadable and it certainly won't get any clearer in six months time. In case you don't have the batch version of WinZip (wzcline), here is the link: http://www.winzip.com/wzcline.htm Hope this helps. thanks for your help- |
|