•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Ruby section within the Web Development category of DaniWeb, a massive community of 423,013 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,009 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Ruby advertiser: SELL YOUR PRODUCT TODAY !
Views: 2695 | Replies: 1
![]() |
I'm trying to write a script that removes temporary files (ie. files with a tilde at the end: temp.txt~)
but that literally looks for files named *~.
I tried something like this:
but that gives me this:
How should I correctly search and remove these files?
#!/usr/bin/ruby
system("rm *~") if File::exists?( "*~" );but that literally looks for files named *~.
I tried something like this:
#!/usr/bin/ruby if File::exists?( /\w*~/ ) puts "Temp exists\n"; else puts "Temp doesn't exist\n"; end
but that gives me this:
•
•
•
•
in `exists?': can't convert Regexp into String (TypeError)
How should I correctly search and remove these files?
.: davidianstyle :.
•
•
Join Date: May 2006
Location: Ontario, Canada
Posts: 18
Reputation:
Rep Power: 3
Solved Threads: 2
I can't say that this is "correct', but this is the way I'd approach the problem. 

ruby Syntax (Toggle Plain Text)
#!/usr/bin/ruby def yes_no(question) print question if gets.chomp =~ /^[yY]/ return true else return false end end delete_list = [] Dir.new(".").each do |file| if file =~ /\w+\~/ delete_list << file end end puts delete_list.join("\n") puts '---------------' if yes_no("delete the previous files? <y/n>: ") delete_list.each { |file| File.delete(file) } end
--Jessehk
![]() |
•
•
•
•
•
•
•
•
DaniWeb Ruby Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- pattern searching and comparing (Shell Scripting)
- Data Models and Pattern Matching (Java)
- Question about string pattern matching (Java)
- Create a perl script for string matching (ASP)
- Shell Scripting problem and related awk issues (Shell Scripting)
Other Threads in the Ruby Forum
- Previous Thread: syncml
- Next Thread: Paypal IPN


Linear Mode