2015-05-31 4 views
1

Я работал над Batch-скриптом, чтобы найти папку в каталоге, и получил ее работу, благодаря ранее найденным вопросам о stackoverflow, однако, несмотря на то, что он работает как надо, у меня мало вопрос.Batch Script Explanations (For Cycle)

for /d /r "%directory%" %%a in (*) do if /i "%%~nxa"=="%foldername%" set "folderpath=%%a" 
echo "%folderpath%" 

Какие %%, (*) и %% - NXA линии для?

Аналогично в этом коде (поиск файла в каталоге)

for /r "%directory%" %%a in (*) do if "%%~nxa"=="%filename%" set p=%%~dpnxa 

Что делает %% ~ dpnxa делать?

Что касается google, я не смог найти никаких объяснений или официальных сайтов MS.

ответ

5

отрывок из for помощи:

In addition, substitution of FOR variable references has been enhanced. 
You can now use the following optional syntax: 

    %~I   - expands %I removing any surrounding quotes (") 
    %~fI  - expands %I to a fully qualified path name 
    %~dI  - expands %I to a drive letter only 
    %~pI  - expands %I to a path only 
    %~nI  - expands %I to a file name only 
    %~xI  - expands %I to a file extension only 
    %~sI  - expanded path contains short names only 
    %~aI  - expands %I to file attributes of file 
    %~tI  - expands %I to date/time of file 
    %~zI  - expands %I to size of file 
    %~$PATH:I - searches the directories listed in the PATH 
        environment variable and expands %I to the 
        fully qualified name of the first one found. 
        If the environment variable name is not 
        defined or the file is not found by the 
        search, then this modifier expands to the 
        empty string 

%%a является маркер, используемый в течение цикла, %%~nxa (на каждой итерации будет соответствовать обрабатываемый файл) это имя и расширение файла. * - это дикая карта, которая означает каждый символ.

wildcards- http://ss64.com/nt/syntax-wildcards.html

цикл - http://ss64.com/nt/for.html