|
Answer» Hello, I am trying to zip a file using the zip utility that comes with windows 7, how can I do this in a batch file? I can not download any third party software and have to use what is included in windows due to admin rights.
As of right now I have it copy, rename and add date then move it to a backup folder but I need to zip it as well.
Thanks!
Code: [Select]@echo off title BackUp My DATABASE
::========Set the date as day-month-year========:: SET currdate= %date:~-10,2%-%date:~-7,2%-%date:~-4,4%
::========Set where your going to backup folder is located========:: SET backupdir="X:\MyFolderName\Backups"
::========Set your backup command========:: ::========http://ss64.com/nt/xcopy.html========:: SET backupcmd=xcopy /s /c /d /e /H /i /r /y
::========Copy and move DB to a folder named Backups and rename the file and add the current date========:: %backupcmd% "X:\MyFolderName\MyFolderName\MyFileName.accdb" "%backupdir%\bak_%currdate%_MyFileName.accdb"
::\\\\\\\\DELETE OLD FILES START////////:: :: Searches for any file(s) older than 300 days (based on the Last Modification Date attribute) :: in the path %backupdir% and will execute del @file where del == delete, @file is the variable which holds the filename. :: Source-http://ss64.com/nt/forfiles.html
FORFILES /p %backupdir% /d -300 /c "cmd /c del @file"
::\\\\\\\\\DELETE OLD FILES END/////////::
pauseIt's not exposed through batch, and even using it through VBScript is rather involvedGreetings oxicottin, What about using makecab.exe to create a cabinet file or must your resulting file be in the zip format only?
Good luck!And why, exactly, do you not have admin privileges? If this is a work computer, and this is a work task, why can't the boss pony up for WinZip like mine did? Or if the destination folder is NTFS, use the Windows 7 native compact command? Or it's easy enough in Powershell (also native to Windows 7), and therefore, by a hybrid script, from batch.
I don't care if its in zip format as long as I can use zip to extract it. What exactly do I have to do to "makecab.exe to create a cabinet file" and my plant doesnt have a tech at it so were kinda on our own and if I ask it will take forever and if they do come they always screw something up... lol im better off not doing it or doing it myself.
Thanks!oxicottin, A cabinet file is different than a zipped file thus you can not use "Zip" to do the EXTRACTION. To extract the contents of a cabinet file you will need to use expand.exe. Makecab.exe and Expand.exe are indigenous to Windows.
Using makecab.exe the file(s) will be compression but you will not be able to right click on the file and extract its contents. A second 'expand' batch file would need to be written. (or use the command prompt)
From a command promt have a looky loo at: makecab /? expand /?
Does that help you?yes its not what im looking for. I will have to see if they will let me install zip or something other. Thanks everyone!Here's a VBS script that will zip a file - POSTED today to another forum.
It seems to have a filesize limitation of around 1GB. The last line to delete the source file is REMed out.
Code: [Select] Option Explicit Dim FileToZip, Result Dim oShell Dim file Dim oFileSys Dim winShell FileToZip = "C:\Program Files\logs\File_2013-04-29.log" Result = "C:\Program Files\logs\File_2013-04-29.log.zip" Set oShell = CreateObject("WScript.Shell") Set oFileSys = CreateObject("Scripting.FileSystemObject") Set file = oFileSys.CreateTextFile(Result, True) file.Write "PK" & Chr(5) & Chr(6) & STRING(18, 0) file.Close Set file = nothing set winShell = createObject("shell.application") winShell.namespace(Result).CopyHere FileToZip wScript.Sleep(5000) 'oFileSys.DeleteFile FileToZip
|