Trouble with FileUtils.rm() -- Invalid arguement error

I have been screwing with this for the last hour, and I still cant get
it (so frustrating when you get stuck on matters that seem trivial).

I am trying to delete all the contents from the temporary internet files
in vista, and I keep getting an invalid argeument error.

cache_dir = ENV['USERPROFILE'] +
"\\AppData\\Local\\Microsoft\\Windows\\Temporary Internet Files\\*.*"

FileUtils.rm(cache_dir)

I have tried several different variations, of backtick, single quotes,
double quotes, etc, etc....even tried deleting a single file, and it
always gives me the same error. Also tried rm_r, rm_rf...still no luck.

could someone explain to me what I am doing wrong? thanks!

···

--
Posted via http://www.ruby-forum.com/.

What's the error?!?!?1111oneoneeleveneleven

···

On Feb 7, 2008, at 9:38 PM, an an wrote:

<snip>

Ari
--------------------------------------------|
If you're not living on the edge,
then you're just wasting space.

an an wrote:

I have been screwing with this for the last hour, and I still cant get
it (so frustrating when you get stuck on matters that seem trivial).

I am trying to delete all the contents from the temporary internet files
in vista, and I keep getting an invalid argeument error.

cache_dir = ENV['USERPROFILE'] +
"\\AppData\\Local\\Microsoft\\Windows\\Temporary Internet Files\\*.*"

FileUtils.rm(cache_dir)

I have tried several different variations, of backtick, single quotes,
double quotes, etc, etc....even tried deleting a single file, and it
always gives me the same error. Also tried rm_r, rm_rf...still no luck.

could someone explain to me what I am doing wrong? thanks!

It looks like you're trying to remove all the files in the directory at once. Bear in mind that FileUtils.rm wants a _list_ of filenames, not a pattern to match. You can specify a list of filenames by accumulating them in an array and then using the splat operator:

filenames = whatever it takes to get all the filename in an array
FileUtils.rm(*filenames)

···

--
RMagick: http://rmagick.rubyforge.org/
RMagick 2: http://rmagick.rubyforge.org/rmagick2.html

Tim Hunter wrote:

an an wrote:

I have tried several different variations, of backtick, single quotes,
double quotes, etc, etc....even tried deleting a single file, and it
always gives me the same error. Also tried rm_r, rm_rf...still no luck.

could someone explain to me what I am doing wrong? thanks!

It looks like you're trying to remove all the files in the directory at
once. Bear in mind that FileUtils.rm wants a _list_ of filenames, not a
pattern to match. You can specify a list of filenames by accumulating
them in an array and then using the splat operator:

filenames = whatever it takes to get all the filename in an array
FileUtils.rm(*filenames)

that makes much more sense. what threw me off was the * in the following
line in the rdoc

FileUtils.rm Dir.glob('*.so')

Did some reading up on Dir.glob and it makes much more sense now.
Thanks!

···

--
Posted via http://www.ruby-forum.com/\.

Tim Hunter wrote:

an an wrote:

I have tried several different variations, of backtick, single quotes,
double quotes, etc, etc....even tried deleting a single file, and it
always gives me the same error. Also tried rm_r, rm_rf...still no luck.

could someone explain to me what I am doing wrong? thanks!

It looks like you're trying to remove all the files in the directory at
once. Bear in mind that FileUtils.rm wants a _list_ of filenames, not a
pattern to match. You can specify a list of filenames by accumulating
them in an array and then using the splat operator:

filenames = whatever it takes to get all the filename in an array
FileUtils.rm(*filenames)

So I am stuck again on this...I have the following code:

dir = Dir.open("c:\\myDir\\delete\\")
FileUtils.rm(dir.entries.reject{|e| /\.{1,2}$/ =~ e})

the problem is, that the dir.entries only returns the filename of each
entry...is there anyway to have them expanded?

···

--
Posted via http://www.ruby-forum.com/\.

an an wrote:

Tim Hunter wrote:
  

an an wrote:
    

I have tried several different variations, of backtick, single quotes,
double quotes, etc, etc....even tried deleting a single file, and it
always gives me the same error. Also tried rm_r, rm_rf...still no luck.

could someone explain to me what I am doing wrong? thanks!
      

It looks like you're trying to remove all the files in the directory at
once. Bear in mind that FileUtils.rm wants a _list_ of filenames, not a
pattern to match. You can specify a list of filenames by accumulating
them in an array and then using the splat operator:

filenames = whatever it takes to get all the filename in an array
FileUtils.rm(*filenames)
    
So I am stuck again on this...I have the following code:

dir = Dir.open("c:\\myDir\\delete\\")
FileUtils.rm(dir.entries.reject{|e| /\.{1,2}$/ =~ e})

the problem is, that the dir.entries only returns the filename of each entry...is there anyway to have them expanded

Use Dir.glob instead:

FileUtils.rm Dir.glob("c:\\myDir\\delete\\")

-Justin

Justin Collins wrote:

an an wrote:

It looks like you're trying to remove all the files in the directory at

dir = Dir.open("c:\\myDir\\delete\\")
FileUtils.rm(dir.entries.reject{|e| /\.{1,2}$/ =~ e})

the problem is, that the dir.entries only returns the filename of each
entry...is there anyway to have them expanded

