Search code examples
windowsbatch-filefor-loopzipalign

How to get only filename + extension of for variable


I want to run the same command on several files in a directory on Windows 8:

for /r %1 %%G in (*.apk) do zipalign -f -v 4 %%G %2

The problem is that %%G is expanded to full path name, but I only need the filename itself. How can I do it?
(zipalign takes 2 parameters: sourcefile and destfile).


Solution

  • Use %%~nxG

    See https://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/percent.mspx for all possible substitutions.