Get modification Time and Filename

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
sugram
Posts: 3
Joined: 22 Jun 2021 21:43

Get modification Time and Filename

#1 Post by sugram » 22 Jun 2021 22:07

Hello

I would like to determine the date of modification and the filename of a directory.
I already get the date, but with the variable %% i I get the full UNC path.
But I only need the * .pvx file names without \\Sharename\xyz\123\xxx 123\

My Test Batch

Code: Select all

for /F "delims=" %%i in ('"dir /s /b /a-d "\\Sharename\xyz\123\xxx 123\*.pvx" "') do (echo set file_date=%%~ti %%i )
I hope that someone could give me a tip here

Many Thanks

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Get modification Time and Filename

#2 Post by aGerman » 23 Jun 2021 03:52

FOR variables support several modifiers. (run FOR /?)
Use %%~nxi to get name and extension only.

Steffen

sugram
Posts: 3
Joined: 22 Jun 2021 21:43

Re: Get modification Time and Filename

#3 Post by sugram » 23 Jun 2021 04:16

Hello

I read that, but unfortunately it doesn't work for me.

Code: Select all

for /F "delims=" %%i in ('"dir /s /b /a-d "\\Sharename\xyz\123\xxx 123\*.pvx" "') do (echo set file_date=%%~ti %%nxi)
output

Code: Select all

C:\Users\hrf3bw\Desktop>(echo set file_date=10.09.2020 13:21 %nxi )
set file_date=10.09.2020 13:21 %nxi

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Get modification Time and Filename

#4 Post by aGerman » 23 Jun 2021 05:56

You forgot the tilde (~).

Steffen

sugram
Posts: 3
Joined: 22 Jun 2021 21:43

Re: Get modification Time and Filename

#5 Post by sugram » 23 Jun 2021 21:30

Oh yes you're right.

For the test, I had written the ~ in front of the %% and not %% ~.
I'm annoyed myself that I haven't seen it.
But thanks for the input :-)


Now it works :-)

Post Reply