Answer the question
In order to leave comments, you need to log in
How to prevent reselection of bat files?
I don't know how to formulate the question for the title, I'll describe the whole problem:
I have a video "log", .wmv files are added to a certain folder every minute. They need to be sent to FTP, I wrote the following code
@echo off
ren "C:\Users\NAME\Documents\log\Videos\*.wmv" *.zip
"C:\folder2\WinSCP\WinSCP.com" ^
/log="C:\folder2\WinSCP\WinSCP.log" /ini=nul ^
/command ^
"open ftp://логин:пароль@сервер/" ^
"synchronize remote -criteria=time ..\send\ /log" ^
"put ..\send\*.zip /logServer/" ^
"exit"
set WINSCP_RESULT=%ERRORLEVEL%
if %WINSCP_RESULT% equ 0 (
echo Success
del /q C:\Users\NAME\Documents\log\Videos\*.zip
) else (
echo Error
)
exit /b %WINSCP_RESULT%
Answer the question
In order to leave comments, you need to log in
Thank you all, I'll post the finished code, maybe it will be useful to someone
@echo off
Set Process=winscp
tasklist | Find /i "%Process%.exe" || (goto Else)
echo net
Goto end
:ELSE
ren "C:\Users\name\Documents\log\Videos\*.wmv" *.zip
"C:\Users\name\Documents\log\WinSCP\WinSCP.com" ^
/log="C:\Users\name\Documents\log\WinSCP\WinSCP.log" /ini=nul ^
/command ^
"open ftp://логин:пароль@сервер/" ^
"put ../Videos\*.zip /logServer/" ^
"exit"
set WINSCP_RESULT=%ERRORLEVEL%
if %WINSCP_RESULT% equ 0 (
echo Success
del /q C:\Users\name\Documents\log\Videos\*.zip
) else (
echo Error
)
exit /b %WINSCP_RESULT%
In the batch file, create a temporary flag file, something like this:
echo.> file.flag
At the very beginning of the batch file, check whether this file exists, if the file exists, then complete the batch file (the previous run has not yet worked), if the file does not exist, we work further ( and create this file). At the end of the work - delete the flag file.
Other options for detecting running copies of the same batch file:
1.similar to the flag file - a flag in the registry
2.using tasklist, you can check whether a process is running with the same batch file.
Side effects: if the batch file for some reason does not delete the flag file, then the next process will never start.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question