I have found a case that seems a bit surprising to me, related to the DIR /B command and the ~t and ~z modifiers for BAT variables. I have a test environment with some files located in a folder ("c:\users\g\documents\bat\carpeta prueba"), a TXT file (LISTA.TXT) with a list of some of those files and a BAT to obtain certain information through the DIR /B command and modifiers. The BAT is as follows:
@echo off
set carpresp=c:\users\g\documents\bat\carpeta prueba
set listarch=c:\users\g\documents\bat\carpeta prueba\lista.txt
rem pushd %carpresp%
for /f "tokens=* usebackq" %%x in ("%listarch%") do for /f "tokens=*" %%a in ('dir /b "%carpresp%\%%x"') do echo %%a %%~ta %%~za %%~na
rem popd
If I run it by enabling PUSHD/POPD, I get all the information, but if I run it as shown, the information associated with the ~t and ~z modifiers does not appear, as can be seen in the attached trace:
C:\Users\g\Documents\BAT>type "c:\users\g\documents\bat\carpeta prueba\lista.txt"
backup_pba.bak
backup_salida.bak
backup_kk.bak
backup_result.bak
cataratas.pdf
backup_info.bak
petroglifos.gpx
C:\Users\g\Documents\BAT>dir "c:\users\g\documents\bat\carpeta prueba"
El volumen de la unidad C es Windows8_OS
El número de serie del volumen es: BA10-8F02
Directorio de c:\users\g\documents\bat\carpeta prueba
31/08/2022 09:50 <DIR> .
31/08/2022 09:50 <DIR> ..
20/07/2022 08:37 <DIR> alabamaCarp
30/08/2022 18:38 80 backup_info.bak
30/08/2022 18:37 315 backup_kk.bak
30/08/2022 18:38 105 backup_lista.bak
30/08/2022 14:46 2.865 backup_pba.bak
30/08/2022 18:38 103 backup_result.bak
30/08/2022 18:27 233 backup_salida.bak
02/08/2022 10:30 100.874 Cataratas.pdf
31/08/2022 09:51 118 lista.txt
16/08/2022 16:00 96.726 Petroglifos.gpx
02/08/2022 07:07 102 result.txt
10 archivos 201.521 bytes
3 dirs 499.963.985.920 bytes libres
C:\Users\g\Documents\BAT>type pba1.bat
@echo off
set carpresp=c:\users\g\documents\bat\carpeta prueba
set listarch=c:\users\g\documents\bat\carpeta prueba\lista.txt
rem pushd %carpresp%
for /f "tokens=* usebackq" %%x in ("%listarch%") do for /f "tokens=*" %%a in ('dir /b "%carpresp%\%%x"') do echo %%a %%~ta %%~za %%~na
rem popd
C:\Users\g\Documents\BAT>pba1
backup_pba.bak backup_pba
backup_salida.bak backup_salida
backup_kk.bak backup_kk
backup_result.bak backup_result
Cataratas.pdf Cataratas
backup_info.bak backup_info
Petroglifos.gpx Petroglifos
C:\Users\g\Documents\BAT>type pba1.bat
@echo off
set carpresp=c:\users\g\documents\bat\carpeta prueba
set listarch=c:\users\g\documents\bat\carpeta prueba\lista.txt
pushd %carpresp%
for /f "tokens=* usebackq" %%x in ("%listarch%") do for /f "tokens=*" %%a in ('dir /b "%carpresp%\%%x"') do echo %%a %%~ta %%~za %%~na
popd
C:\Users\g\Documents\BAT>pba1
backup_pba.bak 30/08/2022 14:46 2865 backup_pba
backup_salida.bak 30/08/2022 18:27 233 backup_salida
backup_kk.bak 30/08/2022 18:37 315 backup_kk
backup_result.bak 30/08/2022 18:38 103 backup_result
Cataratas.pdf 02/08/2022 10:30 100874 Cataratas
backup_info.bak 30/08/2022 18:38 80 backup_info
Petroglifos.gpx 16/08/2022 16:00 96726 Petroglifos
C:\Users\g\Documents\BAT>
Can someone explain this behavior to me? Thank you,
GGG