Getting only current directory

Getting only current directory

2
NewbieNewbie
2

    Dec 31, 2013#1

    I am doing development on Windows and sending the files to Unix (no, I cannot put UltraEdit on our Unix platform). Obviously the paths are set up differently, so I would like to extract my current directory so that, instead of [FILE_PATH], I can set up /my unix path/[CURRENT_DIRECTORY]. I have set up my directory structure on Windows to match that on Unix. Is there anything like that? Is there anything like that, or any way to add a new expression? Thanks.

    6,686585
    Grand MasterGrand Master
    6,686585

      Jan 01, 2014#2

      That's not possible with a smart template. The usage of an UltraEdit macro or script is necessary. A script is in my point of view better as there is a property which contains full name of active file, string variables are supported and string variables can be also easily modified with the replace function of the string object.

      Here is the script solution:

      Code: Select all

      if (UltraEdit.document.length > 0)  // Is any file opened?
      {
         // Is active file a named file?
         if (!UltraEdit.activeDocument.isName(""))
         {
            UltraEdit.insertMode();
            // Get just directory path without drive letter, colon and
            // backslash at beginning from full name of active file.
            // The directory path ends with a backslash (on Windows).
            var sDirectory = UltraEdit.activeDocument.path.replace(/^\w:\\(.+\\).+$/,"$1");
            // Write into the active file at current position of the caret
            // the directory path extended at beginning with fixed UNIX
            // path and with all backslashes replaced by forward slashes.
            UltraEdit.activeDocument.write("/my unix path/"+sDirectory.replace(/\\/g,"/"));
         }
      }
      Copy and paste this code into a new ASCII file. Save the ASCII file for example as GetUnixPath.js into a folder where you want to keep your scripts. Then open Scripting - Scripts and add this script to the list of scripts. If you need to execute this script often for inserting the path of the active file into the file as UNIX path, assign a hotkey or chord to the script for quickly executing the script. The script can be also executed from Scripting menu or via double click on the script name from the Script List opened via View - Views/Lists - Script List.

      Edit: See also function GetFolderName at general file name evaluating functions.
      Best regards from an UC/UE/UES for Windows user from Austria

      2
      NewbieNewbie
      2

        Jan 02, 2014#3

        Thanks!