且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

For 循环读取带空格的文件名

更新时间:2022-02-24 08:14:12

for /R %%F in (*.CDP) do (
    for /F "usebackq delims=" %%A in ("%%~fF") do (

变化:

  1. 此代码不是检索所有标记,而是禁用分隔符

  1. Instead of retrieving all tokens, this code disables the delimiters

由于文件名被引用,usebackq被include表示我们处理的不是直接字符串,而是文件内容

As the file name is quoted, usebackq is include to indicate that we are not processing a direct string, but the file contents

由于代码递归文件夹,如果想法是读取文件内容,那么不是直接使用文件名和扩展名,而是需要完整路径,因为文件位置可能与当前目录不同

As the code recurses folders, if the idea is to read the file contents then instead of directly using the file name and extension, the full path is needed as the file location can differ from current directory