0

I'm looking for some tips in troubleshooting the failure of call to expand t, z, and a.

Example:

for /F "delims=" %%F in (
  'dir /b "%source%\*." '
) do if not exist "%target%\%%~nF.jpg" copy "%source%\%%~F" "%target%\%%~nF.jpg"

for /F "delims=" %%B in (
  'dir /b "%target%\*.jpg"'
) do echo Size: %%~fB

This example runs perfectly, but when I edit that last line to be

%%~zB

I get multiple lines of output that just say Size:

Separately, if I just run

for /F "delims=" %%B in (
  'dir /b "%target%\*.jpg"'
) do echo Size: %%~zB

in a batch file by itself, it runs as expected, showing me actual file sizes. I've tried the same with %~a and %~t and get the same results; no output when run with the other copy sequence, and correct output when run alone.

Not sure what's going on here since %~f works just fine. Thanks to anyone that can help. I don't want to run two batch files. Shouldn't be necessary IMHO.

c.diaz
  • 17
  • 5

1 Answers1

2

I'd suggest you carefully examine the output using %%~fB. The report is probably showing the current directory, not %target% (at least, it does for me...)

Fix:

PUSHD %target%

for /F "delims=" %%B in (
  'dir /b "*.jpg"'
) do echo Size: %%~zB

POPD
Magoo
  • 77,302
  • 8
  • 62
  • 84
  • Winner winner! Thanks for the suggestion. Turns out that when I ran the shorter version, I was running it from the directory that had all the target files. Back to the drawing board now to figure out if I can get this to work from outside the target directory...Unless you can tell me up front that it won't work, saving just a few shreds of sanity for me... – c.diaz Mar 26 '17 at 01:42
  • Just gave in and assumed the PUSHD and POPD commands. All is calm now on the western front. Thanks again! – c.diaz Mar 26 '17 at 02:09