Script to check and not to copy same file - batch-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.

Related

CMD/FTP to create folder using to today date & connect ftp download into created folder

I'm new to this cmd/FTP command. I would like to create a new folder at my local directory using today's date and connect to FTP to download the specific file to the newly created folder. If I manually type in command one by one at cmd, it has no issue. But when I use a batch file to run, my command stopped at FTP.
setlocal enableextensions
set name=%date:~-10,2%"-"%date:~7,2%"-"%date:~-4,4"_"job%
mkdir C:\%name%
cd C:\%name%
ftp
open 192.168.31.93
*user*
*password*
binary
cd *directory*
mget -i *.*
I did try to separate my command to two batches;
1. folder creation
2. FTP download but the file downloaded didn't go into the folder I created. the downloaded file went to C:\Document & Settings.
main batch file
#echo off
call rename.bat
ftp -i -s:ftp.txt
rename.bat
setlocal enableextensions
set name=%date:~-10,2%"-"%date:~7,2%"-"%date:~-4,4%"_job"
mkdir c:\%name%
cd c:\%name%
ftp.txt
open 192.168.31.93
*user*
*password*
binary
cd *directory*
mget *.*
close
Another method I try is using '!' when in FTP environment, then create a folder then exit back to FTP environment. This method again doesn't work with the batch file. Please help
It seems that with command extensions enabled, the working directory set by a child batch file is lost, then the batch file exits.
I'm not sure how to solve it, but you actually do not need the rename.bat file to be a separate file. This "main batch file" should work:
#echo off
setlocal enableextensions
set name=%date:~-10,2%"-"%date:~7,2%"-"%date:~-4,4%"_job"
mkdir c:\%name%
cd /d c:\%name%
ftp -i "-s:%~dp0\ftp.txt"
Also note the /d added to cd. Without that your batch will not work when started from another drive. You also have to use %~dp0 to refer to the batch file folder for the ftp.txt. As at the time ftp is called, you have changed to the target directory.
You possibly do not even need the command extensions to be enabled. So simply removing the setlocal enableextensions might solve the problem too. Though you still need the %~dp0 and /d.
I've decided to post this, although similar to the answer given, there are a couple of differences.
It creates the text file, then deletes it, (this keeps everything more portable).
I have corrected your directory name, (because of a typo).
#Echo Off
Set "Name=%DATE%"
Set "Name=%Name:~-10,2%-%Name:~-7,2%-%Name:~-4%_job"
MD "C:\%Name%" 2>Nul
CD /D "C:\%Name%" || Exit /B
( Echo open 192.168.31.93
Echo *user*
Echo *password*
Echo binary
Echo cd *directory*
Echo mget *.*
Echo close
)>"ftp.txt"
FTP -i -s:ftp.txt
Del "ftp.txt" 2>Nul
Exit /B

Batch - Why is 7zip command working improperly?

Here is my code:
net use v: \\kimezgls-rez\arxiv_mppi
net use w: \\###.###.#.##\Protokoliem\KIMEZGLS-REZ_mppi
cls
cd V:\
if not exist "V:\01_2016" mkdir "V:\01_2016"
pause
ECHO Folder is Created!
ECHO Moving Files...
MOVE "V:\??_01" "V:\01_2016"
ECHO Creating Backup!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
for /d %%X in (01_2016) do "C:\Program Files\7-Zip\7z.exe" a "%%X.7z" "%%X\"
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
ECHO Please wait few seconds...
ECHO Backup is Created!
ECHO Sending Backup to ###.###.#.##\Protokoliem\KIMEZGLS-REZ_mppi
MOVE "V:\01_2016.7z" "w:\"
pause
cls
pause
GOTO MENU
I am trying to make script, that will Create directory, name it 01_2016, and put all files, where name ends with _01 in it. Then Archive folder 01_2016 and send to Another Network folder.
Everything went well to the point, where script started to Archive folder 01_2016, but couldn't.
Scanning the drive:
WARNING: The system cannot find the file specified.
01_2016
0 files, 0 bytes
Creating archive: 01_2016.7z
Items to compress: 0
Files read from disk: 0
Archive size: 32 bytes (1 KiB)
Scan WARNINGS for files and folders:
01_2016 : The system cannot find the file specified
----------------
Scan WARNINGS: 1
For some reason it saves empty .zip folder right on my Desktop. While anylyzing whole code, I came to conclusion, that this command is only thing that doesn't want to let me successfully run script.
Thanks for any help
I guess the problem is that CD V:\ is not enough. If you are on C:\ CD V:\ won't move the scope to V:. To achieve this you have to add the /d switch to the CD command:
...
cd /d V:\
...

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

windows batch script to unzip a file

