I have been tasked with finding a way to create copies of all new files in specific folders that have had changes occur in the last month. I was able to find some code that allows you to pull the most recent files from a directory, but is there any way to pull all files that have been edited since a month ago for example?
I have not used this custom component myself but you might want to look into this one.
Supposedly it pulls all the meta data from files and returns them in a dictionary. I would assume that this would pull the “date modified” meta tag if using it on a file.
Your first problem is determining what the business/requestor means when they say “1 month”. Does that mean 30 days? 28 days? Same day of month in the previous month? If the last option, what if the previous months has less days than the current month (e.g. if it’s the 31st, how do you handle months with only 30 days). For my example below I’ll assume previous 30 days.
You’ll have to do it one folder at a time (unless it’s all subdirectories and you’re ok searching all subdirectories). This can be done by passing it into an array and doing a for each folder in array of folders:
This uses the directory.getfiles() method which will return an ienumerable of strings that are the full file paths of all files in YourDirectory that was modified in the last 30 days. NOTE: I haven’t tested so there might be some syntax error, but you get the idea.
Thank you Dave, this worked perfectly for me. I should be able to handle the backups, the portion that was throwing me the most off was the previous X amount of days. I tested this and it worked exactly as I hoped