Hi
I have just purchased ScriptFTP so this is all new to me
What I would like to do is this
On my FTP Server I have the following file structure - I have a top level folder for the year then subfolders for the month and day so for example files for the 30 March would be in \2018\03\30
What I need is a script to delete any files, subfolders etc that are older than two days i.e any folders such as \2018\ 03\ 21 \2018\ 03\ 20 and so on.
Also come 2019 I would want to delete the 2018 folder too
I am not interested in keeping the files so just want them deleted . I aim to run this script once a day via the Task Scheduler. Is there some kind person who could help with this
Many thanks
Graham
I have just purchased ScriptFTP so this is all new to me
What I would like to do is this
On my FTP Server I have the following file structure - I have a top level folder for the year then subfolders for the month and day so for example files for the 30 March would be in \2018\03\30
What I need is a script to delete any files, subfolders etc that are older than two days i.e any folders such as \2018\ 03\ 21 \2018\ 03\ 20 and so on.
Also come 2019 I would want to delete the 2018 folder too
I am not interested in keeping the files so just want them deleted . I aim to run this script once a day via the Task Scheduler. Is there some kind person who could help with this
Many thanks
Graham
Hi Graham,
Here you have a script that does what you describe. It is a but complex to understand as it contains 3 "FOR EACH" loops one inside the other.
Note that it only deletes the "day" directory, or let's say, the "leaf" of the directory tree. It does not delete the month or the year directories, just in case. It can be modified to do so however.
Below you can also find some screenshots to explain everything.
Here you have a script that does what you describe. It is a but complex to understand as it contains 3 "FOR EACH" loops one inside the other.
Note that it only deletes the "day" directory, or let's say, the "leaf" of the directory tree. It does not delete the month or the year directories, just in case. It can be modified to do so however.
Below you can also find some screenshots to explain everything.
FTP Script
- # Connect to the FTP server, enter your own settings here
- # Get the list of folders in the FTP root directory
- # they must be plain year numbers
- # For each year
- # Open this year fodler
- # Retrieve the list of months
- # For each month
- # Open the month folder
- # Get the list of days
- # For each day
- # Show a line in the ScriptFTP screen. Just to show where we are
- # We build a text string with the current day in the format
- # ScriptFTP understands
- $folder_date_time=$year."_".$month."_".$day."-12_00_00"
- # How old is the current folder?
- # Well, we have the result in seconds, show it
- # Is the folder more than 2 days old (172800 seconds)
- # Delete the day folder and all the files and subdirs that go inside
- # return to parent folder
- # return to parent folder
- # We are done! Let's be polite, close the connection before finishing
Attachments
with_silent_output.png (16.96KiB)Viewed 3897 times
with_normal_output.png (38.07KiB)Viewed 3897 times
before_running.png (2.27KiB)Viewed 3897 times
after_running.png (2.19KiB)Viewed 3897 times
liked Script FTP? Try our other product Email Parser
Hi
That is brilliant - thanks so much
I would like it to delete the month once we are into a new month plus two days and then the year at year end plus two days
What would I need to change for it to do this
Kind Regards
Graham
That is brilliant - thanks so much
I would like it to delete the month once we are into a new month plus two days and then the year at year end plus two days
What would I need to change for it to do this
Kind Regards
Graham