Loop over folder string and parse out last folder name

后端 未结 13 1478
-上瘾入骨i
-上瘾入骨i 2020-12-03 05:39

I need to grab the folder name of a currently executing batch file. I have been trying to loop over the current directory using the following syntax (which is wrong at prese

13条回答
  •  生来不讨喜
    2020-12-03 06:14

    To return to the original poster's issue:

    For example, given the following path: C:\Folder1\Folder2\Folder3\Archive.bat I would expect to parse out the value 'Folder3'.

    The simple solution for that is:

    for /D %%I in ("C:\Folder1\Folder2\Folder3\Archive.bat\..") do echo parentdir=%%~nxI
    

    will give 'Folder3'. The file/path does not need to exist. Of course, .... for the parent's parent dir, or ...... for the one above that (and so on) work too.

提交回复
热议问题