#1 20 Feb 2020 16:45

Ziad18
New Member
Registered: 20 Feb 2020
Posts: 1

Move file based off of timestamp in filename

hello,

I am trying to move few files based  on the timestamp it has in the file name. For example I have file like:

File1_20200218.csv, File2_20200201.csv. So I want to move only the files that are 5 days older, in this instance only the File2_20200201.csv should move to another folder. I searched around the web was not able to figure out, appreciate your help.

Regards,

Ziad

Offline

#2 13 Mar 2020 04:09

pappaG
Member
Registered: 04 Jan 2020
Posts: 3

Re: Move file based off of timestamp in filename

it seems what you need to do is set up a variable of five days ago to move the files?
Windows has a difficult time in the CMD shell getting accurate times unless you use powershell.
the best way I have found is with a command line program called doff.exe I'm sure you could search for it.
then you could write a script like...

for /f "tokens=1-3 delims=/ " %%a in ('doff.exe yyyy/mm/dd -5') do (
set yy=%%a
set mm=%%b
set dd=%%c
)
move file1_%yy%%mm%%dd%.csv "d:\temp\another folder\"

now I don't know if this will work for your situation but it's a start?

pappaG

Last edited by pappaG (13 Mar 2020 04:25)

Offline

#3 13 Mar 2020 12:47

Simon Sheppard
Super Administrator
Registered: 27 Aug 2005
Posts: 1,061
Website

Re: Move file based off of timestamp in filename

I just put a mirror of DOFF.exe on the links page here: https://ss64.com/links/windows.html

The original website seems to have gone offline, so I pulled it from Archive.org
I vaguely remember this once having a restrictive licence but since 2006 it has been available under the BSD/open source licence.

Offline

#4 13 Mar 2020 13:32

pappaG
Member
Registered: 04 Jan 2020
Posts: 3

Re: Move file based off of timestamp in filename

Many thanks Simon,
Just after posting this, I went looking for it and found nothing... and considered that I might have to host this somewhere.

thanks again
pappaG

Offline

Board footer

Powered by FluxBB