[Help] Delete last file ordered by name

Hi all,

I need to create a process that will list all file names inside a folder and then delete only the last file in this list (ordered by descending name).
I found a snippet online and I think it can be useful.
How can I change the fact that this snippet use the creation time instead of the name sorted by descending?

Thank you in advantage :slight_smile:

1 Like

Hi
kindly have a view on this once buddy, on how to get the last created file in the folder while fetching the files with get files method itself

Cheers @alinghi100

1 Like

Hi @alinghi100,
You could use PowerShell script for this:

$path = "(path to folder)"
ls $path | sort-object -Property {$_.Name} | Select-Object -Last "1" | Remove-Item -force

@alinghi100

Directory.GetFiles(PathOfYourFolder).OrderByDescending(function(x) Path.GetFileName(x)).last

can use this in Delete activity

1 Like

Thank you guys,

it worked like a charm :smiley:

Great
Cheers @alinghi100

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.