不工作的批处理文件重写TXT文件



我用devcon实用程序创建一个文件,以便列出连接到PC的所有usb设备,因为我需要删除隐藏设备(未使用)。现在,我想重写创建的文件中的字符串,但要在开头和"直到字符串的末尾,所以这将是一个示例

devcon received string

USBVID_8087&PID_00257&21809D95&0&2

想要重写

"@USBVID_8087&PID_00257&21809D95&0&2"

不确定是否可以在同一行中完成,或者是否需要单独添加

setlocal
cmd /c "for /f delims^=^ eol^= %%I in ('findstr /c:"USBVID" DevicesExist.txt') do @for %%a in (%%I) do @echo %%a"| findstr /c:"USBVID">DevicesExist2.txt

任何想法?,谢谢。

@ECHO OFF
SETLOCAL
rem The following settings for the source directory, destination directory, target directory,
rem batch directory, filenames, output filename and temporary filename [if shown] are names
rem that I use for testing and deliberately include names which include spaces to make sure
rem that the process works using such names. These will need to be changed to suit your situation.
SET "destdir=u:your results"
SET "outfile=%destdir%outfile.txt"
(
FOR /f "tokens=1delims= " %%b IN ('devcon findall *^|find "USBVID"') DO (
ECHO "@%%b"
)
)>>"%outfile%"
GOTO :EOF

不知道为什么你的代码这么复杂,或者为什么你没有发布一个DevicesExist.txt文件的小样本。

此代码执行devcon并将处理后的提取数据附加到目标文件中。使用>代替>>,用此批的输出替换目标文件的任何现有内容。

最新更新