This is probably a very simple question, but I\'m having trouble with it. Basically, I am trying to write a Batch File and I need it to list all the files in a certain directory
You can also try this:
for %%a in (*) do echo %%a
Using a for
loop, you can echo
out all the file names of the current directory.
To print them directly from the console:
for %a in (*) do @echo %a
where
instead dir
?In command line:
for /f tokens^=* %i in ('where .:*')do @"%~nxi"
In bat/cmd file:
@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
For recursively:
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
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
In command line:
for /f tokens^=* %i in ('where /r . *')do @echo/ Path: %~dpi ^| Name: %~nxi
In bat/cmd file:
@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
Some further reading:
[√] Where
[√] Where sample