Use Dir.glob instead:

FileUtils.rm Dir.glob("c:\\myDir\\delete\\")

-Justin

still doesn't work for some reason. in irb if I do

Dir.glob("C:\")
puts Dir.glob("C:\")

neither of which print anything

···

--
Posted via http://www.ruby-forum.com/\.

an an wrote:

Justin Collins wrote:
  

an an wrote:
    

It looks like you're trying to remove all the files in the directory at
        

dir = Dir.open("c:\\myDir\\delete\\")
FileUtils.rm(dir.entries.reject{|e| /\.{1,2}$/ =~ e})

the problem is, that the dir.entries only returns the filename of each entry...is there anyway to have them expanded
      

Use Dir.glob instead:

FileUtils.rm Dir.glob("c:\\myDir\\delete\\")

-Justin
    
still doesn't work for some reason. in irb if I do

Dir.glob("C:\")
puts Dir.glob("C:\")

neither of which print anything

I forgot the asterisk:

FileUtils.rm Dir.glob("c:\\myDir\\delete\\*")

-Justin

Justin Collins wrote:

an an wrote:

entry...is there anyway to have them expanded

Dir.glob("C:\")
puts Dir.glob("C:\")

neither of which print anything

I forgot the asterisk:

FileUtils.rm Dir.glob("c:\\myDir\\delete\\*")

-Justin

still no luck...here is exactly what I have typed into irb:

irb(main):003:1' Dir.glob('c:\')
irb(main):004:1' Dir.glob('c:\drivers\')
irb(main):005:1' Dir.glob("c:\drivers\")
irb(main):006:1' Dir.glob("c:\drivers\*")
irb(main):007:1' puts Dir.glob("c:\drivers\*")
irb(main):008:1' puts Dir.glob("c:\\drivers\\*")
irb(main):009:1' Dir.glob("c:\\drivers\\*")
irb(main):010:1' Dir.glob('c:\\drivers\\*')
irb(main):011:1' Dir.glob("c:\\*")
irb(main):012:1' print Dir.glob("C:\\*")

none of these commands returned anything....any idea why?

···

--
Posted via http://www.ruby-forum.com/\.

i think nobu advised us on using (forward)slash instead of backslash
since the latter was a special/metacharacter, so,

irb(main):008:0> Dir.glob('c:/*')
=> ["c:/#!mail!#2060tDO#", "c:/2.pst", "c:/abap", "c:/abap.pst", "c:/adaptec", "
c:/admin", "c:/adsm.pst", "c:/ae", "c:/aeditor-2.0.log", "c:/and", "c:/AntigenIn
stall.log", "c:/archive.pst", "c:/archive2.pst", "c:/asoutput.log", "c:/Autostar
", "c:/avgun.log", "c:/backup", "c:/backup2.pst", "c:/bind.pst", "c:/bind2.pst",
<--snipped-->

btw, before running the above in irb, pls press ctrl-c+enter or
restart your irb first. your irb prompt is hinting a continuation on a
quote :wink:

kind regards -botp

···

On Feb 9, 2008 10:08 AM, an an <dtown22@gmail.com> wrote:

still no luck...here is exactly what I have typed into irb:
irb(main):011:1' Dir.glob("c:\\*")
irb(main):012:1' print Dir.glob("C:\\*")
none of these commands returned anything....any idea why?

an an wrote:

Justin Collins wrote:
  

an an wrote:
    

entry...is there anyway to have them expanded
          

Dir.glob("C:\")
puts Dir.glob("C:\")

neither of which print anything

I forgot the asterisk:

FileUtils.rm Dir.glob("c:\\myDir\\delete\\*")

-Justin
    
still no luck...here is exactly what I have typed into irb:

irb(main):003:1' Dir.glob('c:\')
irb(main):004:1' Dir.glob('c:\drivers\')
irb(main):005:1' Dir.glob("c:\drivers\")
irb(main):006:1' Dir.glob("c:\drivers\*")
irb(main):007:1' puts Dir.glob("c:\drivers\*")
irb(main):008:1' puts Dir.glob("c:\\drivers\\*")
irb(main):009:1' Dir.glob("c:\\drivers\\*")
irb(main):010:1' Dir.glob('c:\\drivers\\*')
irb(main):011:1' Dir.glob("c:\\*")
irb(main):012:1' print Dir.glob("C:\\*")

none of these commands returned anything....any idea why?
  
Well...it _might_ be a Windows thing, but what did you type in before those lines? You seem to be within a quote.

Notice your prompt:

irb(main):003:1'
               ^

             Should be a > (greater than sign)

For instance:

irb(main):001:0> ' <- I just started a string
irb(main):002:0' <- Now the prompt is different
irb(main):003:0' Until I close the string, it will remain that way
irb(main):004:0' here I close it -> '
=> " <- I just started a string\n<- Now the prompt is different\nUntil I close the string, it will remain that way\nhere I close it -> "
irb(main):005:0> puts "Now we're back to normal"
Now we're back to normal
=> nil

-Justin

Justin & botp,

thanks for your help. I didn't notice that problem with irb, but using
the '/' slash ended up working...thanks for all your help!

···

--
Posted via http://www.ruby-forum.com/.