Help | Site Map
Connecting Tech Pros Worldwide
Reply
 
LinkBack Thread Tools
  #1  
Old July 7th, 2008, 11:15 AM
Newbie
 
Join Date: Oct 2007
Posts: 9
Default 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
Reply
  #2  
Old July 7th, 2008, 01:01 PM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 12,596
Default

If you know the name of the file, just use File.delete("nameoffile.ext") For more information on input/output, see this tutorial.
Reply
  #3  
Old July 8th, 2008, 06:43 AM
Newbie
 
Join Date: Oct 2007
Posts: 9
Default

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
Reply
  #4  
Old July 8th, 2008, 09:44 AM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 12,596
Default

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.
Reply
  #5  
Old July 8th, 2008, 04:04 PM
Expert
 
Join Date: May 2007
Posts: 177
Default

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.
Reply
  #6  
Old July 8th, 2008, 07:08 PM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 12,596
Default

Good point. Always a good idea to look at the wider picture.
Reply
  #7  
Old August 2nd, 2008, 08:12 AM
Newbie
 
Join Date: Aug 2008
Posts: 2
Default

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
Reply
  #8  
Old August 2nd, 2008, 10:51 AM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 12,596
Default

Did you try the suggestions above?
Reply
  #9  
Old August 5th, 2008, 08:34 AM
Newbie
 
Join Date: Aug 2008
Posts: 2
Default

Yes I tried a bit But No idea at all.
Reply
  #10  
Old August 5th, 2008, 10:21 AM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 12,596
Default

What did you try? Both suggestions should work. Is it the looping part that's causing you problems. Show your code.
Reply
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

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.
Post your question now . . .
It's fast and it's free

Popular Articles