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

A

an an

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!
 
F

fedzor

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




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

Tim Hunter

an said:
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)
 
A

an an

Tim said:
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!
 
A

an an

Tim said:
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?
 
J

Justin Collins

an said:
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
 
A

an an

Justin said:
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
 
J

Justin Collins

an said:
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
 
A

an an

Justin said:
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?
 
B

botp

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?

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 ;-)

kind regards -botp
 
J

Justin Collins

an said:
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
 
A

an an

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top