Compress/Zip a file using batch file - batch-file

I need to Compress/Zip an xls file which is generated by my macro.
I have IZarc installed on my machine.
Can somebody please suggest the batch code to zip an xlx file?

This is copy-pasted from this link.
#ECHO OFF
REM Replace space in hour with zero if it's less than 10
SET hr=%time:~0,2%
IF %hr% lss 10 SET hr=0%hr:~1,1%
REM This sets the date like this: mm-dd-yr-hrminsecs1/100secs
Set TODAY=%date:~4,2%-%date:~7,2%-%date:~10,4%-%hr%%time:~3,2%%time:~6,2%%time:~9,2%
REM Use IZArc to Zip files in folder c:\testzip and place the zip archive in C:\testmove
ECHO.
ECHO Zipping all files in C:\testzip and moving archive to c:\testmove
ECHO.
izarcc -a -cx "C:\testmove\xxxx_%TODAY%.zip" "C:\testzip\*.*"
ECHO.
ECHO Delete the files in orginal folder
DEL "C:\testzip\*.*"
PAUSE
For completeness, this script looks good without any cuts.

this utility might be something for you
https://mega.nz/#!4VZnFb6T!nqv0JTqJYLff7e44WQS6-VvhAU-Cs7WBnHZXFd9FRWc
inside there will be 2 .exe files. one for zipping and one for un-zipping. there will also be an .txt file tells you how to use it
virus-total scan
https://www.virustotal.com/da/file/5a38d605e943a1f5ce185e19eb9bda0969d370e7aad9a03575fab7852ed48157/analysis/1488190750/
EXAMPLE OF USAGE:
Zip Files
#echo off
title Zip files in folder
zip.exe zippedxlxfiles path/to/xlxfiles/*.*
pause
Zip a single file
#echo off
title Zip files in folder
zip.exe zippedxlxfiles path/to/xlxfiles/filename.xlx
pause
Note this will zip all the files in the folder you choose
Un-zip Files
#echo off
title Zip files in folder
unzip.exe zippedxlxfiles
pause
Note that this will unzip the files in the same directory as the exe itself

Related

Batch file for moving files to folders based on filenames

I use Dropbox to automatically upload all the photos/videos I take from my phone to a folder "My Dropbox\Camera Uploads". So this is full of files like:
2015-06-09 10.11.19.jpg
2015-09-11 09.28.46.mp4
I'd now like a batch file to move these to the correct folder (creating it if necessary) "..\Photos\Family\YYYY-MM" where YYYY-MM is the year and month of the photo (i.e. the first seven characters of the filename).
(It has to be a relative rather than absolute path as this Dropbox folder is shared across machines with XP, Vista and Windows 7 OSs, so the first part of the path is different on each.)
I've found similar batch files and tried to tweak them, but just can't get it to work. Many thanks for your help.
You can use this script (put it in a file with extension .bat) and start it:
#echo off
setlocal enabledelayedexpansion
rem For each file in your folder
for %%a in (*.*) do (
echo filename=%%a
rem check if the it is not our script
if "%%a" NEQ "%0" (
set foldername=%%a
set foldername=..\Photos\Family\!foldername:~0,7!
echo foldername=!foldername!
rem check if forlder exists, if not it is created
if not exist "!foldername!" mkdir "!foldername!"
rem Move (or change to copy) the file to directory
move "%%a" "!foldername!\"
)
)

Batch file to zip and upload thru ftp

im setting a backup for my pc, can someone help me set a batch file that zip the users folder rename it to date and upload it thru ftp to a server.
Tried some example online with 7zip but the dont seem to work.
thanks
Found this to zip and rename
#ECHO OFF
Title testizarc.bat
REM updated 10/22/2014
REM Replace space in hour with zero if it's less than 10
SET hr=%time:~0,2%
IF %hr% lss 10 SET hr=0%hr:~1,1%
REM This sets the date like this: mm-dd-yr-hrminsecs1/100secs
Set TODAY=%date:~4,2%-%date:~7,2%-%date:~10,4%- %hr%%time:~3,2%%time:~6,2%%time:~9,2%
REM Use IZArc to Zip files in folder c:\testzip and place the zip archive
REM in C:\testmove
ECHO.
ECHO Zipping all files in C:\testzip and moving archive to c:\testmove
ECHO.
izarcc -a -cx "C:\testmove\xxxx_%TODAY%.zip" "C:\testzip\*.*"
ECHO.
ECHO Delete the files in orginal folder
DEL "C:\testzip\*.*"
PAUSE
:end
EXIT /B 0

Need to create a batch file to extract a zip folder using winzip executable commandline and copy to multiple places

The batch file is indented to move the zip file from my local pc to server which is possible now and
the problem is like winzip is not installed on the server so is it possible to move the winzip executable along with batch file and use its commandline to copy the extracted to multiple locations.
my zip file is on my local say \testmachine1\d$\zipfiles\test.zip
(Note: This zip file may contain multiple folders and file)
the batchfile should ask the .
and I would like to move the file to \testmachine2\d$\extractedfiles\
\testmachine3\d$\extractedfiles\
\testmachine4\d$\extractedfiles\
.......................................................
\testmachine[xx]\d$\extractedfiles\
My code looks like this:
I am asking input on the zip file name, extract folder name, target and destination path along with a logfile path from the user
for /R "%destinationPath%" %%I in (%zipFileNamee%.zip") do (
echo %%I >> %LogFile%
"%ProgramFiles%\WinZip\WinZip64.exe" -e" %%~dpI" "%destinationPath%\%extractFolder%\" >> %LogFile%
I understand there are other utilities to do this like 7zip. Its is prefereable to use winzip or 7zip for the same.
After a long try I found out that there is an wzunzip.exe avaliable as portable. I can keep this one along with my batch file and run the following code to unzip a file easily.
for /R "%targetPath%" %%I in (%zipFileName%.zip) do (
wzunzip -ybc "%%I" "%targetPath%\%destinationPath%\" >> %LogFile%
)
This will find the specific file from the set of files and unzip it to the folder specified.
Cheers!!

ZIP each file in a directory that doesn't already have a ZIPped version in another folder

I am using 7-zip and Windows 2008 Server and need to ZIP each file in folder C:\Original that doesn't already have a corresponding ZIP file in C:\Archived. I would prefer doing this with a .bat file.
The C:\Original folder contains a series of .PDF files that are never changes, like so:
MyResume.pdf
HouseLayout.pdf
SurveyResults.pdf
BlahBlahBlah.pdf
I want to run a batch file that will create a ZIP file for each PDF in the C:\Archive folder, but only if the file doesn't already exist. For instance, if the C:\Archive folder already has two files in it:
MyResume.zip
BlahBlahBlah.zip
Running the batch file would ZIP just the two unzipped files, HouseLayout.pdf and SurveyResults.pdf.
I have a batch file that uses the FOR command that will ZIP all of the files in C:\Original, but I only want to ZIP those that don't already exist in C:\Archive.
Thanks
for %%f in ("c:\original\*.pdf") do if not exist "c:\archive\%%~nf.zip" (
7za a "c:\archive\%%~nf.zip" "%%~ff"
)
For each file in the indicated folder/set if not exist a file with the same name but with zip extension, create the zip file with the original file inside it.
I think you need something like this:
for /F %%I in ('dir /b c:\original\*.pdf') do set filename=%%I
set archivedFile=%filename:~,-4%
if not exist C:\archive\%archivedFile%.zip (
REM zip it up
)

Batch file to create Folder based on Date and Copy Files from One Location to Another Location?

I want to Copy/Move files in Windows XP from Desktop(a Folder) to My Document(another Folder), which was created by same Batch File on Current Date in Format DD/MM/YYYY.
This is working fine when .BAT File is in Desktop Folder.
#echo off
set date="%date:~7,2%-%date:~4,2%-%date:~10,4%"
mkdir %date%
copy *.txt \%date%
pause
Now what this .BAT is doing is, creating Folder 18-01-2013 on Desktop and coping all .TXT files in this Folder.
But this is not working,
#echo off
set date="%date:~7,2%-%date:~4,2%-%date:~10,4%"
mkdir %USERPROFILE%\My Documents\%date%
copy %USERPROFILE%\desktop\*.txt %USERPROFILE%\My Documents\%date%
pause
This .BAT File is creating these folders;
1. In C Drive>Documents
2. On Desktop (and, Chandel>My, Documents>18-01-2013, Settings>Anshuman)
Any help in this regard is highly appreciated!
Try putting lines that has file/folder names with spaces in quotes e.g. update this line
mkdir %USERPROFILE%\My Documents\%date%
to
mkdir "%USERPROFILE%\My Documents\%date%"

Resources