with respect to this question, i am trying to adjust the suggested script to changed needs but am failing. Here is the context:
- The script below parses through a set of files with names like
EventLog_12345.txt
- In every file it identifies the line that contains the string vVariable (example
2018-06-22 08:21:19 0133 LET vVariable = 'h**ps://somedomain.com/test/joblog.XML'
) - It gets the file name of the URL at the end of this line (
joblog
) The saves the file as a new file with a new name:
joblog_12345.txt
The following is the script suggested in the referred post, which does the job.
:: Q:\Test\2018\05\22\SO_50982243.cmd @Echo off & Setlocal EnableDelayedExpansion For /f "delims=" %%A in ('findstr /I /M "vVariable" *_*.txt ') Do ( For /f "tokens=2delims=_" %%B in ("%%~nA") Do ( For /f "delims=" %%C in ('findstr /I "vVariable" ^<"%%A"') Do Set "Line=%%C" Set "Line=!Line:/= !" For %%D in (!Line!) Do Set "NewName=%%~nD_%%B%%~xA" Echo Ren "%%~A" "!NewName!" ) )
However, when i try to do the same thing on a set of files that have different names, i am desperately failing (i played around with the
*_*.txt
piece to get this done, but with no success.)- The filenames that i need to identify are looking something like this:
Worker FFM Generator.qcc.2018_06_24_14_46_55.txt
where evereything up until the numbers start is a constant - so the filenames differ only in their numeric part. Eventually i want to save a new file (picking up the example line from above) asjoblog_2018_06_24_14_46_55.txt
Thanks a lot!