From ea296101f12a61b1edae25982499328bee379bd1 Mon Sep 17 00:00:00 2001 From: phil294 Date: Thu, 20 Jul 2023 11:02:02 +0200 Subject: [PATCH] Add SplitPath --- README.md | 8 ++++---- docs/index.html | 22 +++++++++++----------- src/cmd/file/split-path.cr | 12 ++++++++++++ 3 files changed, 27 insertions(+), 15 deletions(-) create mode 100644 src/cmd/file/split-path.cr diff --git a/README.md b/README.md index 0237899..c74af09 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ AHK_X11 can be used completely without a terminal. You can however if you want u
CLICK TO SEE WHICH COMMANDS ARE IMPLEMENTED AND WHICH ARE MISSING. Note however that this is not very representative. For example, no `Gui` sub command is included in the listing. For a better overview on what is already done, skim through the FULL DOCUMENTATION HERE. ```diff -DONE ?% (123/220): +DONE ?% (124/220): + Else, { ... }, Break, Continue, Return, Exit, GoSub, GoTo, IfEqual, Loop, SetEnv, Sleep, FileCopy, + SetTimer, WinActivate, MsgBox, Gui, SendRaw, #Persistent, ExitApp, + EnvAdd, EnvSub, EnvMult, EnvDiv, ControlSendRaw, IfWinExist/IfWinNotExist, SetWorkingDir, @@ -73,7 +73,7 @@ DONE ?% (123/220): + #NoTrayIcon, TrayTip, Random, Shutdown, RunAs, SoundGet, SoundSet, SoundPlay, Sort, + StringTrimLeft, StringTrimRight, WinMinimizeAll, WinMinimizeAllUndo, WinSetTitle, WinWait, + WinWaitClose, WinWaitActive, WinWaitNotActive, DriveSpaceFree, FileGetSize, FileRecycle, -+ FileRecycleEmpty ++ FileRecycleEmpty, SplitPath NEW ?% (9/220): (not part of spec or from a more recent version) @@ Echo, ahk_x11_print_vars, FileRead, RegExGetPos, RegExReplace, EnvGet, Click @@ @@ -88,7 +88,7 @@ REMOVED ?% (11/220): # AutoTrim: It's always Off. It would not differentiate between %a_space% and %some_var%. # It's possible but needs significant work. -TO DO ?% (73/220): alphabetically +TO DO ?% (72/220): alphabetically - BlockInput, Control, ControlFocus, ControlGet, ControlGetFocus, - ControlMove, - DetectHiddenText, DetectHiddenWindows, Drive, DriveGet, @@ -104,7 +104,7 @@ TO DO ?% (73/220): alphabetically - SetCapslockState, SetControlDelay, SetDefaultMouseSpeed, SetFormat, - SetNumlockState, SetScrollLockState, SetStoreCapslockMode, SetTitleMatchMode, - SetWinDelay, SoundGetWaveVolume, -- SoundSetWaveVolume, SplashImage, SplashTextOn, SplashTextOff, SplitPath, StatusBarGetText, +- SoundSetWaveVolume, SplashImage, SplashTextOn, SplashTextOff, StatusBarGetText, - StatusBarWait, StringCaseSense, StringSplit, - SysGet, Thread, Transform, WinActivateBottom, - WinGetActiveStats, WinGetActiveTitle, diff --git a/docs/index.html b/docs/index.html index 31a0e27..28eaaf4 100644 --- a/docs/index.html +++ b/docs/index.html @@ -183,7 +183,7 @@

Table of contents

SetWorkingDir
  • - SplitPath + SplitPath
  • @@ -2622,7 +2622,7 @@

    The "Last Found" Window

    Closes the above window. - SplitPath + SplitPath Separates a file name into its name, directory, extension, and drive. @@ -5011,15 +5011,15 @@

    The "Last Found" Window

    -
    +
    - #

    SplitPath

    [v1.0.15+] + #

    SplitPath


    -

    Separates a file name into its name, directory, extension, and drive.

    +

    Separates a file name into its name, directory, extension, and drive.

    - +
    SplitPath, InputVar [, OutFileName, OutDir, OutExtension, OutNameNoExt, OutDrive]SplitPath, InputVar [, OutFileName, OutDir, OutExtension, OutNameNoExt, OutDrive]
    @@ -5037,7 +5037,7 @@

    The "Last Found" Window

    OutDir - Name of the variable in which to store the directory of the file, including drive letter or share name (if present). The final backslash is not included even if the file is located in a drive's root directory. + Name of the variable in which to store the directory of the file, including drive letter or share name (if present). The final backslash is not included even if the file is located in a drive's root directory. OutExtension @@ -5047,7 +5047,7 @@

    The "Last Found" Window

    OutNameNoExt Name of the variable in which to store the file name without its path, dot and extension. - + OutDrive Name of the variable in which to store the drive letter or server name of the file. If the file is on a local or mapped drive, the variable will be set to the drive letter followed by a colon. If the file is on a network path (UNC), the variable will be set to the share name, e.g. \\Workstation01 @@ -5058,16 +5058,16 @@

    The "Last Found" Window

    Any of the output variables may be omitted if the corresponding information is not needed.

    If InputVar contains a filename with no path or just a relative path (e.g. Address List.txt), OutDrive will be made blank but all the other output variables will be set correctly. Similarly, if there is no path present, OutDir will be made blank; and if there is a path but no file name present, OutFileName and OutNameNoExt will be made blank.

    Actual files and directories in the file system are not checked by this command. It simply analyzes the string given in InputVar.

    -

    Wildcards (* and ?) and other characters illegal in filenames are treated the same as legal characters, with the exception of colon, backslash, and period (dot), which are processed according to their nature in delimiting the drive letter, directory, and extension of the file.

    +

    Wildcards (* and ?) and other characters illegal in filenames are treated the same as legal characters, with the exception of colon, backslash slash, and period (dot), which are processed according to their nature in delimiting the drive letter, directory, and extension of the file.

     

    Related

    StringSplit, StringGetPos, StringMid, StringTrimLeft, StringLeft, FileSelectFile, FileSelectFolder

     

    Example

    -

    FullFileName = C:\My Documents\Address List.txt
    +

    FullFileName = %A_Home%/My Documents/Address List.txt

    ; To fetch only the bare filename:
    SplitPath, FullFileName, name

    ; Or, to fetch all info:
    SplitPath, FullFileName, name, dir, ext, name_no_ext, drive
    -
    ; The above will set the variables as follows:
    ; name = Address List.txt
    ; dir = C:\My Documents
    ; ext = txt
    ; name_no_ext = Address List
    ; drive = C: +
    ; The above will set the variables as follows:
    ; name = Address List.txt
    ; dir = /home/your-user-name/My Documents
    ; ext = txt
    ; name_no_ext = Address List
    ; drive = C:

    diff --git a/src/cmd/file/split-path.cr b/src/cmd/file/split-path.cr new file mode 100644 index 0000000..8944443 --- /dev/null +++ b/src/cmd/file/split-path.cr @@ -0,0 +1,12 @@ +# SplitPath, InputVar [, OutFileName, OutDir, OutExtension, OutNameNoExt, OutDrive] +class Cmd::File::SplitPath < Cmd::Base + def self.min_args; 1 end + def self.max_args; 6 end + def run(thread, args) + path = Path.new thread.get_var(args[0]) + thread.runner.set_user_var(args[1], path.basename) if args[1]? + thread.runner.set_user_var(args[2], path.dirname) if args[2]? + thread.runner.set_user_var(args[3], path.extension[1..]?||"") if args[3]? + thread.runner.set_user_var(args[4], path.stem) if args[4]? + end +end \ No newline at end of file