Best way to delete files in a folder older then X?

Post Reply
User avatar
magnussandstrom
Advanced member
Posts: 345
Joined: Thu Jul 30, 2020 6:34 pm
Location: Sweden
Contact:

Best way to delete files in a folder older then X?

Post by magnussandstrom »

As today we are using Filetrain (from Laidback) for this task but I want to migrate my Filetrain Stations to Switch Flows, but can't find an easy way to do this 'simple task'.

We got several folders on our servers where I (once a day) need to delete files or folders older then 2 days or 31 days or 2 hours.. yeah you get the idea.

Whats the best practice to do this in Switch? Some folders contains 10000+ files so I don't want Switch to make a job out of every file or something strange like that. Just a clean, fast and simple clean up.

Any suggestions?

Best regards,
Magnus
User avatar
magnussandstrom
Advanced member
Posts: 345
Joined: Thu Jul 30, 2020 6:34 pm
Location: Sweden
Contact:

Re: Best way to delete files in a folder older then X?

Post by magnussandstrom »

I've found the Folder Apps with the 'File pool cleanup', but it doesn't work with network folders due to:

'The root folder must be a local folder, network folders are not allowed! Also selecting the root folder of a local drive is not allowed. These are measures to avoid that files are being removed from important locations'

Is there a way around this network path restriction?
sander
Advanced member
Posts: 274
Joined: Wed Oct 01, 2014 8:58 am
Location: The Netherlands

Re: Best way to delete files in a folder older then X?

Post by sander »

You might be interested in my approach with Powershell which supports UNC paths. Fire up via execute command:

Code: Select all

$paths = @(
("d:\sftp\sander\nl"),
("d:\sftp\sander\de")
)

foreach ($path in $paths) {
$limit = (Get-Date).AddDays(-7)

Get-ChildItem $path -Recurse | ? {
    -not $_.PSIsContainer -and $_.CreationTime -lt $limit
} | Remove-Item
}
jan_suhr
Advanced member
Posts: 586
Joined: Fri Nov 04, 2011 1:12 pm
Location: Nyköping, Sweden

Re: Best way to delete files in a folder older then X?

Post by jan_suhr »

Hi Magnus,

You can use the Inject tool to pickup files and send them to Trash.
Jan Suhr
Color Consult AB
Sweden
=============
Check out my apps
User avatar
magnussandstrom
Advanced member
Posts: 345
Joined: Thu Jul 30, 2020 6:34 pm
Location: Sweden
Contact:

Re: Best way to delete files in a folder older then X?

Post by magnussandstrom »

Ok, so I need to use script's or external tools to do this simple/common task in Switch??
Zoranj
Member
Posts: 107
Joined: Tue Sep 20, 2016 7:37 pm
Location: Canada

Re: Best way to delete files in a folder older then X?

Post by Zoranj »

Yes, Switch can do many complex tasks but for some reason some simple tasks are not present.
Sometimes you have to get creative to accomplish simple things.
e.g. delete files older than ... in some folder.

Another one that boggles my mind is working with txt files is not existent.
For example if you have bunch of files in folder, you want to create txt file with list of files, you have to figure out some creative way of doing it or use third party app.
Also working with command line is sometimes difficult too.

Anyways, back to topic, my creative way of deleting old files is by using free and open source app called "Deletefiles".
https://github.com/RickStrahl/DeleteFiles
You call it from Switch and pass parameters, it works with both local and network paths.
I also had to use third party app "Dummy Job Clock" for another simple task, timer.
See screenshot of simple flow and it's configuration I use. It has been solid for years.
Basically timer fires up dummy file (once a day, once a week, etc...) and it executes Deletefile with parameters.

I hope this helps.
Screen Shot 2020-08-12 at 8.54.56 AM.png
Screen Shot 2020-08-12 at 8.54.56 AM.png (32.04 KiB) Viewed 16717 times
freddyp
Advanced member
Posts: 1008
Joined: Thu Feb 09, 2012 3:53 pm

