Within a FOR loop over all files from a folder, I try to set the file time into a variable, but the variable keeps displaying the same value for all files.
Here is the .bat file content:
@echo off
for /f %%a in ('dir /b .\*.*') do (
echo a : %%a
echo ta: %%~ta
set filetime = %%~ta
echo filetime: %filetime%
)
Here is the output:
a : File1.txt
ta: 10/03/2023 17:09
filetime: "02/10/2020 17:44"
a : File2.txt
ta: 10/03/2023 17:10
filetime: "02/10/2020 17:44"
a : File3.txt
ta: 10/03/2023 14:02
filetime: "02/10/2020 17:44"
a : test.bat
ta: 10/03/2023 14:35
filetime: "02/10/2020 17:44"
My purpose was to have the actual file time (%%~ta) written in the variable filetime.