# How to navigate around a thumb drive?

## Recommended Posts

I've had great help in using the MACRO REFERENCE that I found over the weekend. Lots of @...Dir there that help a lot.

However, those all relate to the host computer. Is there an easy way yet as fool-proof a way to launch something on our flash drive without using absolute paths? If the item is in the AutoIt folder or a subfolder, it's an easy thing to use @ScriptDir. But what can we use when it's something _outside_ this folder elsewhere on the drive?

Thanks.

##### Share on other sites

Just use this:

$dir = 'E:\some path\' If FileExists($dir & 'subdir\my file.txt') then ...

##### Share on other sites

Just use this:

$dir = 'E:\some path\' If FileExists($dir & 'subdir\my file.txt') then ...
Hi, thanks! I think I missed something. All that looks like absolute paths to me <lol>. Any way to make them all relative, like what @SriptDir does for anything within the AI folder or subfolders, but for the rest of the thumb drive?

Yes, it's easy to use absolute paths, but not easy re relative ones until one knows the syntax (if any) <g>. I'm trying to avoid drive letters since they're a pain in the butt re the thumb drives. These keep changing depending on the host computer you're on. And a stint here where I was at different desks twice a week for 3 weeks (hence different computers) really made life difficult in this regard. For everything running off the launcher, great, since it just automatically has everything set for relative paths, but nothing else!

Thanks.

Edited by Diana (Cda)

##### Share on other sites

Hi, maybe look for a removable drive, since most usb thumb drives show as Removable, just exclude a:\ and b:\ drives as these are usually reserved for floppy drives (which are shown as removable as well) example:

$PathToFile = "\PathToYourFile\YourFile.ext"$FindIt = _FindFilePath($PathToFile) If$FindIt <> "" Then MsgBox(0, "Found Path to file", "Path to file:" & @LF & $FindIt) If$FindIt = "" Then MsgBox(0, "No Path to file found", "Couldn't find your file")

Func _FindFilePath($iPath) Local$Drv = DriveGetDrive("REMOVABLE")
If Not @error Then
For $i = 1 To$Drv[0]
If $Drv[$i] <> "a:" And $Drv[$i] <> "b:" And FileExists($Drv[$i] & $iPath) Then Return$Drv[$i] &$iPath
Next
EndIf
Return ""
EndFunc

Cheers

Edited by smashly

##### Share on other sites

Hi, maybe look for a removable drive, since most usb thumb drives show as Removable, just exclude a:\ and b:\ drives as these are usually reserved for floppy drives (which are shown as removable as well) example:
;set this to the path your looking for (without the drive letter of coarse)
$PathToFile = "\PathToYourFile\YourFile.ext" _FindFilePath($PathToFile)

Func _FindFilePath($iPath) Local$Drv = DriveGetDrive("REMOVABLE")
If Not @error Then
For $i = 1 To$Drv[0]
If $Drv[$i] <> "a:" And $Drv[$i] <> "b:" And FileExists($Drv[$i] & $iPath) Then MsgBox(0, "Found Path to file", "Path to file:" & @LF &$Drv[$i] &$iPath)
Return 1
EndIf
Next
MsgBox(0, "No Path to file found", "Couldn't find your file")
Return 0
EndIf
EndFuncoÝ÷ Ûú®¢×¢·rÝÉ»­¶¬$±Ê&¦Xj×¦Â¢IèÃ^­ëayø¥z+(}Ê.®Ç­ ¦j§z«¨¶Z()à~ßWªºfy©ì²¶§élz«x-êÞaxjÈ®ØZØb±h­©ò¶§)íà.-~]+²æß¢W^­©eÛZë"²Øb²Ø§ÊØb®*m*È²Ø^­éè¶§È¦V«Áçë¶âÛayÚâ½ê'¶­éjwméðyÆ§ºÇ­«ZàÂ+aë-jÈ¦¦W©jØm¢Ø^­ë-¡ûayø¥yhZ´²)x¢¼²Ê&zØb¬y«2jËaÆ®¶­se6VÆÄWV7WFR÷'F&ÆTG&fRf×²gV÷C²b3#´2b3#´äõDUBb3#¶çBÂÖWFBc2ãSb3#´ÒÖWFBc2ãSb3#´ÖWFBæWRgV÷C²oÝ÷ Ú)ìµæ¡ûaÆ®¶­se6VÆÄWV7WFRgV÷C´S¢b3#´2b3#´äõDUBb3#¶çBÂÖWFBc2ãSb3#´ÒÖWFBc2ãSb3#´ÖWFBæWRgV÷C² Nothing doing?? If I use anything like the huge finding script above, my scripts are going to get so very huge and clunky! #### Share this post ##### Link to post ##### Share on other sites Well how would the @PortableDrive macro work without first finding the file first? No there's no short way that your after that I can see$FindIt = _FindFilePath("\APPS\NOTEPAD\npad\Metapad v3.51\APP- Metapad v3.51\Metapad.exe")
If $FindIt <> "" Then ShellExecute($FindIt)

