- Mengapa tidak digunakan
where
saja dir
?
Di baris perintah:
for /f tokens^=* %i in ('where .:*')do @"%~nxi"
Dalam file 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
Untuk secara rekursif:
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
- Untuk loop dapatkan jalur dan nama:
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
- Untuk perulangan, dapatkan jalur dan nama secara rekursif:
Di baris perintah:
for /f tokens^=* %i in ('where /r . *')do @echo/ Path: %~dpi ^| Name: %~nxi
Dalam file 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