Hello,
I'm going a bit nuts with a script of mine that doesn't seem to behave
with file renaming. I've got 172 files in a directory, all with the
extension ".pstxt."

1. Dir.glob("*.pstxt").each do |pstxtfile|
2.   $ps2kfile = File.basename(pstxtfile, ".pstxt")
3.   $filetime =  File.stat(pstxtfile).mtime
4.   #$filetime = $filetime.to_s.gsub!(/ -0500.*$/, "")
5.   #$totalpages = IO::readlines(pstxtfile).to_s
6.   #$totalpages = $totalpages.to_s.chomp!

...

20. File.rename(pstxtfile, pstxtfile.to_s.gsub(/(^.*)\.pdf\.pstxt/,
"ps2k_#{$1}.pstxt"))

...

The above works fine and renames all 172 files in the directory at
present. But, if I uncomment line number 4 and/or 5 and/or 6, it runs
and gives me the following one entry remaining in my directory:

ps2k_.pstxt

All the 172 files are gone! This doesn't make sense to me. The
"filetime" variables are to be used in something completely different
and I don't see why they're affecting this simple renaming of files.

Thanks,
Peter

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