Jump to content

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. :)

Link to comment
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)
Link to comment
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
Link to comment
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! :)

Link to comment
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
Link to comment
Share on other sites

  • Moderators

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.

Link to comment
Share on other sites

  • 4 weeks later...

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. <_<

Link to comment
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,

your @ScriptFullPath is "F:\DIR1\DIR2\Documents\ScriptName.exe"

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
Link to comment
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")
Link to comment
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,

your @ScriptFullPath is "F:\DIR1\DIR2\Documents\ScriptName.exe"

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.
(That last comment is being rather harsh ... ! <g>)

Hi, guys. Sorry for delay. Bunch of things and RL getting in the way of everything. Still trying to resolve this, though.

Here's the deal, I'm using PowerPro now since I re-discovered it (a launching button program that is highly different from AutoIt but runs along the same lines, highly customizable) and I've found something that might help describe what I'm trying to do. This isn't a question of "deserving" or not to be scripting. That's just plain ridiculous. It's trying to achieve the most straightforward, efficient way of doing things. And 9 lines of code that I can't understand isn't straightforward to me.

PowerPro's code below isn't simple either, not as it could be, but it's straightforward enough and understandable after a fashion (and _simple_!).

Here's the neat thing ... if something to be launched resides in the PowerPro folder or off of it (i.e., like a @ScriptDir type of thing), then one uses "do(pprofolder++". I launch many AI scripts out of a REMINDERS folder in the PowerPro one. So, this works like @ScriptDir, and the name of the AI script is called "EMAILS TO FAMILY (w-delay).au3":

do(pprofolder++"/REMINDERS/EMAILS TO FAMILY (w-delay).au3")

HOWEVER, for other items nowhere near the PowerPro folder yet that still reside on the same drive (the USB flash drive) as PowerPro, can be easily launched via another similar line of code which is "do(disk++?". This also makes for relative paths yet something completely away from the main PPro folder can be a launched. The AI script here is called "APP- Time Worked Calculator- open this folder (w-delay).au3":

do(disk++?":\APPS\TIMER-WORK\TimeWorked Calculator\APP- Time Worked Calculator- open this folder (w-delay).au3")

I'm finding that I need that same sort of flexibility within an AI solution to relative paths and launching outside the script folder. The trouble with the "F:\DIR1\File.exe" and "F:\DIR1\DIR2\File2.exe" with \..\ and cd .. solution above is that they both must reside along the _same_ folder path, something that isn't always the case.

E:\APPS\TIMER-WORK\TimeWorked Calculator\APP- Time Worked Calculator- open this folder (w-delay).au3
doesn't reside on the same folder path at all as
E:\APPS\bar, PowerPro v4.7\APP- PowerPro v4.7\REMINDERS\EMAILS TO FAMILY (w-delay).au3

In this example, @ScriptDir works great for anything within the same folder path as where the script is located, but what to do about what isn't? Is there nothing we can use to emulate when comparing PowerPro's "do(pprofolder++" that eliminates the need for a drive letter, hence making the script workable on relative paths _ANYWHERE_ in the same drive as the USB flash drive?? Is there no similar AI solution?

Edited by Diana (Cda)
Link to comment
Share on other sites

$PortableDrive = StringLeft(@ScriptDir, 2)
MsgBox(0, "Notice", $PortableDrive & "\APPS\NOTEPAD\npad\Metapad v3.51\APP- Metapad v3.51\Metapad.exe")
I get the error: "Windows cannot find 'P\ClearFrequently\Daily- EDITOONS'. Make sure you typed the name correctly, and then try again. To search for a file, click the Start button, and then click Search."

Despite the location being far away from the @ScriptDir, it is correct except for the missing ":". The actual path is this: "P:\ClearFrequently\Daily- EDITOONS". Why is the script missing out on the colon? Is there a way to fix this?

Thanks! <_<

Link to comment
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! <_<

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...