当前位置: 动力学知识库 > 问答 > 编程问答 >

batch file - list only folders in a directory

问题描述:

I'm trying to get a user to enter a folder name from those listed in a particular directory. The following gives me the list but contains the full path which is likely to confuse the user. My string %officeL% refers to the path location e.g. c:\folder1\folder2\

for /d %%X in (%officeL%*) do echo %%X

Ideally I'd like to just get a simple list of just the folders in the final location specified in my string e.g. client1, client2, client3...

网友答案:

You could use batch parameter modifiers:

for /d %%X in (%officeL%*) do echo %%~nX

See http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/percent.mspx?mfr=true or

for /?

for more information.

网友答案:

Following will work for you

    @Echo OFF
    FOR /F %%G IN ('DIR /b %officeL%') DO CALL :Folders "%%G" 

    EXIT /b

    :Folders
    SET str1=%~1
    Echo %str1%
分享给朋友:
您可能感兴趣的文章:
随机阅读: