ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have been writing a VBA script (not my area of expertise) to extract some data from an excel spreadsheet and generate an XML file. The XML file is going to be read in by an existing program. The file will include some Unicode characters and so VBA needs it to be saved as an Unicode (UTF-8) file but the program that will read the file needs it to be saved in ASCII format.
I have opened the file with Notepad++ switched the encoding to ASCII and saved the file and this works.
However I am going to generate about 5000 files, I don't really want to do this for each one by hand! So does anyone know of a way in which I can automate this process.
Ideas, solutions welcome.
Thanks very much.
Click here to see the post LQ members have rated as the most helpful post in this thread.
Excellent response, thanks unSpawn & jim mcnamara. The iconv is supported in php so I can put together a quick script to locate each file and convert it. I'm a little confused by the encodings that I needed to use but I've tested it and it works, so I'm relieved.
function encodeFiles($rootPath) { $directories = scandir($rootPath); // Loop through each directory in the rootPath foreach ($directories as $dir) { $fileName = $rootPath."\\".$dir. "\\metadata.xml"; // Check to see if the current directory has a file called metadata.xml if (file_exists($fileName)) { // Read in the contents $data = file_get_contents($fileName); // Just display on the screen the file being modified echo "Converting " . $fileName . "...\n"; // Convert the contents $data = iconv("UCS-2","UTF-8", $data); // Write back out to the same file file_put_contents($fileName,$data); } // end if file exists } // end loop for each directory in the root directory } // end of function encodeFiles()
When I open the file in Notepad++ it tells me the encoding is ANSI, which is what I needed and the program I feed the file into accepts it. So I'm now making progress in the conversion job.
My title was describing what I thought I needed to do at the time. The program I'm creating the xml files for is fairly poor on documentation and I had spent the whole afternoon trying to figure out why they were being rejected, no errors, no log files, not much in the way of assistance.
But I'm now over that hurdle, I wonder what it will throw at me next.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.