(TLDR see last paragraph)
Below code I have cobbled together with information from other threads in this forum and others. I am very new to this code/language so I don't have a clue how to optimize this.
Here is what I am trying to achieve with this code.
script outputs to a .log instead of command window
script searches for a .dat file in "M:\AnalysisDrop\"
if a .dat file is detected (
script automatically creates a subfolder "M:\AnalysisDrop\title_date_time"
file is moved into the folder
file is opened with the program C:\Analysis\Analysis.exe
wait 5 seconds
goto top (repeat forever)
this script will continuously repeat for what I hope to be a very long time. Will I run into issues with too many "set" commands? I ran into some issue with doing "SETLOCAL EnableDelayedExpansion" and SETLOCAL DisableDelayedExpansion
@Echo off echo Script 1 Initiated @echo on for /f "tokens=2 delims==" %%I in ('wmic os get localdatetime /format:list') do set datetime=%%I set datetime1=%datetime:~0,8%_%datetime:~8,6% SETLOCAL EnableDelayedExpansion SET LOGFILE=Script1_LOG_%datetime1%.log call :top >> %LOGFILE% exit /b 0 :top for %%f in (*.dat) do ( set datetime1=%datetime:~0,8%_%datetime:~8,6% set foldername=%%~nf_%datetime1% md "!foldername!" move "M:\AnalysisDrop\%%~nf*.dat*" "M:\AnalysisDrop\%%~nf_%datetime1%\" pushd M:\AnalysisDrop\%%~nf_%datetime1%\ C:\Analysis\Analysis.exe '%%~nf.dat' popd ) timeout /t 5 /nobreak goto top exit /b 0
I honestly dont need the "for" loop but i'm not sure how to do otherwise (tried to replace "for" with "if", no success. Also, the "datetime1" variable wont update, so if I try to run multiple .dat files of the same name, it writes over the previous one in the same subfolder, which I can live with but prefer not to have.
So to clarify my questions:
1. How do i do this without the "for" loop? I understand this may be causing my issue of the datetime variable not updating.
2. I used the "goto" command to continuously loop this script, should I use something different?