Removing double quotes in a batch program in Windows 2003

隐身守侯 提交于 2019-12-12 05:58:44

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!