Browse folder names only no path and put in text file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
crobertson
Posts: 20
Joined: 25 May 2012 12:34

Browse folder names only no path and put in text file

#1 Post by crobertson » 01 Feb 2015 14:48

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!

Compo
Posts: 600
Joined: 21 Mar 2014 08:50

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

#2 Post by Compo » 01 Feb 2015 15:19

This may give you an idea.

Code: Select all

For /D %%f In (%UserProfile%\Documents\*) Do Echo("Exclude Folder [%%~nxf]? "
Last edited by Compo on 01 Feb 2015 16:17, edited 1 time in total.

crobertson
Posts: 20
Joined: 25 May 2012 12:34

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

#3 Post by crobertson » 01 Feb 2015 15:37

Thanks but that just posted "Exclude folder [%%~nxA]

Compo
Posts: 600
Joined: 21 Mar 2014 08:50

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

#4 Post by Compo » 01 Feb 2015 16:17

Edited…sorry!

crobertson
Posts: 20
Joined: 25 May 2012 12:34

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

#5 Post by crobertson » 01 Feb 2015 17:44

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
)
)

Post Reply