Click here to Skip to main content
15,886,625 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi Below code looks for a file present in a directory and if present sents it to a log file, but is not executing correctly.

Even if the file is not present the goto statement executes and echo writes the output to log file

I need a script which can run continously and log the file arrival arrival time when it is SFTPd

@echo off
 
set dt=%DATE:~6,4%_%DATE:~3,2%_%DATE:~0,2%
set dt=%dt: =0%
:loop
if exist "c:\Systems\SLU_MI\PROD_IMPORT\Netsol_payments*.xml" (
goto found
)else( 
goto check 
)
:found
ECHO Netsol Payments File TIME: %TIME% - %DATE% >>  c:\Systems\SLU_MI\PROD_IMPORT\Netsol_File_Logs\Netsol_File_Time_%dt%.txt
:check
if exist "c:\Systems\SLU_MI\PROD_IMPORT\Netsol_accounts*.xml" (
goto found2
) else (
goto loop
)
:found2
ECHO Netsol Account File TIME: %TIME% - %DATE% >>  c:\Systems\SLU_MI\PROD_IMPORT\Netsol_File_Logs\Netsol_File_Time_%dt%.txt


What I have tried:

tried above code mentioned in the question
Posted
Comments
RedDk 30-Jul-18 11:15am    
Read this:
Terminate and stay resident program - Wikipedia[^]
I would suggest that such technology as a batch script which runs as a monitor of file use is going to do all the things this wikipedia page warns that TSR would do.

See that "Related Questions" list down there on the lower right of your webbrowser screen? Thinking about doing such a thing isn't listed. My take on this list is that if I can't understand what all these suggestions are doing here, MY question is not a good one.

Try googling "inexpensive file monitor software".
Richard MacCutchan 31-Jul-18 5:20am    
"but is not executing correctly."
We cannot guess what that means. Please edit your question and explain exactly what does happen, and why it is not correct.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900