Func _FindFilePath($iPath) Local$Drv = DriveGetDrive("REMOVABLE")
If Not @error Then
For $i = 1 To$Drv[0]
If $Drv[$i] <> "a:" And $Drv[$i] <> "b:" And FileExists($Drv[$i] & $iPath) Then Return$Drv[$i] &$iPath
Next
EndIf
Return ""
EndFunc

##### Share on other sites

You could open a file open dialog and ask the user where the portable file folder is...

##### Share on other sites

Lordy, lordy but this looks complicated. p.s., I _do_ know where the file is, of course, though I imagine, "looking for file" means something else here (??). Is there nothing easier than this??

Nothing doing??

If I use anything like the huge finding script above, my scripts are going to get so very huge and clunky!

How rediculous... 9 lines of code looks difficult? Pfft

If it were an internal function... how many lines would you think it to be?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

##### Share on other sites

Well how would the @PortableDrive macro work without first finding the file first?

Obviously, something like @PortableDrive would work by itself. A bit simplistic, but I was just using that as an example.

No there's no short way that your after that I can see

$FindIt = _FindFilePath("\APPS\NOTEPAD\npad\Metapad v3.51\APP- Metapad v3.51\Metapad.exe") If$FindIt <> "" Then ShellExecute($FindIt) Func _FindFilePath($iPath)
Local $Drv = DriveGetDrive("REMOVABLE") If Not @error Then For$i = 1 To $Drv[0] If$Drv[$i] <> "a:" And$Drv[$i] <> "b:" And FileExists($Drv[$i] &$iPath) Then Return $Drv[$i] & $iPath Next EndIf Return "" EndFunc Why would it need to go through such a convoluted process? So many things work well out of @ScriptDir. Perhaps that might be a way. Can we say travel up from @ScriptDir to the root folder where script located and then travel to say, \APPS\NOTEPAD\npad\Metapad v3.51\APP- Metapad v3.51\Metapad.exe? Then there wouldn't be any of this finding stuff happening. The script would know exactly where to go. Thanks. #### Share this post ##### Link to post ##### Share on other sites If you do$file = @scriptdir & "\..\[Insert your file path here]"

Every "\..\" is like pressign the UP button on Explorer, or typing "cd .." into a command prompt.

for example,

the file you want to launch is "F:\DIR1\File.exe"

You have another one at "F:\DIR1\DIR2\File2.exe"

to launch File.exe you would do this:

ShellExecute(@ScriptDir & "\..\..\File.exe")

for File2.exe it would be

ShellExecute(@ScriptDir & "\..\File2.exe")

If you want it simpler than that I am sorry, but you really don't deserve to be scripting.

Edited by koresho

##### Share on other sites

So many things work well out of @ScriptDir. Perhaps that might be a way. Can we say travel up from @ScriptDir to the root folder where script located and then travel to say, \APPS\NOTEPAD\npad\Metapad v3.51\APP- Metapad v3.51\Metapad.exe? Then there wouldn't be any of this finding stuff happening. The script would know exactly where to go.

$PortableDrive = StringLeft(@ScriptDir, 2) MsgBox(0, "Notice",$PortableDrive & "\APPS\NOTEPAD\npad\Metapad v3.51\APP- Metapad v3.51\Metapad.exe")

If you do

ShellExecute($PortableDrive & "\ClearFrequently\Daily- EDITOONS")oÝ÷ Ú«¨µéÚ #### Share this post ##### Link to post ##### Share on other sites$PortableDrive = StringLeft(@ScriptDir, 2)
ShellExecute(\$PortableDrive & "\ClearFrequently\Daily- EDITOONS")
Thanks. I must have done something wrong initially because "2" didn't work so I tried with "1" and it did work at that time. As these things happen, must have been a fluke.

BUT THIS WORKS JUST GREAT so far! This is exactly the sort of solution needed. Something simple and straightforward.

I believe that I now have all the components necessary for replacing Outlook as my reminder system using a USB flash drive with all _relative_ paths. I have tried so many things but PowerPro running AutoIt scripts has been the best thing so far for the thumb drive. So far, so good re launching and running _anything_ on the thumb drive no matter where it is and never using absolute paths (which is a no-no when using a pen drive as each computer can assign a very different drive letter to the drive).

Thanks!

## Create an account

Register a new account

×

• Wiki

• Back

• Git