I have a 100+ files that were saved with "ISO-8851-1 Western” encoding. I need to convert and save them to “UTF-8”encoding. I can easily open all of them but when I attempt so perform a “Save as” it only saves the first document. Is there save all of them in a single step?
Thanks.
On 10 Jan 2016, at 09:46, J Galt jgaltusa@gmail.com wrote:
I have a 100+ files that were saved with "ISO-8851-1 Western” encoding. I need to convert and save them to “UTF-8”encoding. I can easily open all of them but when I attempt so perform a “Save as” it only saves the first document. Is there save all of them in a single step?
menu File, Save All? It even has a shortcut.
Berend
“Save All” does not work because it does not prompt to choose a new encoding method. In fact, “Save All” does not seem to do anything. I am guessing because it does not detect any changes have been made to the files.
On Jan 10, 2016, at 3:29 AM, Berend Hasselman bhh@xs4all.nl wrote:
menu File, Save All? It even has a shortcut.
Hello there,
On 10 Jan 2016, at 9:46 AM, J Galt jgaltusa@gmail.com wrote:
I have a 100+ files that were saved with "ISO-8851-1 Western” encoding. I need to convert and save them to “UTF-8”encoding. I can easily open all of them but when I attempt so perform a “Save as” it only saves the first document. Is there save all of them in a single step?
IMHO, such task is a job for some command line magic. :-)
Something like this could do: $ find sourcedir -type f -execdir sh -c 'iconv -f iso-8859-1 -t utf-8 "{}" > /path/to/destdir/"{}"' ;
This command line uses iconv to convert all files from "sourcedir" and put the result of the conversion into "destdir".
regards, Christian
Do I execute this from the terminal?
I tried to but it returned the following error: -bash: -type: command not found
On Jan 10, 2016, at 3:36 AM, Christian Rosentreter karibu@gmx.net wrote:
IMHO, such task is a job for some command line magic. :-)
Something like this could do: $ find sourcedir -type f -execdir sh -c 'iconv -f iso-8859-1 -t utf-8 "{}" > /path/to/destdir/"{}"' ;
This command line uses iconv to convert all files from "sourcedir" and put the result of the conversion into "destdir".
Hello there,
On 11 Jan 2016, at 9:51 AM, J Galt jgaltusa@gmail.com wrote:
Do I execute this from the terminal?
I tried to but it returned the following error: -bash: -type: command not found
Yes, from Terminal. The "$" in my example symbolises a common Terminal prompt. So you type everything starting with "find" (skip the "$") and replace "sourcedir" and "/path/to/destdir/" with respective locations on your system.
On Jan 10, 2016, at 3:36 AM, Christian Rosentreter karibu@gmx.net wrote:
IMHO, such task is a job for some command line magic. :-)
Something like this could do: $ find sourcedir -type f -execdir sh -c 'iconv -f iso-8859-1 -t utf-8 "{}" > /path/to/destdir/"{}"' ;
This command line uses iconv to convert all files from "sourcedir" and put the result of the conversion into "destdir".
regards, Christian
I removed the dollar sign and it appears to execute the first part but nothing happens on the second part where it is saving to the destination directory.
On Jan 11, 2016, at 3:28 AM, Christian Rosentreter karibu@gmx.net wrote:
Yes, from Terminal. The "$" in my example symbolises a common Terminal prompt. So you type everything starting with "find" (skip the "$") and replace "sourcedir" and "/path/to/destdir/" with respective locations on your system.
Hi there,
On 11 Jan 2016, at 6:52 PM, J Galt jgaltusa@gmail.com wrote:
I removed the dollar sign and it appears to execute the first part but nothing happens on the second part where it is saving to the destination directory.
I'm not sure what goes wrong for you. I just tried it again and it does the job fine for me. I'm using OS X 10.10.5 (Yosemite) with default "find" and "iconv" commands by Apple.
Example Terminal "session" for reference: https://pastebin.com/BpSRGpCM (empty lines added between the commands for readability)
Perhaps someone else can provide a smarter solution or a ready-to-use script for the purpose. It's just that for me "find" with "-exec[dir]" is the first thing that comes to mind in regards to batch processing of files. The same goes for "iconv" and charset conversion. :-)
Sorry, that I can't be of more help.
regards, Christian
Thanks for the example Christian. I finally got it to work.
In an effort to emulate your example I ended up creating two new folders on my desktop “latin1” and “utf8”. I moved my files into the “latin1” folder and executed this modified version of your code in the terminal:
find /Users/galt/Desktop/latin1/ -type f -execdir sh -c 'iconv -f iso-8859-1 -t utf-8 "{}" > /Users/galt/Desktop/utf8/"{}"' ;