S
Snoopy Dog
I am obviously missing something.
I am simple trying to rename some files with long names to a shorter
format.
Here are a couple of sample file names: longfilename - 0100.txt,
longfilename - 01-1.txt
Here is my code - rename.rb:
# Quick Script to rename files
puts 'start'
require 'find'
require 'ftools'
require 'enumerator'
dir1original = 'c:/temp/'
puts 'Here'
Find.find(dir1original) do |path|
puts 'The current item is ' + path
if File.file? path
puts path + ' is a file'
oldname = path
newname = path
newname.sub!('longfilename - 0', '0')
puts newname + ' Is the newfile'
puts "\n\nCheck About to RENAME file"
File.rename(oldname, newname)
puts 'Renamed ' + oldname + ' to ' + newname + "\n\n\n"
end
end
puts "\n\n"
When I run it I get the following error (after I get teh Check About to
RENAME file message:
rename.rb:21:in 'rename': No such file or directory - c:/temp/0101.txt
or c:/temp/0101.txt <Errno::ENOENT>
from rename.rb:21
from c:/ruby/lib/ruby/1.8/find.rb:39:in 'find'
from c:/ruby/lib/ruby/1.8/find.rb:38:in 'catch'
from c:/ruby/lib/ruby/1.8/find.rb:38:in 'find'
from rename.rb:12
My script is named rename.rb and is located on c:
This is on a Windows XP box.
Not sure what I have missed, but I figure it has to be something simple.
Help would be greatly appreciated.
Snoopy
I am simple trying to rename some files with long names to a shorter
format.
Here are a couple of sample file names: longfilename - 0100.txt,
longfilename - 01-1.txt
Here is my code - rename.rb:
# Quick Script to rename files
puts 'start'
require 'find'
require 'ftools'
require 'enumerator'
dir1original = 'c:/temp/'
puts 'Here'
Find.find(dir1original) do |path|
puts 'The current item is ' + path
if File.file? path
puts path + ' is a file'
oldname = path
newname = path
newname.sub!('longfilename - 0', '0')
puts newname + ' Is the newfile'
puts "\n\nCheck About to RENAME file"
File.rename(oldname, newname)
puts 'Renamed ' + oldname + ' to ' + newname + "\n\n\n"
end
end
puts "\n\n"
When I run it I get the following error (after I get teh Check About to
RENAME file message:
rename.rb:21:in 'rename': No such file or directory - c:/temp/0101.txt
or c:/temp/0101.txt <Errno::ENOENT>
from rename.rb:21
from c:/ruby/lib/ruby/1.8/find.rb:39:in 'find'
from c:/ruby/lib/ruby/1.8/find.rb:38:in 'catch'
from c:/ruby/lib/ruby/1.8/find.rb:38:in 'find'
from rename.rb:12
My script is named rename.rb and is located on c:
This is on a Windows XP box.
Not sure what I have missed, but I figure it has to be something simple.
Help would be greatly appreciated.
Snoopy