Finding a file with yesterdays date in the name and reporting size of it

Hello,

I’m trying to get the size of a file with a specific name that changes every day.

For example today the file is name RCData.RC1_000017_20170118_20170119403003.txt, tomorrow it will be RCData.RC1_000017_20170119_20170120403003.txt

The first date in the string is the previous day, the second date is the day it was gathered.

So I want something like this:

size of files whose (name of it contains "RCData.RC1_" & first 6 of computer name & "YYYYMMDD" & ".txt") of date (now - 1 day) of folder "C:\temp\backup"

The goal is to look for a file with that specific name because there are over a thousand files here and if i report the size of the last modified file it will take a couple minuets.

I tried something like this to get it going ( it’s not working :frowning: )

size of files whose (name of it as lowercase contains (("RCData.RC1_" & first 6 of computer name & "_" & year of it as string & month of it as two digits & day_of_month of it as two digits & ".txt") of date (time zone "pdt") of (now - 1 * day)) of folder "C:\temp\backup"

Can you give us some more information so we can try and help you ?
Things like:

  • what part is not working
  • are you getting an error
  • what results do you get

I ended up figuring it out with a co worker.

It looks like this.

size of file whose (name of it starts with (("RCData.RC1_" & first 6 of computer name & "_" & concatenation of (year of it as string; month of it as two digits; day_of_month of it as two digits) & "_") of date (time zone "pdt") of (now - 1 * day))) of folder "C:\Windows\Options\Applications\HME\backup"

There are a few options for getting YYYYMMDD in relevance here: https://www.google.com/search?q=YYYYMMDD+site%3Abigfix.me

You might consider getting the size for a few of the files… like for tomorrow, today, yesterday, and the day before, so that you have a window of files to get the results from, the reason is that at midnight, all of a sudden the results that should be returned will change. Obviously not all of those files will exist at all times, but you should get all of the files that do exist that match that criteria with the size and filename or size and mod time.


This is probably slower to evaluate, but this should give you the newest file, whatever it may be:

items 1 of (it, files whose (name of it starts with ("RCData.RC1_" & first 6 of computer name & "_")) of folders "C:\Windows\Options\Applications\HME\backup" ) whose(item 0 of it = modification time of item 1 of it) of maximum of modification times of files whose (name of it starts with ("RCData.RC1_" & first 6 of computer name & "_") ) of folders "C:\Windows\Options\Applications\HME\backup"

This works by getting the newest modification time, then getting the file that has that mod time. It uses a tuple construction so that the maximum mod time is only calculated once. You could nest the maximum mod time calc within the first whose statement, but it would be massively slower.