File shortcut

Everything else that doesn't fall into one of the other PB categories.
k3pto
User
User
Posts: 87
Joined: Sat Jan 17, 2015 5:24 pm

File shortcut

Post by k3pto »

Does PB have a way to access a file via a shortcut? FileSize (ShortcutName$) returns -1.
I tried searching the forum and did not find anything helpful.
Axolotl
Addict
Addict
Posts: 837
Joined: Wed Dec 31, 2008 3:36 pm

Re: File shortcut

Post by Axolotl »

If I get you right, you have to search for these keywords.

Code: Select all

CreateShortcut 
ShortcutTarget
Then you will find this one, among others.
Creating a desktop shortcut
Get the Shortcut target
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
BarryG
Addict
Addict
Posts: 4173
Joined: Thu Apr 18, 2019 8:17 am

Re: File shortcut

Post by BarryG »

k3pto wrote: Thu Apr 10, 2025 9:05 pmFileSize (ShortcutName$) returns -1
You can't get the actual ".lnk" file itself with FileSize(), if that's what you mean. Well, I've never seen or found a way.
Marc56us
Addict
Addict
Posts: 1600
Joined: Sat Feb 08, 2014 3:26 pm

Re: File shortcut

Post by Marc56us »

Hi,

A very old little program that I have wrote 11 years ago. (just updated)

Code: Select all

; Extract full program name from lnk file
; (C)Marc56(us) - 2015-11-27 
; Updated 2025-04-12

RegEx.s     = "^[A-Z]\:\\[\w\d\:\\\s\.()\-]+"
Source_Dir$ = GetUserDirectory(#PB_Directory_Desktop)

If Not CreateRegularExpression(1, RegEx)
    Debug "Bad RegEx" : End
EndIf

If ExamineDirectory(0, Source_Dir$, "*.lnk")
    While NextDirectoryEntry(0)
        If DirectoryEntryType(0) = #PB_DirectoryEntry_File
            File_Name$ = DirectoryEntryName(0)
            If ReadFile(2, Source_Dir$ + File_Name$)
                While Eof(2) = 0
                    Txt$ = ReadString(2)
                    If MatchRegularExpression(1, Txt$)
                        Debug "-" + RSet(File_Name$, 50, ".") + " > [" + Txt$ + "]"
                    EndIf
                Wend   
                CloseFile(2)    
            EndIf
        EndIf
    Wend
    FinishDirectory(0)
EndIf
Doesn't work in every situation, but almost.
:wink:
AZJIO
Addict
Addict
Posts: 2191
Joined: Sun May 14, 2017 1:48 am

Re: File shortcut

Post by AZJIO »

BarryG wrote: Sat Apr 12, 2025 1:09 pm
k3pto wrote: Thu Apr 10, 2025 9:05 pmFileSize (ShortcutName$) returns -1
You can't get the actual ".lnk" file itself with FileSize(), if that's what you mean. Well, I've never seen or found a way.
He does not have a shortcut. He cannot get an executable file from the missing shortcut.
Post Reply