如果目录名称带有空格字符,例如,我在互联网上找到的答案不起作用。 “相机胶卷”
我尝试使用for / dir / findstr命令,但似乎无济于事
批处理文件内容:
@echo off
for /f %%F in ('dir c:\Users\melov\Pictures /s/b/a-d ^| findstr /v ".jpg"') do echo "%%F"
@echo on
请记住,我用ECHO代替了DEL命令,以便我可以模拟问题。
"c:\Users\melov\Pictures\desktop.ini"
"c:\Users\melov\Pictures\Camera" **(PROBLEM HERE)**
"c:\Users\melov\Pictures\ControlCenter4\Scan\CCF06182019.pdf"
"c:\Users\melov\Pictures\Saved" **(PROBLEM HERE)**
"c:\Users\melov\Pictures\Screenshots\desktop.ini"
"c:\Users\melov\Pictures\Screenshots\Screenshot"
"c:\Users\melov\Pictures\Screenshots\Screenshot"
原始文件夹结构
├───Camera Roll
├───ControlCenter4
│ ├───Email
│ ├───OCR
│ ├───Scan
│ └───SharePoint
├───cunha
├───Saved Pictures
└───Screenshots
答案 0 :(得分:1)
cmd
的默认分隔符为空格,因此您只需告诉它更改默认分隔符即可。
@echo off
for /f "delims=" %%F in ('dir /b /s /a-d "c:\Users\melov\Pictures " ^| findstr /v ".jpg"') do echo "%%F"
使用tokens=*
@echo off
for /f "tokens=*" %%F in ('dir /b /s /a-d "c:\Users\melov\Pictures " ^| findstr /v ".jpg"') do echo "%%F"