ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
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.
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.
$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
// 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
} // 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.