问题
I'm just past a beginning batcher (probably more like a butcher) and have been fighting with this far too long (I've found some suggestions and tried them but can't seem to make any of them work - probably UE). I have a file on a Windows 2003 machine that I created in with a batch file (dir_list.txt) that looks like:
"t001wp"
"w003th"
"b005ku"
"k009dp"
.
.
.
.
I want to strip out the double quotes. Thanks in advance for any help.
回答1:
Search help for the "for" command and the answer is near the bottom of the help. The %%~i will automatically strip the quotes. If there are spaces in the quoted text you will need to use "tokens=*" to capture the entire string in quotes. Hope this helps.
@echo off
for /f "tokens=*" %%i in (x) do echo %%~i
回答2:
@echo off
for /F "usebackq delims= " %%j in (dir_list.txt) do (
echo %%~j>> new_dir_list.txt
)
Update: Edited after bobbogo's suggestion.
Update2: Edited to consider trailing spaces.
回答3:
Maybe:
type nul>output.txt
setlocal enabledelayedexpansion
for /f %%X in (my_file.txt) DO (
set line=%%X
set line=!line:"=!
echo.!line!>>output.txt
)
来源:https://stackoverflow.com/questions/5328131/removing-double-quotes-in-a-batch-program-in-windows-2003