I am working with a batch file that monitors a folder and looks to see if there are any files. I do not know much about batch programming and inherited the file, but could anyone let me know if there is a way were I can read in the filename and trim a certain amount of characters from it?
The filename is always going to look like this: 12345_20131031.txt There will also be 8 characters to the right of the _ and, plus 4 characters for the ".txt"
I basically just want to grab the filename and trim everything to the right of the "_" and the extension so I am just left with: 12345
Below is the code I have for looping through the files. I have been following around with what is already there, but all I can seem to get is the full path/dir/filename of the file and I can't seem to get the right setting to just give me the filename and trim it.
Any help would be appreciated:
@ECHO OFF
set cnt= for %%a in (c:\Encoded_HL7_Vanderbilt\*.*) do set cnt=%%a
if !%cnt%!==!! exit
set "folder=%~1"
:: If more than 0 files exist begin, otherwise exit
FOR %%a IN (c:\Encoded_HL7_Vanderbilt_rob\*.*) DO (
:: need to get filename and trim everything to the right of "_" here
)
exit
:done
goto :EOF