How do you delete a script?

Perl Script To Delete Dynamically Created Files?

  • I need a Perl script to help clean up dynamically created files. The files are in the format ABC###.gif Where ### is some randomly created alphanumeric character. The part I'm having trouble is some of these files will be in use by web users. How will I know this, or how can I make sure I'm not deleting an in use file?

  • Answer:

    What do you mean that you are concerned that it will be in use by users? If just viewed on a page, the image won't disappear from the users page if you delete it. If the user is actually doing something to the actual file, then change the script that allows the user to manipulate the file. Create a temp file for the user to manipulate then write the completed file to your directory that you want to delete from, then if you happen to delete a file that is being worked on, it doesn't matter. For the deletion: my @filesToDelete = glob("/whateverdir/ABC*.gif"); foreach (@filesToDelete){ unlink $_; }

Trish J at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

I'm inclined to think that you will not no if it is in use unless that web user has an open file handle on the file, in that case the file would not be able to be deleted. Given the nature of the web I'm betting that there is no open file handle. This would mean that unless there is a mechanism by which the web site/application keeps track of the the in use files there is not a practical way for you to know if it is being used. You might be able to use the atime of the file to help deduce whether or not the file was used today. Basically the answer to your question is that there either needs to be a rule that determines the retention period of these files or the web site will need to assist you in knowing what files are still being referenced.

yanick

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.