472,146 Members | 1,444 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,146 software developers and data experts.

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
Jul 7 '08 #1
9 9675
acoder
16,027 Expert Mod 8TB
If you know the name of the file, just use File.delete("nameoffile.ext") For more information on input/output, see this tutorial.
Jul 7 '08 #2
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
Jul 8 '08 #3
acoder
16,027 Expert Mod 8TB
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.
Jul 8 '08 #4
improvcornartist
303 Expert 100+
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.
Jul 8 '08 #5
acoder
16,027 Expert Mod 8TB
Good point. Always a good idea to look at the wider picture.
Jul 8 '08 #6
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
Aug 2 '08 #7
acoder
16,027 Expert Mod 8TB
Did you try the suggestions above?
Aug 2 '08 #8
Yes I tried a bit But No idea at all.
Aug 5 '08 #9
acoder
16,027 Expert Mod 8TB
What did you try? Both suggestions should work. Is it the looping part that's causing you problems. Show your code.
Aug 5 '08 #10

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Theo | last post: by
6 posts views Thread by Nicolae Fieraru | last post: by
11 posts views Thread by Jennifer | last post: by
5 posts views Thread by anony | last post: by
5 posts views Thread by CodeRazor | last post: by
3 posts views Thread by Jim Carlock | last post: by
2 posts views Thread by StanB | last post: by
reply views Thread by Saiars | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.