December 04, 2020, 11:28:33 AM

Author Topic: [bb] GetFileFromShortcut by John Blackledge [ 1+ years ago ]  (Read 484 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
Title : GetFileFromShortcut
Author : John Blackledge
Posted : 1+ years ago

Description : Call GetFileFromShortcut$(yourlnk$)
which returns the internal filename


Code :
Code: BlitzBasic
  1. ;---------------------------------
  2. ; zlibGetFileFromShortcut ; John Blackledge 06/02/2013
  3. ;---------------------------------
  4. ; for normal use just comment out Example()
  5. ; and call GetFileFromShortcut$(yourlnk$)
  6. ; which returns the internal filename
  7. ;---------------------------------
  8.  
  9. ;Example()
  10.  
  11. ;---------------------------------
  12. Function Example()
  13. ;---------------------------------
  14.         Graphics 1024,768
  15.        
  16.         lnk$ = "C:Documents and SettingsJohnDesktopLifestory.doc.lnk"
  17.         Print "From file shortcut "+lnk$
  18.         file$ = GetFileFromShortcut$(lnk$,1)
  19.         Print "File = "+file$
  20.         Print " "
  21.        
  22.         lnk$ = "C:Documents and SettingsJohnDesktopSys.lnk"
  23.         Print "From folder shortcut "+lnk$
  24.         file$ = GetFileFromShortcut$(lnk$)
  25.         Print "File = "+file$
  26.         Print " "
  27.        
  28.         WaitKey()
  29.         End
  30.        
  31. End Function
  32.  
  33. ;---------------------------------
  34. Function GetFileFromShortcut$(lnk$, printfg=0)
  35. ;---------------------------------
  36.         Local filein, m$,b,index,rindex,name$,search$
  37.         Local startpos, endpos, i, char$
  38.         Local length, path$
  39.        
  40.         If printfg=1 Then Print "Filesize "+FileSize(lnk$)
  41.        
  42.         filein = ReadFile(lnk$)
  43.         m$ = ""
  44.         While Not Eof(filein)
  45.                 b = ReadByte(filein)
  46.                 m$ = m$ + Chr$(b)
  47.         Wend
  48.         CloseFile(filein)
  49.         If printfg=1 Then Print "Read in "+Len(m$)
  50.        
  51. ; Isolate "Lifestory.doc.lnk"
  52.         rindex = JRinstr(lnk$,"")
  53.         name$ = Mid$(lnk$,rindex)
  54.         If printfg=1 Then Print name$
  55.        
  56. ; Isolate "Lifestory.doc"
  57.         rindex = JRinstr(name$,".")
  58.         search$ = Left$(name$,rindex-1)
  59.         If printfg=1 Then Print search$
  60.        
  61. ; Get "" pos in string
  62.         index = Instr(m$,search$)
  63.         If printfg=1 Then Print "Endpath = "+index
  64.         endpos = index
  65.        
  66. ; Work backwards from pos to get drive
  67.         i = index
  68.         While i > 0
  69.                 i = i - 1
  70.                 char$ = Mid$(m$,i,1)
  71.                 If char$ = ":"
  72.                         startpos = i-1
  73.                         i = 0
  74.                 EndIf
  75.         Wend
  76.         If printfg=1 Then Print "Startpath = "+startpos
  77.        
  78. ; Get full path and add original search$
  79.         length = endpos - startpos
  80.         path$ = Mid$(m$,startpos,length)
  81.         If printfg=1 Then Print path+search$
  82.        
  83.         Return path+search$
  84. End Function
  85.  
  86. ;---------------------------------
  87. Function JRinstr(txt$, separator$)
  88. ;---------------------------------
  89.         Local retval = 0, z
  90.        
  91.         For z = Len(txt$) To 1 Step -1
  92.                 If Mid$(txt$,z,1) = separator$
  93.                         retval = z
  94.                         z = 0
  95.                 EndIf
  96.         Next
  97.        
  98.         Return retval
  99. End Function
  100.  
  101. ;-----------------------------------------------
  102. ;-----------------------------------------------


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal