Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Delete any file beginning with some character

Reply
Thread Tools

Delete any file beginning with some character

 
 
Sarika Patil
Guest
Posts: n/a
 
      03-17-2009
Hi,

I am trying to delete files in a folder whichever beginning with any
string
but not able to do it?
Command used in rb file is

File.delete("A*.jpg")
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Andrew Timberlake
Guest
Posts: n/a
 
      03-17-2009
On Tue, Mar 17, 2009 at 2:38 PM, Sarika Patil
<> wrote:
> Hi,
>
> I am trying to delete files in a folder whichever beginning with any
> string
> but not able to do it?
> Command used in rb file is
>
> File.delete("A*.jpg")
> --
> Posted via http://www.ruby-forum.com/.
>
>


Try:
Dir.glob('A*.jpg').each { |file| File.delete(file) }

Andrew Timberlake
http://ramblingsonrails.com
http://www.linkedin.com/in/andrewtimberlake

"I have never let my schooling interfere with my education" - Mark Twain

 
Reply With Quote
 
 
 
 
Heesob Park
Guest
Posts: n/a
 
      03-17-2009
Hi,

2009/3/17 Sarika Patil <>:
> Hi,
>
> I am trying to delete files in a folder whichever beginning with any
> string
> but not able to do it?
> Command used in rb file is
>
> File.delete("A*.jpg")

require 'fileutils'
FileUtils.rm Dir.glob('A*.jpg')

Regards,

Park Heesob

 
Reply With Quote
 
 
 
Reply

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 On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Regex: Any character in character class Sebastian Java 17 02-04-2013 10:26 PM
FAQ 5.2 How do I change, delete, or insert a line in a file, or append to the beginning of a file? PerlFAQ Server Perl Misc 0 02-24-2011 11:00 PM
index of string from beginning of line vs beginning of file Jesse B. Ruby 9 03-27-2010 04:04 PM
How to append some data at the beginning of a file Uday Thokala Ruby 8 08-27-2007 01:58 AM
501 PIX "deny any any" "allow any any" Any Anybody? Networking Student Cisco 4 11-16-2006 10:40 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57