Simple execute it in a console.
// Removes the Byte Order Mark - BOM from a text file with UTF-8 encoding
// The BOM defines that the file was stored with an UTF-8 encoding.
function RemoveBOM(filePath) {
// Create a reader and a writer
var writer,reader, fileSize;
var writer = new ActiveXObject("Adodb.Stream");
var reader = new ActiveXObject("Adodb.Stream");
// Load from the text file we just wrote
reader.Open();
reader.LoadFromFile( filePath);
// Copy all data from reader to writer, except the BOM
writer.Mode=3;
writer.Type=1;
writer.Open();
reader.position=5;
reader.copyto(writer,-1);
// Overwrite file
writer.SaveToFile(filePath,2);
// Return file name
RemoveBOM = filePath;
// Kill objects
var writer = null;
var reader = null;
}
RemoveBOM("OPM_Mitarbeiter.csv-utf8.txt");
cscript bomremover.js
Keine Kommentare:
Kommentar veröffentlichen