Page 1 of 1

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

Posted: Wed Aug 12, 2020 9:19 am
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

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

Posted: Wed Aug 12, 2020 10:21 am
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?

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

Posted: Wed Aug 12, 2020 10:30 am
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
}

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

Posted: Wed Aug 12, 2020 10:35 am
by jan_suhr
Hi Magnus,

You can use the Inject tool to pickup files and send them to Trash.

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

Posted: Wed Aug 12, 2020 12:19 pm
by magnussandstrom
Ok, so I need to use script's or external tools to do this simple/common task in Switch??

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

Posted: Wed Aug 12, 2020 2:58 pm
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 16944 times

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

Posted: Thu Aug 13, 2020 9:01 am
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.

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

Posted: Thu Aug 13, 2020 9:28 am
by jan_suhr
A shared network volume would normally only have work files on it, no system files should be on a network volume.

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

Posted: Thu Aug 13, 2020 11:03 am
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 :)

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

Posted: Thu Aug 13, 2020 2:50 pm
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!

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

Posted: Thu Aug 27, 2020 4:00 pm
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!

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

Posted: Fri Aug 28, 2020 9:00 am
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".

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

Posted: Sat Nov 28, 2020 4:35 pm
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: