Stefano Crocco
5/16/2007 3:02:00 PM
Alle mercoledì 16 maggio 2007, Peter Bailey ha scritto:
> I need to send some graphics file over to UNIX land, but, without an
> extension. So, I rename the files and try to send them, and, Ruby
> complains that the file isn't there. Why is it that a file rename
> doesn't continue to be legitimate with the original variable name? When
> it's time to "put" the file, Ruby says that the file doesn't exist, I
> guess because it still think that the variable is pointing to the file
> with the extension. What's the point of File.rename if the files can't
> stick with the variable names?
>
> Thanks a lot,
> Peter
>
>
> require 'net/ftp'
> ...
>
> Dir.glob("*.100").each do |arborfile|
> File.rename(arborfile, File.basename(arborfile, ".100"))
> ftp.putbinaryfile(arborfile.downcase)
> ...
arborfire is simply a string, it's not related with a file at all. File.rename
changes the name of the file on the filesystem. When you use
ftp.putbinaryfile, you pass it the old filename, which doesn't refer to a
file anymore, since you renamed it. What you want is this:
Dir.glob("*.100").each do |arborfile|
new_name = File.basename(arborfile, ".100")
File.rename arborfile, new_name
ftp.putbinaryfile(new_name.downcase)
...
I hope this helps
Stefano