zoukankan      html  css  js  c++  java
  • autohotkey 符号链接 软连接 symbolink

    使用objFolder=Shell.Application.NameSpace(文件夹)objFolderItem=..ParseName(文件)objFolder.GetDetailsOf(objFolderItem, iColumn),Windows 资源管理器 列
    参见代码中的说明、链接。

    包含隐式命令行访问方式(COM方式访问,WScript.ShellAttachConsoleobjExec := objShell.Execcmd_result := objExec.StdOut.ReadAll()dir /al

    ;i need help, how can i check a file is a "Symlink" file - Ask for Help - AutoHotkey Community
    #SingleInstance, Force
    ;https://autohotkey.com/board/topic/116161-i-need-help-how-can-i-check-a-file-is-a-symlink-file/page-2#entry671220
    SetBatchLines -1
    ComObjError(false)
    
    ;~ symlink=symlink_Shell
    symlink=symlink_Cmd
    previous:=Clipboard
    Loop{
        InputBox, OutputVar_file, Test, Input file/folder path to check,,,180,,,,,% previous
        if ErrorLevel
            ExitApp
        previous:=Trim(OutputVar_file,"""")
        if not FileExist(OutputVar_file)
            continue
        if %symlink%(OutputVar_file,target,type)
            MsgBox % OutputVar_file " is a symlink.`nTarget: " target "`nType: " type
        else
            MsgBox "%OutputVar_file%" is not a symlink
    }
    ;https://autohotkey.com/board/topic/116161-i-need-help-how-can-i-check-a-file-is-a-symlink-file/page-2#entry671199
    symlink_Shell(filepath,ByRef target="", ByRef type="")
    {
        SplitPath, filepath , FileName, DirPath,
        objShell :=   ComObjCreate("Shell.Application")
        objFolder :=   objShell.NameSpace(DirPath)      ;set the directry path
        objFolderItem :=   objFolder.ParseName(FileName)   ;set the file name
        att := objFolder.GetDetailsOf(objFolderItem, 6)
        ;    6: attributes (see iColumn bellow)
        ;    L: Link?
        status := objFolder.GetDetailsOf(objFolderItem, 202)
        ;    202: link status (see iColumn bellow)
        ;    "未解析“ test from symlink or normal file / folder
        target := objFolder.GetDetailsOf(objFolderItem, 203)
        ;    203: Link target (absolute) (see iColumn bellow)
        ;iColumn:
        ;    Folder.GetDetailsOf method (Shlobj\_core.h) - Win32 apps | Microsoft Docs
        ;        https://docs.microsoft.com/en-us/windows/win32/shell/folder-getdetailsof
        ;    c# - What options are available for Shell32.Folder.GetDetailsOf(..,..)? - Stack Overflow
        ;        https://stackoverflow.com/questions/22382010/what-options-are-available-for-shell32-folder-getdetailsof
        if (att="AL")
            type:="File"
        else if (att="DL")
            type := "Folder"
        ;else assert(att="A")
        if (att="AL" or att="DL")
            return 1
        else
            return 0
    }
    ;    https://autohotkey.com/board/topic/116161-i-need-help-how-can-i-check-a-file-is-a-symlink-file/page-2#entry671733
    symlink_Cmd(filepath,ByRef target="", ByRef type="")
    {
        if RegExMatch(filepath,"^w:\?$") ;returns 0 if it is a root directory
            return 0
        SplitPath, filepath , fn, pdir
        dhw := A_DetectHiddenWindows
        DetectHiddenWindows On
        Run "%ComSpec%" /k,, Hide, pid
        while !(hConsole := WinExist("ahk_pid" pid))
            Sleep 10
        DllCall("AttachConsole", "UInt", pid)
        DetectHiddenWindows %dhw%
        objShell := ComObjCreate("WScript.Shell")
        objExec := objShell.Exec(comspec " /c dir /al """ (InStr(FileExist(filepath),"D") ? pdir "" : filepath) """")
        While !objExec.Status
            Sleep 100
        cmd_result := objExec.StdOut.ReadAll()
        DllCall("FreeConsole")
        Process Exist, %pid%
        if (ErrorLevel == pid)
            Process Close, %pid%
        if RegExMatch(cmd_result,"<(.+?)>.*?Q" fn "E.*?[(.+?)]",m)
        {
            type:=m1, target:=m2
            ;    target: original (maybe relative)
            if (type="SYMLINK")
                type := "File"
            else if (type="SYMLINKD")
                type := "Directory"
            return 1
        }
        else
            return 0
    }
    
    View Code

     扩展:[Function] FilesHardLinked() - Detect if two files are hardlinks (links pointing to the same file) - AutoHotkey Community

  • 相关阅读:
    BZOJ1969: [Ahoi2005]LANE 航线规划
    BZOJ1800: [Ahoi2009]fly 飞行棋
    BZOJ2661: [BeiJing wc2012]连连看
    BZOJ2464: 中山市选[2009]小明的游戏
    BZOJ2440: [中山市选2011]完全平方数
    BZOJ2226: [Spoj 5971] LCMSum
    Codeforces 610B
    Codeforces 757B
    Codeforces B
    HDU 6090 Rikka with Graph
  • 原文地址:https://www.cnblogs.com/RobertL/p/14762236.html
Copyright © 2011-2022 走看看