ksmith247 Posted August 25, 2009 Posted August 25, 2009 This is will be part of a larger script which will recursively search through directories and delete shortcuts pointing to a particular target. I do not know in which folder the shortcuts may be located (hence the recursive search) nor what they may be named (reason behind using the target path). I haven't begun to tackle the search part but am trying to get the piece to find the shortcut working. I keep getting the error: ==> Subscript used with non-Array variable.: If $aLinkInfo[0] = "C:\Program Files (x86)\CDBurnerXP\cdbxpp.exe" Then If $aLinkInfo^ ERROR I have tried several variations but can't seem to hit on the right one. Can someone please point me in teh right direction? -Thanks. #include <array.au3> #include <file.au3> $aLinkList = _FileListToArray(@DesktopCommonDir, "*.lnk") For $link In $aLinkList $aLinkInfo = FileGetShortcut($link) If $aLinkInfo[0] = "C:\Program Files (x86)\CDBurnerXP\cdbxpp.exe" Then MsgBox(0, "", "Yes") Else MsgBox(0, "", "No") EndIf Next Support bacteria; it's the only culture most people have.LxP's Learning to Script with AutoIt 3 - Excellent starting placeVolly's Links Page - Links to cool and useful scriptsAutoIt Wrappers - Valuater's AutoIt Wrappers post. Lots of good stuff.Support AutoIt - Make a donation here; I did.[size="2"]#include <Guinness.pint>[/size]
99ojo Posted August 25, 2009 Posted August 25, 2009 This is will be part of a larger script which will recursively search through directories and delete shortcuts pointing to a particular target. I do not know in which folder the shortcuts may be located (hence the recursive search) nor what they may be named (reason behind using the target path). I haven't begun to tackle the search part but am trying to get the piece to find the shortcut working. I keep getting the error: ==> Subscript used with non-Array variable.: If $aLinkInfo[0] = "C:\Program Files (x86)\CDBurnerXP\cdbxpp.exe" Then If $aLinkInfo^ ERROR I have tried several variations but can't seem to hit on the right one. Can someone please point me in teh right direction? -Thanks. #include <array.au3> #include <file.au3> $aLinkList = _FileListToArray(@DesktopCommonDir, "*.lnk") For $link In $aLinkList $aLinkInfo = FileGetShortcut($link) If $aLinkInfo[0] = "C:\Program Files (x86)\CDBurnerXP\cdbxpp.exe" Then MsgBox(0, "", "Yes") Else MsgBox(0, "", "No") EndIf Next Hi, try this: #include <array.au3> #include <file.au3> $aLinkList = _FileListToArray(@DesktopCommonDir, "*.lnk") For $i = 1 To UBound ($aLinkList) - 1 $aLinkInfo = FileGetShortcut(@DesktopCommonDir & "\" & $aLinkList [$i]) If $aLinkInfo[0] = "C:\Program Files (x86)\CDBurnerXP\cdbxpp.exe" Then MsgBox(0, "", "Yes") Else MsgBox(0, "", "No") EndIf Next ;-)) Stefan
jvanegmond Posted August 25, 2009 Posted August 25, 2009 It is possible that FileGetShortcut fails and returns something not defined in the documentation (probably not an array, more likely number 0 or empty string). In this case it sets the @error flag to 1, you can check for this like so: #include <array.au3> #include <file.au3> $aLinkList = _FileListToArray(@DesktopCommonDir, "*.lnk") For $link In $aLinkList $aLinkInfo = FileGetShortcut($link) If Not @error Then If $aLinkInfo[0] = "C:\Program Files (x86)\CDBurnerXP\cdbxpp.exe" Then MsgBox(0, "", "Yes") Else MsgBox(0, "", "No") EndIf EndIf Next You have a very nice style of coding. Compliments. : ) github.com/jvanegmond
99ojo Posted August 25, 2009 Posted August 25, 2009 (edited) It is possible that FileGetShortcut fails and returns something not defined in the documentation (probably not an array, more likely number 0 or empty string). In this case it sets the @error flag to 1, you can check for this like so: #include <array.au3> #include <file.au3> $aLinkList = _FileListToArray(@DesktopCommonDir, "*.lnk") For $link In $aLinkList $aLinkInfo = FileGetShortcut($link) If Not @error Then If $aLinkInfo[0] = "C:\Program Files (x86)\CDBurnerXP\cdbxpp.exe" Then MsgBox(0, "", "Yes") Else MsgBox(0, "", "No") EndIf EndIf Next You have a very nice style of coding. Compliments. : ) Hi, the first $link is the number of files returned by _FileListToArray. So his FileGetShortname doesn't return an array. ==> Subscript used with non-Array variable Also he need for FileGetShortCut the full path to lnk file. His _FileListToArray only returns filenames. ==> Subscript used with non-Array variable -> New For Loop if he wants to use For ... In construction: For $link In $aLinkList $aLinkInfo = FileGetShortcut(@DesktopCommonDir & "\" & $link) If IsArray ($aLinkInfo) Then If $aLinkInfo[0] = "C:\Program Files (x86)\CDBurnerXP\cdbxpp.exe" Then MsgBox(0, "", "Yes") Else MsgBox(0, "", "No") EndIf EndIf Next ;-)) Stefan Edited August 25, 2009 by 99ojo
jvanegmond Posted August 25, 2009 Posted August 25, 2009 You're probably right, Stefan. I didn't analyze the full script, only cause and effect of the original problem and tried to repair that (I.E. the script I posted does not stop with array error anymore). github.com/jvanegmond
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now