Asking Better Questions<\/a> , it’ll help you get more direct answers, and spend less time explain, re-explaining, etc.<\/p>\nLast, can you show everyone the code that you have and tell us what you’ve tried (changed from the original) to accomplish your task? It is not clear what you want, looking at the original code, your question can mean 2 different things that I see. It could mean always archive 1 static folder located in a specific place, or it could mean archiving only the top level folders in a specific directory.<\/p>\n
Note for the thread<\/em><\/p>\nThe code he is talking about is written for AutoHotKey a scripting software.<\/p>","upvoteCount":0,"datePublished":"2015-11-10T22:19:52.000Z","url":"https://community.spiceworks.com/t/zip-files-from-1-folder-and-archive-daily/450322/4","author":{"@type":"Person","name":"zalittle","url":"https://community.spiceworks.com/u/zalittle"}},{"@type":"Answer","text":"
My goal is to always archive 1 static folder located in a specific place. I have messed around with the code a bit and this is what I have now… which still doesn’t work.<\/p>\n
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.\n; #Warn ; Enable warnings to assist with detecting common errors.\nSendMode Input ; Recommended for new scripts due to its superior speed and reliability.\n;SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.\n;Created By: Zach Little\n;11/5/15\n;Please see https://community.spiceworks.com/topic/1276602-zip-files-from-multiple-folders-daily?page=1#entry-5201072 for details information about the creation of this script\n;Please leave the above lines in for credit\n\n;Link to standalone 7zip:\t\thttp://www.7-zip.org/a/7z1510-extra.7z\n;The only file in here that you need is 7za.exe, place this somewhere you know where it is.\n;Modify the below line to the location of the downloaded 7za.exe file.\nPathToEXE = C:\\Program Files\\7-Zip\\7za.exe\n\n;Location of Final Archive\nFinalArchive = C:\\temp2\\%A_MM%-%A_DD%-%A_YYYY% %A_Hour%%A_Min%.zip\n\n;Modify below to set the location of the folders to archive. These do not have to be on your desktop, I just used that for testing. You can replace %A_Desktop% with a network path such as '\\\\server1\\directroy' or something like 'C:\\directory\\whatever'\n;To Add more follow the format Below\n;VARNAME = FOLDERLOCATION\\FOLDER\nArchive1 = C:\\toplevel\\process\\subfolder1\n;Archive2 = C:\\toplevel\\process\\subfolder2\n;Archive3 = %A_Desktop%\\Folder3\n;Archive4 = %A_Desktop%\\Folder4\n\nZIP()\nEXITAPP\nreturn\n\nZIP()\n{\n;If you add more folders above, please be sure to add the 2 template lines below and update the VARNAME to what you listed above! Be sure to remove the ; at the begininning of your new lines.\n;RunWait %PathToExe% a %FinalAchive% %VARNAME%\n;Sleep 5000\nRun %PathToExe% a %FinalArchive% %Archive1%\n;Sleep 5000\n;RunWait %PathToExe% a %FinalArchive% %Archive2%\n;Sleep 5000\n;RunWait %PathToExe% a %FinalArchive% %Archive3%\n;Sleep 5000\n;RunWait %PathToExe% a %FinalArchive% %Archive4%\n}\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2015-11-11T13:12:37.000Z","url":"https://community.spiceworks.com/t/zip-files-from-1-folder-and-archive-daily/450322/5","author":{"@type":"Person","name":"jeffgman","url":"https://community.spiceworks.com/u/jeffgman"}},{"@type":"Answer","text":"\n\n
<\/div>\n
jeffgman:<\/div>\n
\nMy goal is to always archive 1 static folder located in a specific place. I have messed around with the code a bit and this is what I have now… which still doesn’t work.<\/p>\n
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.\n; #Warn ; Enable warnings to assist with detecting common errors.\nSendMode Input ; Recommended for new scripts due to its superior speed and reliability.\n;SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.\n;Created By: Zach Little\n;11/5/15\n;Please see https://community.spiceworks.com/topic/1276602-zip-files-from-multiple-folders-daily?page=1#entry-5201072 for details information about the creation of this script\n;Please leave the above lines in for credit\n\n;Link to standalone 7zip:\t\thttp://www.7-zip.org/a/7z1510-extra.7z\n;The only file in here that you need is 7za.exe, place this somewhere you know where it is.\n;Modify the below line to the location of the downloaded 7za.exe file.\nPathToEXE = C:\\Program Files\\7-Zip\\7za.exe\n\n;Location of Final Archive\nFinalArchive = C:\\temp2\\%A_MM%-%A_DD%-%A_YYYY% %A_Hour%%A_Min%.zip\n\n;Modify below to set the location of the folders to archive. These do not have to be on your desktop, I just used that for testing. You can replace %A_Desktop% with a network path such as '\\\\server1\\directroy' or something like 'C:\\directory\\whatever'\n;To Add more follow the format Below\n;VARNAME = FOLDERLOCATION\\FOLDER\nArchive1 = C:\\toplevel\\process\\subfolder1\n;Archive2 = C:\\toplevel\\process\\subfolder2\n;Archive3 = %A_Desktop%\\Folder3\n;Archive4 = %A_Desktop%\\Folder4\n\nZIP()\nEXITAPP\nreturn\n\nZIP()\n{\n;If you add more folders above, please be sure to add the 2 template lines below and update the VARNAME to what you listed above! Be sure to remove the ; at the begininning of your new lines.\n;RunWait %PathToExe% a %FinalAchive% %VARNAME%\n;Sleep 5000\nRun %PathToExe% a %FinalArchive% %Archive1%\n;Sleep 5000\n;RunWait %PathToExe% a %FinalArchive% %Archive2%\n;Sleep 5000\n;RunWait %PathToExe% a %FinalArchive% %Archive3%\n;Sleep 5000\n;RunWait %PathToExe% a %FinalArchive% %Archive4%\n}\n<\/code><\/pre>\n<\/blockquote>\n<\/aside>\nThe only error I am getting is in the<\/p>\n
Run %PathToEXE% a %FinalArchive% %Archive1%\n<\/code><\/pre>\nIf I change<\/p>\n
PathToEXE = C:\\Program Files\\7-Zip\\7za.exe\n<\/code><\/pre>\nTo<\/p>\n
PathToEXE = C:\\Program Files\\7-Zip\n<\/code><\/pre>\nAnd then change the run to say<\/p>\n
Run %PathToEXE%\\7za.exe\n<\/code><\/pre>\nIt works. Give that a try.<\/p>\n
Edit<\/em> \nHad double slashes in the code.<\/p>","upvoteCount":0,"datePublished":"2015-11-11T13:51:39.000Z","url":"https://community.spiceworks.com/t/zip-files-from-1-folder-and-archive-daily/450322/6","author":{"@type":"Person","name":"zalittle","url":"https://community.spiceworks.com/u/zalittle"}},{"@type":"Answer","text":"When I make the code change I get the following error:<\/p>\n
<\/p>\n
<\/p>","upvoteCount":0,"datePublished":"2015-11-11T14:13:17.000Z","url":"https://community.spiceworks.com/t/zip-files-from-1-folder-and-archive-daily/450322/7","author":{"@type":"Person","name":"jeffgman","url":"https://community.spiceworks.com/u/jeffgman"}},{"@type":"Answer","text":"
On line 36 you didn’t specify your archive or what it is archiving, sorry I wasn’t clear in the last post, i was just modifying the beginning of the run command, not the entire line.<\/p>\n
Line 36 should read<\/p>\n
Run, %PathToEXE%\\7za.exe a %FinalArchive% %Archive1%\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2015-11-11T14:16:47.000Z","url":"https://community.spiceworks.com/t/zip-files-from-1-folder-and-archive-daily/450322/8","author":{"@type":"Person","name":"zalittle","url":"https://community.spiceworks.com/u/zalittle"}},{"@type":"Answer","text":"That makes sense. But I’m still getting an error. I wasn’t sure if the comma after “Run” was ok, but it errors with or without it. It is the correct path to 7zip.<\/p>\n
<\/p>","upvoteCount":0,"datePublished":"2015-11-11T14:28:51.000Z","url":"https://community.spiceworks.com/t/zip-files-from-1-folder-and-archive-daily/450322/9","author":{"@type":"Person","name":"jeffgman","url":"https://community.spiceworks.com/u/jeffgman"}},{"@type":"Answer","text":"
I’m not sure what AutoHotKey is, but this can be down with a 10 line powershell command<\/p>\n
$folder = \"C:\\folder\\folder\"; # variable for the folder that gets zipped\n$zip = \"C:\\folder\\folder.zip\"; #Path to ZIP file\n\nIf (Test-Path -Path $Zip)\n{\nRemove-Item $zip; #deletes previous version of zip\n}\n\nAdd-Type -Assembly \"System.IO.Compression.FileSystem\" ;\n[System.IO.Compression.ZipFile]::CreateFromDirectory($folder, $zip) ;\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2015-11-11T14:30:47.000Z","url":"https://community.spiceworks.com/t/zip-files-from-1-folder-and-archive-daily/450322/10","author":{"@type":"Person","name":"davidr4","url":"https://community.spiceworks.com/u/davidr4"}},{"@type":"Answer","text":"Try changing it to:<\/p>\n
Run, C:\\Program Files\\7-zip\\7za.exe a %FinalArchive% %Archive1%\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2015-11-11T14:31:02.000Z","url":"https://community.spiceworks.com/t/zip-files-from-1-folder-and-archive-daily/450322/11","author":{"@type":"Person","name":"zalittle","url":"https://community.spiceworks.com/u/zalittle"}},{"@type":"Answer","text":"Thanks davidr4. I started using Auto Hot Key with a another script so I’d like to be consistent.<\/p>\n
Zach - I didn’t get an error this time, but no output file. So, I decided to remove all variables and put the direct path and it does work. However, file extension is “.7z” unlike the original script you wrote for zipping multiple folders which have “.zip” file extension. I specified .zip in the code. What do you think?<\/p>\n
Run, C:\\Program Files\\7-zip\\7za.exe a C:\\temp2\\%A_MM%-%A_DD%-%A_YYYY% %A_Hour%%A_Min%.zip C:\\toplevel\\process\\subfolder1\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2015-11-11T14:45:56.000Z","url":"https://community.spiceworks.com/t/zip-files-from-1-folder-and-archive-daily/450322/12","author":{"@type":"Person","name":"jeffgman","url":"https://community.spiceworks.com/u/jeffgman"}},{"@type":"Answer","text":"That did the trick. Thank you!<\/p>","upvoteCount":0,"datePublished":"2015-11-11T14:54:59.000Z","url":"https://community.spiceworks.com/t/zip-files-from-1-folder-and-archive-daily/450322/14","author":{"@type":"Person","name":"jeffgman","url":"https://community.spiceworks.com/u/jeffgman"}},{"@type":"Answer","text":"
Use the powershell Luke … Oh no OP’s not Luke… Still . Go for powershell as powershell 5 seems to have some built in cmndlets to archive files<\/p>\n
Read here<\/a><\/p>","upvoteCount":0,"datePublished":"2015-11-12T08:47:21.000Z","url":"https://community.spiceworks.com/t/zip-files-from-1-folder-and-archive-daily/450322/15","author":{"@type":"Person","name":"edwineekelaers2","url":"https://community.spiceworks.com/u/edwineekelaers2"}},{"@type":"Answer","text":"I actually changed the AutoHotKey script and it works perfectly. See below.<\/p>\n
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.\n; #Warn ; Enable warnings to assist with detecting common errors.\nSendMode Input ; Recommended for new scripts due to its superior speed and reliability.\n;SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.\n;Originally created By: Zach Little. Has since been modified.\n;11/5/15\n;Please see https://community.spiceworks.com/topic/1276602-zip-files-from-multiple-folders-daily?page=1#entry-5201072 for details information about the creation of this script\n;Please leave the above lines in for credit\n;Link to standalone 7zip:\t\thttp://www.7-zip.org/a/7z1510-extra.7z\n;The only file in here that you need is 7za.exe, place this somewhere you know where it is.\n;Modify the below line to the location of the downloaded 7za.exe file.\nPathToEXE = C:\\Program Files\\7-Zip\\7za.exe\nZIP()\nEXITAPP\nreturn\nZIP()\n{\n;Source folder of files to zip\nSourcePath = C:\\TEST\\OUTBOUND\\ARCHIVE\\\n;Zip file name prefix\nZipPrefix = Prefix1\n;Zip file location\nZipPath = C:\\TEST\\OUTBOUND\\ARCHIVE\\ZIP\n{\n;Rename file extension\nFileMove, %SourcePath%\\*.*, %SourcePath%\\*.bak\n;Add files with new extension to source folder\nLoop, Files, %SourcePath%\\*.bak,df\n{\nRun C:\\Program Files\\7-Zip\\7za.exe a \"%ZipPath%\\%ZipPrefix%_%A_YYYY%%A_MM%%A_DD%_%A_Hour%%A_Min%.zip\" %A_LoopFileLongPath%,,hide\nprocess, wait, 7za.exe ; Make sure it's running first\nprocess, waitclose, 7za.exe ; wait's for 7za.exe to close first instead of RunWait checking for 7za.exe to close\nfiledelete, %A_LoopFileLongPath%\n}\n}\n}\nF4::\nExitApp\nReturn\n\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2015-11-13T13:49:21.000Z","url":"https://community.spiceworks.com/t/zip-files-from-1-folder-and-archive-daily/450322/16","author":{"@type":"Person","name":"jeffgman","url":"https://community.spiceworks.com/u/jeffgman"}},{"@type":"Answer","text":"if the OP runs Powershell 5 then he can use a powershell cmndlet to zip files. It’s called compress-archive<\/p>","upvoteCount":0,"datePublished":"2015-11-13T17:49:48.000Z","url":"https://community.spiceworks.com/t/zip-files-from-1-folder-and-archive-daily/450322/17","author":{"@type":"Person","name":"edwineekelaers2","url":"https://community.spiceworks.com/u/edwineekelaers2"}}]}}
zalittle
(Zach Little)
November 10, 2015, 10:19pm
4
jeffgman:
Thanks to Zach I can successfully zip files from multiple folders and archive daily with datestamp. I now tried to modify the code to zip files for only 1 folder and archive by using a datestamp. In theory this should be much simpler to accomplish, but I came to the conclusion I don’t know what I’m doing. lol
Help please?
Couple things,
First, i’d check out the community guidelines and be sure that you are familiar with what the SpiceWorks community expects of its members.
Second, check out this thread, Asking Better Questions , it’ll help you get more direct answers, and spend less time explain, re-explaining, etc.
Last, can you show everyone the code that you have and tell us what you’ve tried (changed from the original) to accomplish your task? It is not clear what you want, looking at the original code, your question can mean 2 different things that I see. It could mean always archive 1 static folder located in a specific place, or it could mean archiving only the top level folders in a specific directory.
Note for the thread
The code he is talking about is written for AutoHotKey a scripting software.