Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have had a lot of files with filenames in windows-1251 encoding. I wanted to convert it to utf8.But I have accidentally converted it wrongly by convmv:

convmv -r --notest -f windows-1255 -t utf8 *

So now I need to convert it from utf8 to windows-1255 again than from windows-1251 to utf8 but convmv doesn't want to do it:

convmv --notest -f utf8 -t windows-1255 זטחם�.docx
cp1255 doesn't cover all needed characters for: "./זטחם�.docx"
To prevent damage to your files, we won't continue.
First fix this or correct options!

Is any --force option for convmv? How I can fix my file's filenames without convmv?

Here is file example http://fbe.am/l8O

share|improve this question

migrated from stackoverflow.com Jun 1 '13 at 0:51

This question came from our site for professional and enthusiast programmers.

    
Read this option --nosmart in man page: j3e.de/linux/convmv/man/#nosmart –  QMechanic73 Jun 2 '13 at 16:25
    
@TiagoCa thanks, but it haven't helped. –  freemanoid Jun 2 '13 at 17:21
    
Could you post an example file somewhere so we can try it out? –  terdon Jun 3 '13 at 14:50
    
Yes here is fbe.am/l2N –  freemanoid Jun 4 '13 at 9:02
1  
Could you upload the file as a .zip? The name gets converted to HTML escapes (זטחם�.docx) when downloaded. –  terdon Jun 6 '13 at 12:23

1 Answer 1

up vote 2 down vote accepted
+50

THIS IS NOT A GOOD IDEA

The convmv is just a simple Perl script, so the code is quite easy to edit. It is set to exit if certain tests fail, by telling it to ignore the test results and continue, I was able to do:

../convmv.modified.pl --notest -f utf8 -t windows-1255 זטחם�.docx 
Your Perl version has fleas #37757 #49830 
cp1255 doesn't cover all needed characters for: "./זטחם�.docx"
mv "./זטחם�.docx"   "./����"
Ready!

This created a file called ????, I could then use normal convmv to change its encoding to utf8 (had to use find because I could not give ???? as a file name):

find . -type f -exec convmv --notest -f windows-1255 -t utf8 {} \;

$ find . -type f -exec convmv --notest -f windows-1255 -t utf8 {} \;
Your Perl version has fleas #37757 #49830 
mv "./����" "./זטחם"
Ready!

I then renamed the file to add the docx extension (mv זטחם זטחם.docx) and could open the file in libre office.


This is a bad idea because I have not solved the problem that stopped convmv from correctly converting your files, I simply ignored it. I think the problem is that your first, mistaken conversion added strange characters to the file name that convmv does not know how to deal with. I cannot guarantee that (or even offer an opinion on whether) this will not harm your files. I recommend you try it on one file first and see if it actually works.

The other problem is that I was expecting the file name to be in the same alphabet as that of the file's text and it is not (I think), so the entire operation probably just failed. Since I can't read the alphabet in question I cannot be sure.

Anyway, if you want to try this, you need to make the following changes to /usr/bin/convmv:

  1. Comment line 359, change this:

    die "To prevent damage to your files, we won't continue.\nFirst fix errors or correct options!\n" if ($errors_occurred);
    

    To this:

    #die "To prevent damage to your files, we won't continue.\nFirst fix errors or correct options!\n" if ($errors_occurred);
    
  2. And change this (line 460):

    from_to($newname, $opt_f, $opt_t, Encode::FB_QUIET) or die "SHOULD NOT HAPPEN HERE: conversion error, so suitable charset used?: \"$oldfile\"\nTo prevent damage to your files, we won't continue. First fix this!\n";
    

    to this:

    from_to($newname, $opt_f, $opt_t, Encode::FB_QUIET);
    
share|improve this answer
    
If remove � characters from the filename then convmv works well. –  freemanoid Jun 6 '13 at 14:20
1  
@freemanoid Yes but I guess that the � represents soemthig you don't want to lose, if that is the only problem, you can remove them with this command: find . -name "*�*" -exec rename 's/�//g' '{}' \; –  terdon Jun 6 '13 at 14:23
    
I really would like to have more clean solution. Thank you. –  freemanoid Jun 6 '13 at 14:36
1  
@freemanoid yes, as I said, this is not a good solution. The problem, however, is that since you have renamed the files, you have probably lost some information. I don't think you will be able to do much better than this... –  terdon Jun 6 '13 at 14:48
1  
@freemanoid yes, that depends on your implementation of rename you seem to have the one from util-linux. –  terdon Jun 8 '13 at 16:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.