Page 1 of 1

Browse folder names only no path and put in text file

Posted: 01 Feb 2015 14:48
by crobertson
I have a utility using xcopy excludes some folder or files. The plan is to display each folder and ask if you would like to exclude it from the backup.
This is as far as I could get;
for %%f in ("%userprofile%\Documents\*") do (
choice /c yn /m "Exclude Folder [%%~dpnxf]? "
if errorlevel 2 (
echo ... skipped
) else (
echo "%%~ff">>%~dp0exclude.txt
)
)
How do I display only the subfolder's name in My Documents without the path (My Video, My Music, etc.)
How do I display only the files names in My Documents.
Thanks to whomever I got this bit of code from.
I appreciate the help!

Re: Browse folder names only no path and put in text file

Posted: 01 Feb 2015 15:19
by Compo
This may give you an idea.

Code: Select all

For /D %%f In (%UserProfile%\Documents\*) Do Echo("Exclude Folder [%%~nxf]? "

Re: Browse folder names only no path and put in text file

Posted: 01 Feb 2015 15:37
by crobertson
Thanks but that just posted "Exclude folder [%%~nxA]

Re: Browse folder names only no path and put in text file

Posted: 01 Feb 2015 16:17
by Compo
Edited…sorry!

Re: Browse folder names only no path and put in text file

Posted: 01 Feb 2015 17:44
by crobertson
I figured it out! This gives me only the Folder name (no path) and saves it to a text file for later use.

for /f "tokens=*" %%i in ('dir "%userprofile%\Documents\" /ad /b') do (
choice /c yn /m "Exclude Folder [%%i]?
if errorlevel 2 else (
echo %%i>>%~dp0exclude.txt
)
)