I need to go through all the directories except one (named "FORBIDDEN"), and to print for each of them all the files they contain.
So I wrote a batch script like this:
@echo off
for /f "tokens=*" %%G in ('dir /b /s /a:d %cd%') do ^
if %%G NEQ C:\Users\ME\FORBIDDEN (dir /a-d %%G)
But the part (dir /ad %%G)
is not good because I get some errors saying that files were not find.
So, for each round of the loop, how to list all files present in the directory (whose path is in %%G
) ?
Cheers
for /d /r %%d in (*) do if not "%%~nxd"=="FORBIDDEN" 2>nul dir /a-d "%%d"
For each folder if it is not the excluded one, show its contents
edited to adapt to comments
To only include the files with full path
for /d /r %%d in (*) do if not "%%~nxd"=="FORBIDDEN" (
for %%f in ("%%~fd") do echo "%%~ff"
)
Another option (that also includes files in the current folder) could be
dir /a-d /s /b | find /v "\FORBIDDEN\"
Get the full list and filter it, to only retrieve the lines that does not make reference to the excluded folder
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.