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!
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)
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?
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!
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
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
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
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,