Hi I wrote the below code to rename the file names. The logic is during
renaming file new name should be preceded with the Directory name into
which the file resides.
C:/Documents and Settings/rakshiar/My Documents/userdata/Downloaded
Files/H76191
/Intergrity letter[1][1].pdf
C:/Documents and Settings/rakshiar/My Documents/userdata/Downloaded
Files/H76191
/H76191Intergrity letter[1][1].pdf
C:/Documents and Settings/rakshiar/My Documents/userdata/Downloaded
Files/H76191
/Intergrity letter[1][1].pdf.part
C:/Documents and Settings/rakshiar/My Documents/userdata/Downloaded
Files/H76191
/H76191Intergrity letter[1][1].pdf.part
Error occurs when the execution came into that part
H76954
C:/Documents and Settings/rakshiar/My Documents/userdata/Downloaded
Files/H76954
/Specjalistyczny Gabinet Kardiologiczny Dr hab. med. Ewa
Straburzy?ska-Migaj.pdf
C:/Documents and Settings/rakshiar/My Documents/userdata/Downloaded
Files/H76954
/H76954Specjalistyczny Gabinet Kardiologiczny Dr hab. med. Ewa
Straburzy?ska-Mig
aj.pdf
C:/Documents and Settings/rakshiar/My
Documents/userdata/Ruby/Scripts/FileNamere
naming.rb:20:in rename': Invalid argument - (C:/Documents and Settings/rakshiar /My Documents/userdata/Downloaded Files/H76954/Specjalistyczny Gabinet Kardiolog iczny Dr hab. med. Ewa Straburzy?ska-Migaj.pdf, C:/Documents and Settings/rakshi ar/My Documents/userdata/Downloaded Files/H76954/H76954Specjalistyczny Gabinet K ardiologiczny Dr hab. med. Ewa Straburzy?ska-Migaj.pdf) (Errno::EINVAL) from C:/Documents and Settings/rakshiar/My Documents/userdata/Ruby/Scrip ts/FileNamerenaming.rb:20:inblock (2 levels) in ’
from C:/Documents and Settings/rakshiar/My
Documents/userdata/Ruby/Scrip
ts/FileNamerenaming.rb:9:in each' from C:/Documents and Settings/rakshiar/My Documents/userdata/Ruby/Scrip ts/FileNamerenaming.rb:9:inblock in ’
from C:/Documents and Settings/rakshiar/My
Documents/userdata/Ruby/Scrip
ts/FileNamerenaming.rb:5:in each' from C:/Documents and Settings/rakshiar/My Documents/userdata/Ruby/Scrip ts/FileNamerenaming.rb:5:in’
C:\Documents and Settings\rakshiar\My Documents\userdata\Ruby\Scripts>
I believe the issue is how the read is being done.
/Specjalistyczny Gabinet Kardiologiczny Dr hab. med. Ewa
Straburzy?ska-Migaj.pdf
The ? tells me that Ruby isn’t parsing this correctly (or maybe parsing
is the
wrong term here encoding I think is a better choice). This looks similar
to an
encoding issue I recently faced within a text file.
I believe the issue is how the read is being done.
/Specjalistyczny Gabinet Kardiologiczny Dr hab. med. Ewa
Straburzy?ska-Migaj.pdf
The ? tells me that Ruby isn’t parsing this correctly (or maybe parsing
is the
wrong term here encoding I think is a better choice). This looks similar
to an
encoding issue I recently faced within a text file.
If there’s a length limit, try renaming using only the basename and then
move the file seperately.
I tried the below as you linked me:
file_new_name.gsub!(/[\x00/\:*?"<>|]/, ‘_’)
But still the error:
H76954
C:/Documents and Settings/rakshiar/My Documents/userdata/Downloaded
Files/H76954
/Specjalistyczny Gabinet Kardiologiczny Dr hab. med. Ewa
Straburzy?ska-Migaj.pdf
C:/Documents and Settings/rakshiar/My Documents/userdata/Downloaded
Files/H76954
/H76954Specjalistyczny Gabinet Kardiologiczny Dr hab. med. Ewa
Straburzy_ska-Mig
aj.pdf
C:/Documents and Settings/rakshiar/My
Documents/userdata/Ruby/Scripts/FileNamere
naming.rb:21:in `rename’: No such file or directory - (C:/Documents and
Settings
/rakshiar/My Documents/userdata/Downloaded Files/H76954/Specjalistyczny
Gabinet
Kardiologiczny Dr hab. med. Ewa Straburzy?ska-Migaj.pdf, C:/Documents
and Settin
gs/rakshiar/My Documents/userdata/Downloaded
Files/H76954/H76954Specjalistyczny
Gabinet Kardiologiczny Dr hab. med. Ewa Straburzy_ska-Migaj.pdf)
(Errno::ENOENT)
from C:/Documents and Settings/rakshiar/My
Documents/userdata/Ruby/Scrip
ts/FileNamerenaming.rb:21:in block (2 levels) in <main>' from C:/Documents and Settings/rakshiar/My Documents/userdata/Ruby/Scrip ts/FileNamerenaming.rb:9:ineach’
from C:/Documents and Settings/rakshiar/My
Documents/userdata/Ruby/Scrip
ts/FileNamerenaming.rb:9:in block in <main>' from C:/Documents and Settings/rakshiar/My Documents/userdata/Ruby/Scrip ts/FileNamerenaming.rb:5:ineach’
from C:/Documents and Settings/rakshiar/My
Documents/userdata/Ruby/Scrip
ts/FileNamerenaming.rb:5:in `’
C:\Documents and Settings\rakshiar\My Documents\userdata\Ruby\Scripts>
Look at the Ruby Gem UNF. I think that should solve your problem.
Wayne
----- Original Message ----
From: Arup R. [email protected]
To: ruby-talk ML [email protected]
Sent: Wed, January 30, 2013 7:31:13 AM
Subject: Re: (Errno::EINVAL) occurs during the File::rename() execution
After doing a bit research I found that there is a file called
“Specjalistyczny Gabinet Kardiologiczny Dr hab. med. Ewa
Straburzyńska-Migaj.pdf” in the directory - “H76954”. Now when the
script reading,one character - ń in the file name converting it
to the ?. Thus getting the error. Anyway to avoid the such
character encoding problem?
If there’s a length limit, try renaming using only the basename and then
move the file seperately.
I tried the below as you linked me:
file_new_name.gsub!(/[\x00/\:*?"<>|]/, ‘_’)
After doing a bit research I found that there is a file called
“Specjalistyczny Gabinet Kardiologiczny Dr hab. med. Ewa
Straburzyńska-Migaj.pdf” in the directory - “H76954”. Now when the
script reading,one character - ń in the file name converting it
to the ?. Thus getting the error. Anyway to avoid the such
character encoding problem?
I’ve never used it but it looks like all you have to do is: .to_unf
Wayne
----- Original Message ----
From: Arup R. [email protected]
To: ruby-talk ML [email protected]
Sent: Wed, January 30, 2013 7:50:48 AM
Subject: Re: (Errno::EINVAL) occurs during the File::rename() execution
Wayne B. wrote in post #1094354:
Look at the Ruby Gem UNF. I think that should solve your problem.