Script to convert all files in a directory from EBCDIC to ASCII

Script to convert all files in a directory from EBCDIC to ASCII

3
NewbieNewbie
3

    Aug 10, 2018#1

    Does anyone have a JavaScript on hand that can convert a file from EBCDIC to ASCII?

    I need to pull files daily from our AS400 and convert them to ASCII before uploading them via FTP to a customer.

    Also, since I'll have to do this every day, is there a command line option that I can run to automatically convert all of the files in a specific directory?

    This way I can create a batch file to run automatically every day which will save me from having to manually login each day to do the conversion.

    Thanks in advance for any responses.

    6,686585
    Grand MasterGrand Master
    6,686585

      Aug 10, 2018#2

      Open a new ASCII file and copy and paste into following two lines:

      Code: Select all

      for (var nDocIndex = 0; nDocIndex < UltraEdit.document.length; nDocIndex++) UltraEdit.document[nDocIndex].fromEBCDIC();
      UltraEdit.saveAll();
      
      Save the file with whatever name you like in whatever directory you prefer which is accessible for the account configured in scheduled task used later to run the automated conversion. The used account must have also read and execution permission to start UltraEdit and let UltraEdit read/write its configuration files.

      The command line to use in the batch file is:

      "C:\Program Files\IDM Computer Solutions\UltraEdit\uedit64.exe" /fni "C:\Path to\Folder with the\EBCDIC files\*" /s,e="C:\Path to\Script file\ScriptFile.js"

      You have to adapt the red formatted parts to your environment.

      UltraEdit is started with forcing a new instance opening all files in specified directory and  then running the specified script which converts all opened files from EBCDIC to ASCII and saves all files. UltraEdit exits itself after script execution finished.

      The used command line parameters are explained on help page Command Line Parameters which can be read by pressing key F1 in started UltraEdit, selecting second tab Index, enter or navigate in list to Command Line Parameters and double click twice on this term in list and in opened window with a sublist with just this page and one more page reference.

      On using your account in scheduled task running the batch file it could be useful to create a copy of %APPDATA%\IDMComp\UltraEdit\uedit64u.ini for example with name Convertu.ini in same directory and specify this INI file also on command line with /i="%APPDATA%\IDMComp\UltraEdit\Convertu.ini" instead of parameter /fni to use always the same INI file with the same settings for this conversion task.

      This special INI file used for the conversion task should have unchecked option Reload files previously open on startup at Advanced - Settings or Configuration - File handling - Load and should have checked option Clear recent document/project and search/replace histories on exit in configuration at Toolbars / menus - Miscellaneous. It would be also useful to have in this INI file unchecked the option Automatically check for updates at Application layout - Miscellaneous. Most important is that the setting Allow multiple instances is checked at Application layout - Miscellaneous. After creating the INI file Convertu.ini start UltraEdit once with just the two parameters /fni /i="%APPDATA%\IDMComp\UltraEdit\Convertu.ini" and make at least those four changes in configuration.
      Best regards from an UC/UE/UES for Windows user from Austria

      3
      NewbieNewbie
      3

        Aug 10, 2018#3

        Thanks Mofi, that works great. The only issue I have is with the new Convert.ini file. When I run with this option, I get "Convert.ini contains an incorrect path" message and UltraEdit throws an error as it closes. It still performs the conversion properly but GUI throws error. When I run the command line script with just the convert.ini, it opens and closes fine. But when I run with the conversion script included is when I see the errors.

        I've read through the .ini and I don't really see any paths that this account shouldn't have permissions to. I've also made sure all of the files and directories exist that are specified. Any suggestions on what might cause this?

        6,686585
        Grand MasterGrand Master
        6,686585

          Aug 12, 2018#4

          I have only tested the command line as posted without additionally using a specific INI file for this conversion task before my first reply. Now I have tested everything and here is the perfect working solution with using additionally a specific INI file.

          First, on using UltraEdit for Windows v24.00 or any later version, it is best to create a copy of uedit32u.ini (32-bit UltraEdit) respectively uedit64u.ini (64-bit UltraEdit) with name Convertu.ini in directory %APPDATA%\IDMComp\UltraEdit.

          Full Unicode aware versions of UltraEdit always expect INI file name with u as last character of file name left to file extension. So on using just Convert.ini, starting UltraEdit v24.00 or any later version with command line parameter /i="%APPDATA%\IDMComp\UltraEdit\Convert.ini", making the necessary changes in configuration and exiting UltraEdit, there are finally created in directory %APPDATA%\IDMComp\UltraEdit the files Convertu.in0, Convertu.ini and Convertu.rb0 in addition to Convert.ini. And UltraEdit has stored the changed settings in Convertu.ini and uses that file in future.

          For that reason for UltraEdit for Windows v24.00 or any later version it is better to create directly Convertu.ini as copy of uedit32u.ini or uedit64u.ini and start UltraEdit once with the command line parameter /i="%APPDATA%\IDMComp\UltraEdit\Convertu.ini" to configure this special INI file.

          Second, there are several options which should be checked or unchecked for this conversion task to make the conversion as fast as possible. Here is a list of recommended changes to do after starting UltraEdit with command line parameter /i= and opening Advanced - Settings or Configuration:
          • Editor - Advanced
            Uncheck setting Load/restore printer settings.
            Uncheck setting Auto-save modified documents when application loses focus.
          • Editor - Auto-complete
            Uncheck setting Show auto-complete dialog automatically.
          • Editor - Braces / strings
            Uncheck setting Enable auto-brace matching.
            Uncheck setting Enable brace auto-completion.
            Uncheck setting Enable string auto-completion.
          • Editor - Bookmarks
            Uncheck setting Save bookmarks.
          • Editor - XML / HTML
            Uncheck setting Display XML/HTML tag highlighting.
            Uncheck setting Automatically close XML/HTML tags.
          • Spell checker - Miscellaneous
            Uncheck setting Spell as you type.
          • File handling - Backup
            Select option No backup and of course do not use Version backup feature.
          • File handling - Conversions
            Configure the conversion options for EBCDIC to ASCII conversion as needed for your task.
          • File handling - DOS/Unix/Mac handling
            Select option Never prompt to convert files to DOS format and Uncheck all three check box options at bottom.
          • File handling - File change detection
            Select option Disable for File change detection and of course do not enable file polling feature, i.e. use value 0 for the polling interval.
          • File handling - Load
            Uncheck setting Reload files previously open on startup.
          • File handling - Miscellaneous
            Uncheck setting Create new file if the file specified on command line does not exist.
            Uncheck setting Create new Edit file when opening with no other files.
          • File handling - Save
            Configure the save settings to your requirements. Don't turn on automatic save feature.
          • File handling - Temporary files
            Select option Open file without temp file but NO Prompt and set Threshold for above (KB) to 0.
          • Editor display - Code folding
            Uncheck all settings on this configuration dialog.
          • Editor display - Formatting
            Uncheck setting Auto indent new lines.
          • Editor display - Line change indicator
            Uncheck setting Enable line change indicator (LCI).
          • Editor display - Miscellaneous
            Uncheck setting Disable line numbers.
            Uncheck setting Auto-correct keywords.
            Check setting Disable mouse wheel zoom.
            Uncheck setting Display CSS color tooltips.
          • Editor display - Syntax highlighting
            Uncheck setting Enable syntax coloring.
          • Application layout - Miscellaneous
            Check setting Allow multiple instances. This is most important setting in special INI file for the conversion task.
            Uncheck setting Automatically check for updates.
          • Application layout - Status bar
            Check setting Use basic status bar.
          • Toolbars / menus - Miscellaneous
            Uncheck setting Clear recent document/project and search/replace histories on exit.
          • Scripting
            Uncheck setting Show status information in output window.
            Uncheck setting Show cancel dialog.
          Third, it looks like there is a bug in UltraEdit v25.10.0.50 on parsing the command line parameters. /fni must be the first parameter on using it on command line. But it looks like /i= must be also specified as first parameter. Otherwise the specified INI file is used as expected, but additionally UltraEdit interprets the INI file argument also as file name argument and tries to open the INI file like a file to edit with a really strange build path consisting of current directory path on starting UltraEdit as well as parts of specified path. This wrong argument parsing results in the error message.

          The solution is using the command line as follows:

          "C:\Program Files\IDM Computer Solutions\UltraEdit\uedit64.exe" /i="%APPDATA%\IDMComp\UltraEdit\Convertu.ini" "C:\Path to\Folder with the\EBCDIC files\*" /s,e="C:\Path to\Script file\ScriptFile.js"

          Parameter /fni is replaced by parameter /i= with full specified INI file name to use which has setting Allow multiple instances enabled to make it possible to run UltraEdit for conversion task even if an instance of UltraEdit is currently running.

          Of course I reported the issue with wrong interpretation of parameter /i= on not being the first parameter on command line to IDM support by email which exists according to my tests only in UltraEdit for Windows v25.00.0.68 to currently latest v25.10.0.50 and UEStudio v18.00.0.04 to currently latest v18.10.0.08. Previous versions of UltraEdit or UEStudio don't have this bug.

          Update: The bug with wrong interpretation of parameter /i= on not being the first parameter on command line in UltraEdit for Windows 25.00.0.xx and 25.10.0.xx and UEStudio 18.00.0.xx and 18.10.0.xx was fixed with first public released UltraEdit 25.20 and UEStudio 18.20.
          Best regards from an UC/UE/UES for Windows user from Austria

          3
          NewbieNewbie
          3

            Aug 13, 2018#5

            Thanks Mofi, you're the best. I was able to stop the errors by swapping the /i with /fni so /i was the first option listed. Also, I found it helped to copy the original uedit64u.in0 & uedit64u.rb0 files in addition to the uedit64u.ini file. Now everything appears to be working without throwing any errors.

            Thanks again!