I am trying to create a batch file that gets a zipped folder for that particular date (v_date) from the sftp site and then unzip them. The zip file contains five files that are text documents. I have written batch scripts that successfully get the zip file from the remote site and save a copy of it on the local drive. I need to incorporate the unzip part in to my script.
SET v_date=%1
if [%v_date%] == [] SET v_date=%date:~10,4%%date:~4,2%%date:~7,2%
echo option batch continue>FTP_File_Get.txt
echo option confirm off>>FTP_File_Get.txt
echo open Target>>FTP_File_Get.txt
echo lcd "M:\Development\Data History\File" >> FTP_File_Get.txt
echo cd /Export/File >> FTP_File_Get.txt
echo get /Export/File/Filename_%v_date%.zip "M:\Development\DataHistory\Filename_%v_date%.zip">>FTP_File_Get.txt
echo exit>>FTP_File_Get.txt
M:\temp\apps\WinSCP\winscp.com/script="M:\Development\SFTPBatchFiles\FTP_File_Get.txt"
del FTP_File_Get.txt
This is my code to UNZIP:
SET v_date=%1
if [%v_date%] == [] SET v_date=%date:~10,4%%date:~4,2%%date:~7,2%
cd "M:\Development\Data History\"
::SET v_file="M:\Development\Data History\Filename_%v_date%.zip"
::unzip -o %v_file%
"C:\Program Files\7-Zip\7z.exe" e "Filename_%v_date%.zip"
I need to move the extracted files (6 Files) into their respective folders, Any help is greatly appreciated
To unzip the files you can use this command line:
"C:\Program Files\7-Zip\7z.exe" e "filename.zip"
#echo off
set "source=%userprofile%\Desktop\basanta\Automation\a"
set "target=%userprofile%\Desktop\basanta\Automation\b"
FOR %%A IN ("%source%\*.gz") DO (
"%programfiles%\7-zip\7z.exe" x "%%~A" -o"%target%\%%~pA"
del "%%~A" /Y
)
Use the above code by saving it to .bat file extension
Remember %userprofile% is for the directory, %programfiles% for the program files set as a variable in windows
hope that helps

seeking alteration in batch file

I have a batch file as under:
#echo off
"C:\Program Files\WinZip\WINZIP32.EXE" -min -a -ex "C:\Documents and Settings\vipul\Desktop\vipul.zip" files vipul.xls
copy vipul.zip "C:\Documents and Settings\vipul\Desktop\My briefcase"
copy vipul.zip "E:\Valuations\2009"
exit
HERE vipul.xls is the file on my desktop which is to be copied to my briefcase and same is to be ziiped and then sent to E\valu...folder.
Alteration i want here is as under:
every time the file name is getting changed, e.g. it may be sanj.xls or lago.xls and so on. (in place of vipul.xls), so how i can do this?
Just like there is printdir.bat file in xp
You could have this batch file which works for any file with .xlsextension:
#echo off
"C:\Program Files\WinZip\WINZIP32.EXE" -min -a -ex "C:\Documents and Settings\vipul\Desktop\worksheets.zip" files *.xls
copy worksheets.zip "C:\Documents and Settings\vipul\Desktop\My briefcase"
copy worksheets.zip "E:\Valuations\2009"
exit
Or, if just one that files can exist in some time:
#echo off
set filename=
if exists vipul.xls set filename=vipul
if exists sanj.xls set filename=sanj
if exists lago.xls set filename=lago
if "%filename%" == "" goto end
"C:\Program Files\WinZip\WINZIP32.EXE" -min -a -ex "C:\Documents and Settings\vipul\Desktop\%filename%.zip" files %filename%.xls
copy %filename%.zip "C:\Documents and Settings\vipul\Desktop\My briefcase"
copy %filename%.zip "E:\Valuations\2009"
exit
:end
Its not tested, but this should help you:
#echo off
REM check if supplied file name actaully exists
IF "%1"=="" GOTO END
IF NOT EXIST "%1" GOTO END
REM define output file name. Use supplied files name without extension and add ".zip"
SET OutputPath=C:\Documents and Settings\vipul\Desktop\%~n1.zip
"C:\Program Files\WinZip\WINZIP32.EXE" -min -a -ex "%OutputPath%" files "%1"
copy "%OutputPath%" "C:\Documents and Settings\vipul\Desktop\My briefcase"
copy "%OutputPath%" "E:\Valuations\2009"
:END
This batch uses the first command line parameter (%1) as input for the file to package and copy.
The first IF statements check if the file is valid. The SET command set a variable with the name of the file to create (the zip file). The remaining part is mainly the code you already have, but now uses the variables.
EDIT:
To call the batch programm, lets name it package.bat, use a syntax like this:
package "C:\Documents and Settings\vipul\Desktop\vipul.xls"
or
package "C:\Documents and Settings\vipul\Desktop\sanj.xls"
You can also use drag 'n drop and simply drop the file you want to process on the batch file package.bat to start it.
If it doesn't work, add a comment.
EDIT:
To use this batch file in your send to context menu do the following steps:
save the above code in a file and name package.bat (or anything else you want)
put in a location you want.
create a link to the batch file package.bat (right click on the file, chose create link)
move the created link file to your Send to folder (e.g. C:\Documents and Settings\vipul\SendTo
now you can select any file you want and chose the batch file command from your context menu->send to
Hope that helps.

Resources