- Por que não usar
where
, em vez dir
?
Na linha de comando:
for /f tokens^=* %i in ('where .:*')do @"%~nxi"
No arquivo bat / cmd:
@echo off
for /f tokens^=* %%i in ('where .:*')do %%~nxi
file_0003.xlsx
file_0001.txt
file_0002.log
where .:*
G:\SO_en-EN\Q23228983\file_0003.xlsx
G:\SO_en-EN\Q23228983\file_0001.txt
G:\SO_en-EN\Q23228983\file_0002.log
Para recursivamente:
where /r . *
G:\SO_en-EN\Q23228983\file_0003.xlsx
G:\SO_en-EN\Q23228983\file_0001.txt
G:\SO_en-EN\Q23228983\file_0002.log
G:\SO_en-EN\Q23228983\Sub_dir_001\file_0004.docx
G:\SO_en-EN\Q23228983\Sub_dir_001\file_0005.csv
G:\SO_en-EN\Q23228983\Sub_dir_001\file_0006.odt
- Para loop obter caminho e nome:
for /f tokens^=* %i in ('where .:*')do @echo/ Path: %~dpi ^| Name: %~nxi
@echo off
for /f tokens^=* %%i in ('where .:*')do echo/ Path: %%~dpi ^| Name: %%~nxi
Path: G:\SO_en-EN\Q23228983\ | Name: file_0003.xlsx
Path: G:\SO_en-EN\Q23228983\ | Name: file_0001.txt
Path: G:\SO_en-EN\Q23228983\ | Name: file_0002.log
- Para loop, obtenha o caminho e o nome recursivamente:
Na linha de comando:
for /f tokens^=* %i in ('where /r . *')do @echo/ Path: %~dpi ^| Name: %~nxi
No arquivo bat / cmd:
@echo off
for /f tokens^=* %%i in ('where /r . *')do echo/ Path: %%~dpi ^| Name: %%~nxi
Path: G:\SO_en-EN\Q23228983\ | Name: file_0003.xlsx
Path: G:\SO_en-EN\Q23228983\ | Name: file_0001.txt
Path: G:\SO_en-EN\Q23228983\ | Name: file_0002.log
Path: G:\SO_en-EN\Q23228983\Sub_dir_001\ | Name: file_0004.docx
Path: G:\SO_en-EN\Q23228983\Sub_dir_001\ | Name: file_0005.csv
Path: G:\SO_en-EN\Q23228983\Sub_dir_001\ | Name: file_0006.odt