I wrote a script that will take in a list of files and 7zip will pass in the array and zip of the files. It works to an extent, but not quite how I need it to. I'm archiving sets of IIS web logs in a directory. Problem being is that under each web folder, the IIS log names are the same format. I need it to recurse the directories, but somehow my command line isn't doing that even when I include the -r. It will just keep overwriting until it gets to the last set. Here's my vbscript sample:
So it should be inputting:
"c:\program files\7-zip\7z.exe" a -t7z -y -r WEBLOGS.7z strFILE, 0, True
strFile is an array that gets passed through a txt file containing the list of files to be zipped up and also has the full path. As I mentioned, it is archiving, but since the directories are not being passed in, it just overwrites the archived files until it hits the last ones. I found part of the command line example on the web and I'm unsure of what the last part does (0,True).
Any help would be awesome!!!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
"c:\program files\7-zip\7z.exe" a -t7z -y -r WEBLOGS.7z strFILE, 0, True
the -r should include the directories in the archive, but it's not. I'm passing in a text file with a list of files (with their full path) to be zipped. These are IIS web logs for about 30 different sites. They are in different folders, but in the end, they all have the same file names as it's formatted by the date.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2011-04-15
Have you tried downloading the command line version of 7-zip and running your script so that it references 7za.exe (instead of 7z.exe)? See my earlier forum reply to someone who asked about where to find the command line version. It would be cool if the solution turns out to be as simple as this! :-)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Maybe it's the logic of my script. I'm loading all the files into an array. In a function, I am running a For loop to go through each line of the text file and within the loop, is the 7za command. The script works to an extent, but it's just not recursing the directories and in the end, just overwriting the initial files.
For i = 1 To UBound(readArray)
strFile = readArray(i)
WScript.Echo Now & ": " & "zipping " & strFile
oShell.Run Chr(34) & s7zLocation & "7za.exe" & Chr(34) & " a -t7z -y " & sArchiveName & " " & strFile, 0, True
Next
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2011-04-15
Not to sound silly, but I've been looking over the line in your example immediately above starting with "oShell.Run…" and I don't see a "-r" in there anywhere…. Could it be as simple as that? :-)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Sorry, i was messing around with the settings and i copied/pasted at the wrong time. I've used -r in there.
Any other ideas???
Thanks
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2011-04-15
Maybe you're writing more script than you need to, as 7-zip may have that functionality built into it already. Consider the following section of 7-zip's command line help file … :
List file
You can supply one or more filenames or wildcards for special list files (files containing lists of files). The filenames in such list file must be separated by new line symbol(s).
For list files, 7-Zip uses UTF-8 encoding by default. You can change encoding using -scs switch.
Multiple list files are supported.
For example, if the file "listfile.txt" contains the following:
My programs\*.cpp
Src\*.cpp
then the command
7z a -tzip archive.zip @listfile.txt
adds to the archive "archive.zip" all "*.cpp" files from directories "My programs" and "Src".
… so maybe another approach you could try is to write to a text file (e.g., MyFiles.txt) the path(s) to the items you want recursed and zipped and then invoke 7-zip's command line with the "@MyFiles.txt" command line syntax. (I'm giving you my best ideas at a solution. I hope one of them finally helps out. :-) )
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Actually, the first part is what I am doing. I'm scanning a folder/subfolders for logs older than X amount of days and the file (with the full path) get written to a line in a text file.
So with the second part, I can just put @myfiles.txt instead of strFile and it will read each line in the text file? I will give that a shot.
Thanks!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2011-04-15
Please post if you're successful with that "@" syntax. It took me a little time to get "up to speed" understanding what you were doing since I don't know vbscript that well. I think you were on the mark about the script's logic. Another idea that just came to mind with respect to debugging your original script would be to name the 7-zip archive(s) with (a) name(s) based on what the current value of "i" is in your For loop (e.g. WEBLOGS1.7z, WEBLOGS2.7z, etc.). That would probably illustrate what's happening but would also give you "i" number of 7-zip archives (probably not what you'd want, even if you subsequently archived all of those into one final additional 7-zip archive).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2011-04-16
Excuse me, but if I get the problem right, it seems that there's no problem.
I tried to do a simple test. I created a directory with some subdirectories and sub-subdirectories, and put some files to each of the directories. Many files have the same name: tst.txt, but some had different names. Then I executed the next command line:
"c:\program files\7-zip\7z.exe" a -t7z -y -r WEBLOGS.7z "D:\test\tst.txt"
It have successfully created the archive named WEBLOGS.7z with all the subdirectories that contained the files named tst.txt (and only those), all files were in place. This is the case even when there is no "D:\test\tst.txt" itself, only "D:\test\subdir\tst.txt".
If I undertstand the problem, you try to make an archive of all the files in the subdirectories of a directory, and all these files have the same name (possibly defined by a date). Then all your script has to do is define the file name it wants to add to the archive, and then execute the command
"c:\program files\7-zip\7z.exe" a -t7z -y -r WEBLOGS.7z "drive-letter:\path-to-root-dir\filename.fileext"
No need to specify full path to every file, as it will be handled automatically by 7-zip's -r switch.
Thanks Mike - I will take a look on Monday. I didn't realize I could just pass in the text file containing the list of files. I was running the loop since I thought I had to pass in each individual file into the command. I will take a look back at Monday when I return to the office. Thank you for your help.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2011-04-16
It's not a "text file containing the list of files" that I'm talking about.
Assuming that you have a directory structure like this:
Based on your last post, if I have a weblogs.7z file archive already and it already contains a file called d:\weblogs\4182011.log then running the command:
"c:\program files\7-zip\7z.exe" a -t7z -y -r WEBLOGS.7z "D:\weblogs2\4182011.log"
should add the 2nd log file and not overwrite the old file, correct?
I did the example above and it's overwriting and not recursing directories. Here is what I'm working with:
**************
d:\listoffiles.txt which contains the following lines:
My script will pass each line of the text as a string into an array. I will then run a FOR loop til the end of the text file and each string is passed into the command line as such:
Fori=1ToUBound(readArray)strFile=readArray(i)WScript.EchoNow&": "&"zipping "&strFileoShell.RunChr(34)&s7zLocation&"7za.exe"&Chr(34)&" a -r -t7z -y "&sArchiveName&" "&strFileNext
I also tried putting @d:\listoffiles.txt and that did not do anything. The text file with the list of files is generated from another script as I need to archive between certain months which is why I can't just do *.log
I am currently running version 9.20.0.0
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2011-04-18
nocode99
No, I meant a different thing.
In the example you gave, if you issue the following command:
"c:\program files\7-zip\7z.exe" a -t7z -y -r WEBLOGS.7z "D:\test.txt"
you will get the WEBLOGS.7z containing all three files. That's what I was talking about: you need to run 7-zip against the root of the directory tree, not against the real files. 7-zip will do it itself. And you need to run it only once, not many times as in your script.
However, in the example you gave, your root directory is the root directory, which may mean that there are much more directories in it. And then, it's easily possible that threr are other files named "test.txt" that 7-zip will find and add to the archive, too. That's possibly not what you need. If your d: drive isn't dedicated to the weblogs only, then it would be better if your example looked like this:
Ok - I (finally) see what you're saying now. I will just need to tailor my script to determine which month to archive and then have the script write out a command for each day of the web logs. Thanks!!!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2011-04-19
And maybe even simpler: you can tell 7-zip to add files by mask. Let's assume that log files have the folowing name pattern: MDDYYYY.log. Then all you need to add the april logs is
"c:\program files\7-zip\7z.exe" a -t7z -y -r WEBLOGS.7z "d:\4??2011.log"
The question marks will do everything you need.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello,
I wrote a script that will take in a list of files and 7zip will pass in the array and zip of the files. It works to an extent, but not quite how I need it to. I'm archiving sets of IIS web logs in a directory. Problem being is that under each web folder, the IIS log names are the same format. I need it to recurse the directories, but somehow my command line isn't doing that even when I include the -r. It will just keep overwriting until it gets to the last set. Here's my vbscript sample:
So it should be inputting:
"c:\program files\7-zip\7z.exe" a -t7z -y -r WEBLOGS.7z strFILE, 0, True
strFile is an array that gets passed through a txt file containing the list of files to be zipped up and also has the full path. As I mentioned, it is archiving, but since the directories are not being passed in, it just overwrites the archived files until it hits the last ones. I found part of the command line example on the web and I'm unsure of what the last part does (0,True).
Any help would be awesome!!!
Can anyone verify my command line?
the -r should include the directories in the archive, but it's not. I'm passing in a text file with a list of files (with their full path) to be zipped. These are IIS web logs for about 30 different sites. They are in different folders, but in the end, they all have the same file names as it's formatted by the date.
Have you tried downloading the command line version of 7-zip and running your script so that it references 7za.exe (instead of 7z.exe)? See my earlier forum reply to someone who asked about where to find the command line version. It would be cool if the solution turns out to be as simple as this! :-)
Nope - still didn't work :(
Maybe it's the logic of my script. I'm loading all the files into an array. In a function, I am running a For loop to go through each line of the text file and within the loop, is the 7za command. The script works to an extent, but it's just not recursing the directories and in the end, just overwriting the initial files.
Not to sound silly, but I've been looking over the line in your example immediately above starting with "oShell.Run…" and I don't see a "-r" in there anywhere…. Could it be as simple as that? :-)
Sorry, i was messing around with the settings and i copied/pasted at the wrong time. I've used -r in there.
Any other ideas???
Thanks
Maybe you're writing more script than you need to, as 7-zip may have that functionality built into it already. Consider the following section of 7-zip's command line help file … :
For list files, 7-Zip uses UTF-8 encoding by default. You can change encoding using -scs switch.
Multiple list files are supported.
For example, if the file "listfile.txt" contains the following:
My programs\*.cpp
Src\*.cpp
then the command
7z a -tzip archive.zip @listfile.txt
adds to the archive "archive.zip" all "*.cpp" files from directories "My programs" and "Src".
… so maybe another approach you could try is to write to a text file (e.g., MyFiles.txt) the path(s) to the items you want recursed and zipped and then invoke 7-zip's command line with the "@MyFiles.txt" command line syntax. (I'm giving you my best ideas at a solution. I hope one of them finally helps out. :-) )
Actually, the first part is what I am doing. I'm scanning a folder/subfolders for logs older than X amount of days and the file (with the full path) get written to a line in a text file.
So with the second part, I can just put @myfiles.txt instead of strFile and it will read each line in the text file? I will give that a shot.
Thanks!
Please post if you're successful with that "@" syntax. It took me a little time to get "up to speed" understanding what you were doing since I don't know vbscript that well. I think you were on the mark about the script's logic. Another idea that just came to mind with respect to debugging your original script would be to name the 7-zip archive(s) with (a) name(s) based on what the current value of "i" is in your For loop (e.g. WEBLOGS1.7z, WEBLOGS2.7z, etc.). That would probably illustrate what's happening but would also give you "i" number of 7-zip archives (probably not what you'd want, even if you subsequently archived all of those into one final additional 7-zip archive).
Excuse me, but if I get the problem right, it seems that there's no problem.
I tried to do a simple test. I created a directory with some subdirectories and sub-subdirectories, and put some files to each of the directories. Many files have the same name: tst.txt, but some had different names. Then I executed the next command line:
"c:\program files\7-zip\7z.exe" a -t7z -y -r WEBLOGS.7z "D:\test\tst.txt"
It have successfully created the archive named WEBLOGS.7z with all the subdirectories that contained the files named tst.txt (and only those), all files were in place. This is the case even when there is no "D:\test\tst.txt" itself, only "D:\test\subdir\tst.txt".
If I undertstand the problem, you try to make an archive of all the files in the subdirectories of a directory, and all these files have the same name (possibly defined by a date). Then all your script has to do is define the file name it wants to add to the archive, and then execute the command
"c:\program files\7-zip\7z.exe" a -t7z -y -r WEBLOGS.7z "drive-letter:\path-to-root-dir\filename.fileext"
No need to specify full path to every file, as it will be handled automatically by 7-zip's -r switch.
By the way, the last arguments to the Run method are intWindowStyle and bWaitOnReturn (see http://msdn.microsoft.com/en-us/library/d5fk67ky.aspx).
Best regards, Mike.
Thanks Mike - I will take a look on Monday. I didn't realize I could just pass in the text file containing the list of files. I was running the loop since I thought I had to pass in each individual file into the command. I will take a look back at Monday when I return to the office. Thank you for your help.
It's not a "text file containing the list of files" that I'm talking about.
Assuming that you have a directory structure like this:
you will need to just call
and you need not to create some file containing the full paths to each "2011-04-17.log" in the tree.
Mike,
Based on your last post, if I have a weblogs.7z file archive already and it already contains a file called d:\weblogs\4182011.log then running the command:
should add the 2nd log file and not overwrite the old file, correct?
I did the example above and it's overwriting and not recursing directories. Here is what I'm working with:
**************
d:\listoffiles.txt which contains the following lines:
My script will pass each line of the text as a string into an array. I will then run a FOR loop til the end of the text file and each string is passed into the command line as such:
I also tried putting @d:\listoffiles.txt and that did not do anything. The text file with the list of files is generated from another script as I need to archive between certain months which is why I can't just do *.log
I am currently running version 9.20.0.0
nocode99
No, I meant a different thing.
In the example you gave, if you issue the following command:
you will get the WEBLOGS.7z containing all three files. That's what I was talking about: you need to run 7-zip against the root of the directory tree, not against the real files. 7-zip will do it itself. And you need to run it only once, not many times as in your script.
However, in the example you gave, your root directory is the root directory, which may mean that there are much more directories in it. And then, it's easily possible that threr are other files named "test.txt" that 7-zip will find and add to the archive, too. That's possibly not what you need. If your d: drive isn't dedicated to the weblogs only, then it would be better if your example looked like this:
Then the command like
would only check the c:\weblogs directory and its subdirectories for the test.txt files.
Best regards.
Ok - I (finally) see what you're saying now. I will just need to tailor my script to determine which month to archive and then have the script write out a command for each day of the web logs. Thanks!!!
And maybe even simpler: you can tell 7-zip to add files by mask. Let's assume that log files have the folowing name pattern: MDDYYYY.log. Then all you need to add the april logs is
The question marks will do everything you need.