netDIO is a Dyalog namespace of methods for Disk And File Input/Output Utility Using .Net. One advantage of using netDIO is that in most cases the file handle is guaranteed to be closed, even if exceptions are raised. This is important in mission critical application or long running program that cannot reboot easily. Check the comments of each methods for more information.

Text File with UTF-8 Encoding

This is the preferred way to exchange files with people in other country since the local encoding on their computer may change. The text file will be one continuous vector of characters.

   text←UFileRead file_name          ⍝ Reads The Contents of a Unicode Text File.
   text UFileWrite file_name         ⍝ Creates a New File, Writes The Text Using The UTF-8 Encoding.
   text UFileAppend file_name        ⍝ Appends The Specified Text to a File Using The UTF-8 Encoding.

Text File with UTF-8 Encoding as Multiple Lines

This method opens a file, reads each line of the file, then adds each line as an element of a vector. It then closes the file. A line is defined as a sequence of characters followed by a carriage return ('\r'), a line feed ('\n'), or a carriage return immediately followed by a line feed. The lines Read/Written is a vector of individual character vector where each element is representing a line.

  lines←UFileReadAllLines file_name   ⍝ Opens a text file, reads all lines of the file, and then closes the file.
  lines UFileWriteAllLines file_name  ⍝ Creates a new file, writes the specified individual lines to the file.
  lines UFileAppendAllLines file_name ⍝ Appends lines to a file using UTF8 encoding, and then closes the file.

  ⍝ Simple CSV file of numbers can be imported using UFileReadAllLines and a DFN function:
  lines ← 2⊃UFileReadAllLines file_name
  csv   ← ⊃','{2⊃⍺⎕VFI('-'⎕R'¯')⍵}¨lines    ⍝ The delimiter is ',' (left argument of the DFN)
                                            ⍝ If there is no negative value ('-'⎕R'¯') can be removed
                                            ⍝ csv is a matrix of numbers. Invalid numbers are replaced with 0

Text File with Default Windows Code Page

   text←TFileRead file_name          ⍝ Reads The Contents of a Text File Using the Default Windows Code Page.
   text TFileWrite file_name         ⍝ Creates a New File, Writes The Text Using The Default Windows Code Page.
   text TFileAppend file_name        ⍝ Appends The Specified Text to a File Using The Default Windows Code Page.

Binary File

   data←BFileRead file_name          ⍝ Reads The Contents of a Binary File Into a Character Vector Without Encoding.
   data BFileWrite file_name         ⍝ Creates a New File, Write The Specified Character Vector to The File Without Encoding.


        DirCopy (source_path target_path) ⍝ Copies a Directory And Its Contents. SubDirectories Are Not Copied.
        DirCreate path                    ⍝ Creates All Directories And Subdirectories as Specified By Path.
        DirDelete path                    ⍝ Deletes The Specified Directory And Any Subdirectories in The Directory.
        DirExists path                    ⍝ Determines Whether The Given Path Refers to an Existing Directory on Disk.
        DirMove (source_path target_path) ⍝ Moves a Directory And Its Contents. SubDirectories Are Moved.
        DirRename (actual_path new_path)  ⍝ Renames a Directory (This Method is Identical to DirMove).
        DirSize path                      ⍝ Returns The Size in Bytes of a Directory And It's Subdirectories.
        GetDirCurrent                     ⍝ Returns The Current Directory Path.
        GetDirectories path               ⍝ Returns The SubDirectories of a Directory.
        GetDrives                         ⍝ Returns The Names of The Logical Drives on This Computer as "<drive letter>:\".
        GetExtension file_name            ⍝ Returns The Extension of a Path String.
        GetFiles path                     ⍝ Returns The Names of Files in a Directory.
        SetDirCurrent path                ⍝ Sets The Current Directory Path.

File Manipulation and Info

                FileCopy (source_FileName target_FileName) ⍝ Copies an Existing File to a New File.
                FileDelete file_name                       ⍝ Deletes a File.
                FileExists file_name                       ⍝ Verify if One or Many File(s) Exists.
                FileMove (source_FileName target_FileName) ⍝ Moves a File to a New Location.
                FileRename (old_FileName new_FileName)     ⍝ Renames a File (This Method is Identical to FileMove).
                FileSize file_name                         ⍝ Returns The Size of a File in Bytes.
                FileVersion file_name                      ⍝ Returns The File Version of a File in Characters.
                GetAttributes file_name                    ⍝ Returns The Attributes of a File in Numeric And Litteral Form.
 new_attributes SetAttributes file_name                    ⍝ Sets The Attributes of a File.
                GetCreationTime file_name                  ⍝ Returns The Creation Date And Time of a File as DateTime Object.

File and Folder Dialogs

        DialogFolder       ⍝ Selects a Directory with FolderBrowserDialog.
        DialogOpenFile     ⍝ Selects a File to Open With OpenFileDialog.
        DialogSaveFile     ⍝ Selects a File to Save With SaveFileDialog.

See also wpfOokiiDialogBox and wpfDialogBox on the subject of Dialog Boxes.


            EncodingDetector file_name   ⍝ Returns The Encoding of a File And it's Content.
  {nsOrKey} NS2File file_name            ⍝ Function to save and retrieve a Namespace (NS) under a format compatible with C#.
            ZipCompressFile file_name    ⍝ Compress a file using Syncfusion Zip namespace.
            GetTempFileName              ⍝ Returns a Uniquely Named Temporary File on Disk With Full Path.
            GetTempPath                  ⍝ Returns The Path of The Current System's Temporary Folder.

See also Utf8orNot and UnicodeForAplers on the subject of Unicode.

How to install netDIO in your workspace

  1. Download netDIO.v1.2.txt

  2. Do a Select all (Ctrl+A) and a copy (Ctrl+C).
  3. In your workspace execute )ed ⍟ netDIO

  4. Paste (Ctrl+V) the text into the Dyalog editor
  5. Press Escape and ')save' your workspace

Optionally to de-script the namespace you can do:

'netDIO' ⎕SE.SALTUtils.CopyNs netDIO

Version Information

 Version 1.0 February 2015, Pierre Gilbert

 Version 1.1 August 2015
     Method Added:    UFileAppendAllLines

 Version 1.2 March 2016
     Method Corrected for bug: FileSize

Original author:

Pierre Gilbert




<apgil AT SPAMFREE videotron DOT ca>

CategoryDyalog - CategoryDyalogDotNet - CategoryDyalogDotNetUtilities - CategoryDotNet

netDIO (last edited 2016-03-16 14:55:51 by PierreGilbert)