 |

July 7th, 2008, 11:15 AM
|
|
Newbie
|
|
Join Date: Oct 2007
Posts: 9
|
|
Deleting all tmp files(session,cookies,cache) in ruby
Hello,
For my ruby on rails application,i need to delete all the temporary files created in /tmp folder.If those files increases, at some point in time, my application stops working unless i delete all session files manually.Is there any way, so that i can keep on deleting those files from the folder automatically or somehow.Please help if anyone knows.Its urgent.
Thanks in advance
|

July 7th, 2008, 01:01 PM
|
 |
Site Moderator
|
|
Join Date: Nov 2006
Location: UK
Posts: 12,596
|
|
If you know the name of the file, just use File.delete("nameoffile.ext") For more information on input/output, see this tutorial.
|

July 8th, 2008, 06:43 AM
|
|
Newbie
|
|
Join Date: Oct 2007
Posts: 9
|
|
Quote:
|
Originally Posted by acoder
If you know the name of the file, just use File.delete("nameoffile.ext") For more information on input/output, see this tutorial.
|
No.I think i was not clear about my question.In tmp/session folder,
ruby_sess.7e406b1b7791bd09
ruby_sess.10645ae490aa2726..
This kind of many files get created.I want clear all the files regularly.I should delete all the files in that folder.How can i do this?Hope i am clear this time.
Thanks
|

July 8th, 2008, 09:44 AM
|
 |
Site Moderator
|
|
Join Date: Nov 2006
Location: UK
Posts: 12,596
|
|
Use the FileUtils module. Loop over the directory. If it's a file, use rm and if it's a directory use rm_f to delete the files/directories (or you could use rm with option force set to true).
Make an attempt at that and see what you can come up with.
|

July 8th, 2008, 04:04 PM
|
|
Expert
|
|
Join Date: May 2007
Posts: 177
|
|
I have no experience with FileUtils, but that may work exactly as you need. My only question about it is, will it delete current sessions? Is that a concern? If so, you could try using Dir to get all files in the tmp directory, then loop over them. Then for each file, you can check its last modified time (using File.stat) to determine if you want to delete it. I've never used this for the tmp directory, but it works for other situations.
|

July 8th, 2008, 07:08 PM
|
 |
Site Moderator
|
|
Join Date: Nov 2006
Location: UK
Posts: 12,596
|
|
Good point. Always a good idea to look at the wider picture.
|

August 2nd, 2008, 08:12 AM
|
|
Newbie
|
|
Join Date: Aug 2008
Posts: 2
|
|
Hello,
Good day ! :)
I am also in a same position as you.I need to delete all my session files from /tmp directory.Did you found any alternative for that.
Please help me in this issue.I would be Great to you if you can help me in resolving this.
Cheers,
Rajesh
|

August 2nd, 2008, 10:51 AM
|
 |
Site Moderator
|
|
Join Date: Nov 2006
Location: UK
Posts: 12,596
|
|
Did you try the suggestions above?
|

August 5th, 2008, 08:34 AM
|
|
Newbie
|
|
Join Date: Aug 2008
Posts: 2
|
|
Yes I tried a bit But No idea at all.
|

August 5th, 2008, 10:21 AM
|
 |
Site Moderator
|
|
Join Date: Nov 2006
Location: UK
Posts: 12,596
|
|
What did you try? Both suggestions should work. Is it the looping part that's causing you problems. Show your code.
|
 |
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
What is Bytes?
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over network members.
|