In a batch file, I am trying to figure out how to remove characters at front/back of an command echo'd data. Not specifically with a directory, but for sake of example. Is there a way to strip characters at front or back of data as it is written to a file?
EXAMPLE: dir /b *.txt >dir.txt
This result would save the filenames of a directory: filename.txt thisistest.txt hardquestion.txt
but I would like to strip out last 4 characters of the filenames so it would echo to dir.txt only the filename: filename thisistest hardquestion
>dir.txt (for %%a in (*.txt) do echo %%~na)
for
command will iterate over the indicated set of files and for each one, a reference to the file is stored in the replaceable parameter ( %%a
in this case) and the code after the do
clause executed.
In this case, the code executed for each of the files is echo %%~na
, echo the name of the file referenced by %%a
All the for
command output is redirected to the final file.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.