How to convert files to UTF-8
Hi, I have sites written in Win-1250 alias cp150. I need to convert all files to UTF-8. I know about iconv but I found problem with this tool. When I tried to convert I had to make a copy of the original file. But I have many files in (sub)folders. So If I would want to use iconv instead, I would need to convert all files from *.php to *.tmp and than copy or rename back to *.php. This looks too difficult. Any other way how to do it, something intelligent and simple?
Thanx |
You already have the utility (iconv). You simply have to find the files to be converted and then decide where to put the converted files. (This is the "intelligent and simple" way to do it)
One possibility: Create a directory where all the converted files will go. Suppose it is "nufiles". Then, simply do this: Code:
for filename in *; do iconv <options> $filename > nufiles/$filename; done Code:
for filename in $(find <path> -name "*.php*") do |
Thanx I will try
|
I have this code:
Code:
path="www" - iconv: enter sequence not allowed on position 263 - file does not exist - mv: cannot get informations about *„tmpfile“ - file does not exist |
Code:
iconv -f WINDOWS-1250 -t UTF-8 < $filename > tmpfile iconv -f oldformat -t newformat file I don't know if your form is equivalent, but I would try it first as specified. Adding the redirection "> tmpfile" is fine regardless |
Well I try your syntax and much less errors happened.
I found this error: file name: "www/information/select, insert, update.txt" Returns: iconv: file „www/information/select,“ cannot open: file not found iconv: file „insert,“ cannot open: file not found iconv: file „update.txt“ cannot open: file not found Edit: Solution: "$filename" |
My hunch is that you need to look thru all your subfolders and find whatever is causing this----starting with how $filename gets set to that long string.
When you find the directory with the evidence, run the command there. Be sure to look for hidden files, also... ls -a ls -al |
Well 1st problem disappeared. I don't know how. I just copied new (original) folder and run the script again. The php files are right converted.
However see this: Code:
# pwd Code:
++ iconv -f WINDOWS-1250 -t UTF-8 www/system/vstupy/+info/info I added -size +10 to end of the find command Edit: No success. I delete the file "info" and run again. And it stopped with the same error. I dont know what to do with it. Note: The iconv error illegal (not allowed) input sequence on position n means that the file was already converted and I converted it twice. |
Do you see the file name "info - errors.txt"? So the space is like separator even I have "$filename" in the ""
Code:
iconv: input file „www/system/vstupy/+info/info“ The second is "-" ... and this causes that process stoped like "read" command. What I need to do to fix the syntax? This is my code: Code:
path="www" |
Maybe is the problem in the separator of find command?
Does the find see the "info - errors.txt" file as three files? I think so. Then I set Code:
IFS=$'\n' |
Indeed---spaces in filenames not good.
I would advise changing them all ( a simple script can--eg-- change all the spaces to "_" ) |
I also find spaces in filenames a pain in the @$$.
I basically made a rule for myself to treat spaces as if they are illegal filename characters. |
Quote:
I think it is posible to remake the command to syntax like Code:
find -name "*.php" -exec iconv <options> {} |
Quote:
|
Quote:
|
All times are GMT -5. The time now is 02:22 PM. |