Batch Script to check if Zip file extracted or not - batch-file

I am new to batch scripting and trying to write a script which will search the zip files inside a folder and extract if exists using 7-Zip. These two are working fine but i am trying to implement a logic where i need to update the log file which will have the entries which zip file got extracted and which got failed. Can someone help me here as when i tried to append log after extracting its showing all the entries present inside the zip files which i dont want. Below is script.
#ECHO OFF
SET LookForFile="C:\test\Software00*.*"
:CheckForFile
IF EXIST %LookForFile% GOTO RunELK
#ECHO TIMEOUT /T 20 >nul
GOTO CheckForFile
:RunELK
ECHO RunELK for this file : %LookForFile%
"C:\Program Files\7-Zip\7z.exe" e "C:\test\Software00*.*" -oC:\test >> C:\test\LOG1.LOG

Related

Batch file to run exe with unknown filename as arguments

I have an exe for comparing 2 .csv files. And it works when I open cmd window, drag exe, type space, drag 1st csv file, type space, and drag 2nd file.
Now I want to automate it, and the problem is it is never on the same place, nor uses the same files for comparing...
What I got so far is following in batch:
%~dp0\Komparator.exe BC101.csv BC102.csv
pause
those 2 csv files are going to be in same folder, next to .exe and .bat file... but that "same folder" is not always the same, today its one location, another day is another folder
but I dont know how to automate those 2 arguments for file names, I just want it to recognize two .csv files near .exe and .bat
Thanks in advance!
You can read csv filenames and store them into batch variables using for cycle.
Here's an example, assuming your csv files are in the same directory as the batch file.
compare.cmd
#echo off
set FILE1=
set FILE2=
for /f "delims=" %%a in ('dir /b %~dp0*.csv 2^>nul ^| sort') do (
if defined FILE1 set "FILE2=%%~a" & goto :exit_loop
set "FILE1=%%~a"
)
:exit_loop
if not defined FILE1 echo first csv file not found!& goto :eof
if not defined FILE2 echo second csv file not found!& goto :eof
%~dp0\Komparator.exe "%~dp0%FILE1%" "%~dp0%FILE2%"

Script to check and not to copy same file

My scheduler will run every 15 mins and I don’t want to copy the same file again.
I have the script below in a batch file running in the task scheduler:
cd C:\Program Files (x86)\WinSCP
FOR /R C:\Utils\TRASACTION\ICP %%f IN (*.LOG) DO TYPE NUL>%%f
Winscp.com /script=C:\Utils\TRASACTION\ICPS\download.txt >> C:\Utils\ICPS\lowe.log
set CURRENT_DATE=%date:~10,4%%date:~4,2%%date:~7,2%
xcopy C:\Utils\TRASACTION\Accounting_file\%CURRENT_DATE%\ACCOUNTING_FILE_* Y:\Transactions\In >> C:\Utils\TRASACTION\ICPS\lowe.log
exit
in line 3 that download.txt contains the below script
option echo off
option batch on
option confirm off
open sftp://icps:xxxxxxxxx#11.111.111.111
lcd "C:\Utils\ TRASACTION\ICPS"
cd /Out/1.ACCOUNTINGFILE
get %TIMESTAMP#yyyymmdd% C:\Utils\ TRASACTION\Accounting_file\
exit
I would like to insert a check in the script when the folder is available then proceed to the copy or else exit.
Or is there another way not the copy the file from the folder that has been already copied to the directory in below line?
(xcopy C:\Utils\TRASACTION\Accounting_file\%CURRENT_DATE%\ACCOUNTING_FILE_* Y:\Transactions\In >> C:\Utils\TRASACTION\ICPS\lowe.log
Thanks for your help.

Writing batch file to zip a folder using 7zip

In the image above, I have a batch file in script folder that copies all files from shr02 to Tempo using XCOPY
Tempo Folder
I'm trying to run several trial code to list all directories inside Tempo folder Like:
SET tmp="C:\Users\Marc\Desktop\Tempo\."
FOR /d %%D IN (%tmp%) do echo %%~D
However, I am getting confused of getting some folders . and .. and sometimes File Not Found
What I want to accomplish
I want to compress all the contents of Tempo folder using my 7za.exe (which is inside my script folder)
and move it to Final folder. How can I achieve this?
Update
I tried to run this block of code.
SET tmp="C:\Users\Marc\Desktop\Tempo"
SET exe="C:\Users\Marc\Desktop\script\7zip\7za.exe"
SET dst="C:\Users\Marc\Desktop\Final\tmp.7z"
%exe% "a -t7z %dst% %tmp% -r"
Error Message:
Unsupported Command
a -t7z C:\Users\Marc\Desktop\Final\tmp.7z
C:\Users\Marc\Desktop\Tempo* -r

Using XCOPY to copy files in a Zipped folder Not Working

I am trying to copy files from a path which is like as shown below
D:\XXX\XXX\SXX_FX.zip\ADMIN
By using code...
#echo off
Rem This is for copy down all the files in the directory
set origin=D:\NXG\Backup_Prod\SGL_FINANCE\WebFolder\SGL_FINANCE.zip\ADMINAPP
set drive=D:\TEST3
set d1=%date:~4,2%
set d2=%date:~7,2%
set d3=%date:~10,4%
XCOPY "%origin%" "%drive%_%d1%%d2%%d3%.zip*" /s /Y
echo "The program has completed"
But I am getting the error message. File not found - ADMIN.
Is it because I am trying to open the zipped file while copying.
Could you please throw some light on how to unzip that folder on the fly.
Using 7zip
Take a "file.txt" from "Archive.zip" to "Destination\Folder"
"C:\Program Files\7-Zip\7z.exe" e -ir!file.txt "C:\Path\To\Archive.zip" -o"C:\Path\to\Destination\Folder\"

Run bat file after save in NetBeans

I am using NetBeans 8.0.2 with PHP project. I have batch file called organizer.bat that configure to do some actions with the PHP source code.
Until now I run it manually after the code was changed.
I want that NetBeans will run my organizer.bat file automatically after I save a file in my project.
How can I configure such behavior?
One solution would be to have a batch file running in the background that periodically checks for new files in your project folder.
There's a lot of ways to do that. One way, for example, would be to output the directory files into a log file every 10 seconds.
If the new log file matches the old log file, then the contents of the directory are the same and the batch file does not need to be run.
The below commands will overwrite any existing log files.
:loop
cd C:\ProjectDirectory
xcopy logfile.log logfile2.log /f /y
dir > logfile.log
for %%I in (logfile.log) do set /a fs = %%~zI
for %%I in (logfile2.log) do set /a fs2 = %%~zI
if %fs%==%fs2% (echo "No changes in directory") else (echo "Changes in directory, run batch file.")
timeout /t 10
goto loop

Resources