Convert multiple files to UTF-8

Help with writing and playing macros

Convert multiple files to UTF-8

Postby bshadow » Wed Aug 09, 2006 12:24 am

Hi
I would like to convert like 30 files to UTF-8 from ASCII.
I got no idea doing this.
But I wanna do it to all the files in the same time, save them and finish the job quickly.
I don't know how to do it and I don't have time to do one by one.

Please help, thanks.
User avatar
bshadow
Newbie
 
Posts: 2
Joined: Mon Aug 07, 2006 11:00 pm

Re: Convert multiple files to UTF-8

Postby Mofi » Wed Aug 09, 2006 7:30 am

Sorry, but there is no ASCIIToUTF8 macro command (up to UE v17.20) nor a method to make the conversion for all opened files at once. Best idea I have is to open all files and use following macro:

Loop
IfNameIs ""
ExitLoop
EndIf
SaveAs ""
CloseFile
EndLoop

This macro opens the Save As dialog for every opened file. At the first file select Format: UTF-8 or UTF-8 - NO BOM and press twice the Return key to save the file with it's current name and overwrite the current file. For all other files you only have to press RETURN, TAB, RETURN. You can insert into the macro further commands before the SaveAs command to insert also the appropriate HTML or XML encoding information into every file.

Attention: Don't forget to set the Format in the Save As dialog back to your preferred file format or Default before saving a new file next time.

Note: The following macro will not work because with SaveAs without dialog the file is always saved in the current format of the file.

Clipboard 9
Loop
IfNameIs ""
ExitLoop
EndIf
CopyFilePath
SaveAs "^c"
CloseFile
EndLoop
ClearClipboard
Clipboard 0

The first macro above does not work anymore as explained with UltraEdit v16.00 depending on version of Windows because with v16.00 the Format option of the Save As dialog is not remembered anymore between two calls (Windows 2000 and Windows XP only, see Format (encoding) not preset correct in Save As dialog (fixed) for details). The Format option is now always set to Default on opening of the Save As dialog.

But UE v16.00 and later have now a configuration setting at Advanced - Configuration - Editor - New File Creation to create new files by default as UTF-8 files and therefore using this setting a macro could be used which just copies, the name of the file to a clipboard, the complete content of the file to another clipboard, close the file, opens a new file (encoded in UTF-8), paste the content from clipboard and saves the name from first clipboard.

Loop
IfNameIs ""
ExitLoop
EndIf
Clipboard 8
CopyFilePath
Clipboard 9
SelectAll
Copy
CloseFile
NewFile
Paste
Clipboard 8
SaveAs "^c"
CloseFile
EndLoop
Clipboard 8
ClearClipboard
Clipboard 9
ClearClipboard
Clipboard 0
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4055
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Convert multiple files to UTF-8

Postby bshadow » Wed Aug 09, 2006 11:26 am

I'm kind new to this program, can you tell me exactly how to create a macro and do that?

thanks
User avatar
bshadow
Newbie
 
Posts: 2
Joined: Mon Aug 07, 2006 11:00 pm

Re: Convert multiple files to UTF-8

Postby Mofi » Wed Aug 09, 2006 12:41 pm

In menu Macro select Record. Enter the name for the macro. The other options are not important for THIS macro, but better disable the Show Cancel Dialog for this macro. Press OK button to start recording.

Then stop macro recoding immediatelly by clicking on Macro - Stop Recording. Next click on Macro - Edit Macro and paste my macro lines over the existing 4 lines which are not needed. Close the dialog and the macro is ready to use. Open all your files to convert and run the macro with Macro - Play Again.

Note: If you can't see the macro menu, click with the right mouse button on a free area of the menu bar and select Advanced (instead of Basic) to switch to the Advanced menu.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4055
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna


Return to Macros