Re: Best way to delete files in a folder older then X?

Post by freddyp »

I have deliberately chosen to block the "File Pool Cleanup" app (which is part of the Folder Apps bundle) from cleaning up file pools on network drives and on root folders. You have to consider that there is no method for a script or app to communicate with the user once the flow is started. Without this safety net, if you inadvertently selected C: as your file pool root folder and you started the flow, you can probably imagine what would happen. And I did not want to run the risk of having to go into a debate on whose fault it was: the user's for having chosen the wrong root folder, or the app's for not having warned the user he was going to destroy his system.

If there is a consensus that it is the user's responsibility and not Enfocus's when such a mistake is made, I am quite willing to create a new version where this limitation is removed. I think I will add an extra property "Allow root folders" (default: No) nevertheless. When this property is set to Yes and you delete all the files of your most important customer and it takes you a whole day to get everything back from a backup (you do keep backups don't you?), then you will be referred to this post.

I would like to hear from you.
jan_suhr
Advanced member
Posts: 586
Joined: Fri Nov 04, 2011 1:12 pm
Location: Nyköping, Sweden

Re: Best way to delete files in a folder older then X?

Post by jan_suhr »

A shared network volume would normally only have work files on it, no system files should be on a network volume.
Jan Suhr
Color Consult AB
Sweden
=============
Check out my apps
Padawan
Advanced member
Posts: 358
Joined: Mon Jun 12, 2017 8:48 pm
Location: Belgium
Contact:

Re: Best way to delete files in a folder older then X?

Post by Padawan »

jan_suhr wrote: Thu Aug 13, 2020 9:28 am A shared network volume would normally only have work files on it, no system files should be on a network volume.
Just my two cents: I've seen people share the entire C drive

System files should not be on a network volume, but that doesn't mean that they can't be :)
User avatar
magnussandstrom
Advanced member
Posts: 345
Joined: Thu Jul 30, 2020 6:34 pm
Location: Sweden
Contact:

Re: Best way to delete files in a folder older then X?

Post by magnussandstrom »

freddyp wrote: Thu Aug 13, 2020 9:01 am If there is a consensus that it is the user's responsibility and not Enfocus's when such a mistake is made, I am quite willing to create a new version where this limitation is removed. I think I will add an extra property "Allow root folders" (default: No) nevertheless. When this property is set to Yes and you delete all the files of your most important customer and it takes you a whole day to get everything back from a backup (you do keep backups don't you?), then you will be referred to this post.

I would like to hear from you.
In my experience with various software vendors it's always the customers responsibility what they choose to do with the system. An updated app with the option to turn off the said restriction would be very appreciated Freddy!
User avatar
magnussandstrom
Advanced member
Posts: 345
Joined: Thu Jul 30, 2020 6:34 pm
Location: Sweden
Contact:

Re: Best way to delete files in a folder older then X?

Post by magnussandstrom »

Ping: Freddy - Is it possible to create an updated version of the 'File pool cleanup app' without server-path restrictions? I would very much appreciate that!
freddyp
Advanced member
Posts: 1008
Joined: Thu Feb 09, 2012 3:53 pm

Re: Best way to delete files in a folder older then X?

Post by freddyp »

There are a couple of other outstanding wishes for apps in the "Folder Apps" bundle and Laurent and I would like to tackle them all at the same time. We would also like to take the opportunity to convert all the apps to Node.js. The downside of this message is that it will take a bit longer. We will post a message here when there is a new version of "Folder Apps".
User avatar
magnussandstrom
Advanced member
Posts: 345
Joined: Thu Jul 30, 2020 6:34 pm
Location: Sweden
Contact:

Re: Best way to delete files in a folder older then X?

Post by magnussandstrom »

@Freddy - Maybe you can add a time selection/filter (hour/day/week/weekday/month/year) to the new node.js version of Folder apps? As discussed here: viewtopic.php?f=12&t=3913. It would be a very useful feature when making 'clean up' flows etc. :idea:
Post Reply