Jump to content

@ScriptDir?


Recommended Posts

<banging head against wall>Okay, best to come for help yet again because I'm going around in circles. Have searched for @SriptDir messages on this forum, looked through the help file and googled for this and AI together but keep getting highly complex code that I can't make heads or tails of re @ScriptDir. Intellectually, I understand what the purpose is, I can't seem to wrap my brain around modifying code for what I need. My needs are always so much simpler ... <g>

How would @ScriptDir be used in these 2 different cases:

Case 1)

SoundPlay ("..\WAVS\ETHTECHN21_SS01.WAV")

where the absolute path would be this path below on this particular computer:

E:\APPS\APPS unzipped\AutoIt\APP- AutoIt v3.2.5.0- Scripts\WAVS\ETHTECHN21_SS01.WAV

Case 2)

ShellExecute("E:\WORKINGdirs\WorkDir- EXCEL\TIME LOGGER for WORK.xls")

where the script that has the above code is located at this path below on this computer:

E:\APPS\APPS unzipped\AutoIt\APP- AutoIt v3.2.5.0- Scripts\LaunchFile(s)- XL2K, Time Logger for Work.au3

Thanks much! Appreciate the help. :whistle:

Link to comment
Share on other sites

1. ScriptDir cannot be used here unless you have a certainty of the length of the folder that the script was in. So if the script was in E:\APPS\APPS unzipped\AutoIt\APP - AutoIt v3.2.5.0 - Scripts\SomeFolder, you could trim 10 letters off that and then use it like this:

$dirpart1 = StringTrimRight(@ScriptDir, 10)
SoundPlay($dirpart1 & "WAVS\ETHTECHN21_SS01.WAV")

2. It isn't really possible to use @ScriptDir here, you're best off just moving the spreadsheet into the same folder as the script and referencing it from there.

Unless you are planning to distribute this script, it will be much easier just to reference the absolute paths of the files rather than doing all this extra work. Otherwise, if you are going to have these files referenced, you probably should have them all in the same folder when you're developing the script anyway.

Edited by sandman

[center]"Yes, [our app] runs on Windows as well as Linux, but if you had a Picasso painting, would you put it in the bathroom?" -BitchX.com (IRC client)"I would change the world, but they won't give me the source code." -Unknownsite . blog . portfolio . claimidcode.is.poetry();[/center]

Link to comment
Share on other sites

  • Developers

@scriptdir will contain the path of the directory so in:

Case1: assuming the script is located in : E:\APPS\APPS unzipped\AutoIt\APP- AutoIt v3.2.5.0- Scripts

SoundPlay (@scriptdir & "\WAVS\ETHTECHN21_SS01.WAV")

Case2: Don't see how you can use @scriptdir here since the path you point to is located in another directory tree on the disk.

:whistle:

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Case 1)

SoundPlay ("..\WAVS\ETHTECHN21_SS01.WAV")

where the absolute path would be this path below on this particular computer:

E:\APPS\APPS unzipped\AutoIt\APP- AutoIt v3.2.5.0- Scripts\WAVS\ETHTECHN21_SS01.WAV

SoundPlay(@ScriptDir & "\WAVS\ETHTECHN21_SS01.WAV")oÝ÷ Ú«¨µéÚ
IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font]
Link to comment
Share on other sites

<banging head against wall>Okay, best to come for help yet again because I'm going around in circles. Have searched for @SriptDir messages on this forum, looked through the help file and googled for this and AI together but keep getting highly complex code that I can't make heads or tails of re @ScriptDir. Intellectually, I understand what the purpose is, I can't seem to wrap my brain around modifying code for what I need. My needs are always so much simpler ... <g>

How would @ScriptDir be used in these 2 different cases:

Case 1)

SoundPlay ("..\WAVS\ETHTECHN21_SS01.WAV")

where the absolute path would be this path below on this particular computer:

E:\APPS\APPS unzipped\AutoIt\APP- AutoIt v3.2.5.0- Scripts\WAVS\ETHTECHN21_SS01.WAV

Case 2)

ShellExecute("E:\WORKINGdirs\WorkDir- EXCEL\TIME LOGGER for WORK.xls")

where the script that has the above code is located at this path below on this computer:

E:\APPS\APPS unzipped\AutoIt\APP- AutoIt v3.2.5.0- Scripts\LaunchFile(s)- XL2K, Time Logger for Work.au3

Thanks much! Appreciate the help. :lmao:

If you have the absolute paths of the files anyway, what's the point of using the @ScriptDir macro at all? Just edit that SoundPlay() function with the full path, or better yet, put the path in a variable first, then use that:

$sWavPath = "E:\APPS\APPS unzipped\AutoIt\APP- AutoIt v3.2.5.0-  Scripts\WAVS\ETHTECHN21_SS01.WAV"
SoundPlay($sWavPath)

$sXlsPath = "E:\WORKINGdirs\WorkDir- EXCEL\TIME LOGGER for WORK.xls"
ShellExecute($sXlsPath)

Where does any need for @ScriptDir come from?

:whistle:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

If you have the absolute paths of the files anyway, what's the point of using the @ScriptDir macro at all? Just edit that SoundPlay() function with the full path, or better yet, put the path in a variable first, then use that:

; ...oÝ÷ Ùh^­çhzƧÊwuú+IÊâ¦Ðâ­Ê&yúèé캷¿ªê-x"ZÞ«^¶aÀ ­ç²+÷Þ­éív¸¯zÚ-ë®*m²®*m*â²j+zåzË.±é^²Ëhµëayú%uêì¢z-êÝ®+Þ°éåÉÈZ¨}Ê'²'^­«b¢x¬v¸¯zW­µêÜjw!jx²j·!x¢»ayú%uêä'wk÷«¢jvÞvÞ¶Þ²oz'âµìb²Û(©è¶«v¸¯zW­µêâË^iÒ.±ähn¨§*''åjÈ]®+Þ¶©u«^iÇ«µ¨§~]z¶§v+'¢×k÷z§u©í~î¥Ö­xW¬¢v§¢Ø^¬ð¬¢Z'«,z×(Ø­Ú­é¶)ë¢h}Úâ½ê+{ayK®ÀèréÛ%¡Æ­Ó+"²Ø^±Êâ¦Ò.±æ§v+]¡ë,yªÜÚ.¥Ö­yúèØ^v¸¯y:-çk÷¢±ø±yÖ¬¥©pk&Þ
«"¶+Úwij»b¶*'¢{az̬µé6®¶­sd÷Bb33µ'VäW'&÷'4fFÂb33²Â ¤bæ÷BfÆT6ævTF"67&DF"fײb33²b3#²ââb3#²b33²FVà ôW'&÷"b33´6÷VÆBæ÷B6ævRv÷&¶ærF&V7F÷'b33² WB¤VæD` ¤vÆö&Â6öç7Bb33c´EU2Ò`¤vÆö&Âb33c¶æEöF ¤vÆö&Âb33c·6÷W&6RÒv÷&¶ætF"fײb33²b3#µ6ögGv&RFWÆ÷ÖVçBb33° ¤bfÆTW7G2b33´C¢b3#µ&ö¦V7G2b3#µ6ögGv&RFWÆ÷ÖVçBb33²æBfÆTW7G2b33²âb3#µ6ögGv&RFWÆ÷ÖVçBb33²FVà ²WFFRFRfÆ6G&fRg&öÒFR6÷W&6RföÆFW  b×6t&÷C#BÂb33µ7æ6&öæ¦Rb33²Âb33µ6÷W&6S¢b33²fײD"fײD"fײb33²gV÷C´C¢b3#µ&ö¦V7G2b3#µ6ögGv&RFWÆ÷ÖVçBgV÷C²b33²fײ5$Äbfײð b33´FW7FæFöã¢b33²fײD"fײb33²gV÷C²b33²fײb33c·6÷W&6Rfײb33²gV÷C²b33²Òb33c´EU2FVà õ&ö&ö6÷b33´C¢b3#µ&ö¦V7G2b3#µ6ögGv&RFWÆ÷ÖVçBb33²Âb33c·6÷W&6R VæD`¤VÇ6P ²6V6²b6÷W&6RföÆFW"W7G0 bæ÷BfÆTW7G2b33c·6÷W&6RFVà ôW'&÷"b33c·6÷W&6Rfײb33²æ÷Bf÷VæBb33² WB VæD` ²Æö6FRFW7FæFöâföÆFW"bBÇ&VGW7G0 b33c¶G&fRÒG&fTvWDG&fRb33´dTBb33² bæ÷BW'&÷"FVà f÷"b33c¶ÒFòT&÷VæBb33c¶G&fRÓ bfÆTW7G2b33c¶G&fU²b33c¶Òfײb33²b3#µ6ögGv&RFWÆ÷ÖVçBb33²FVà b33c¶æEöF"Òb33c¶G&fU²b33c¶Òfײb33²b3#µ6ögGv&RFWÆ÷ÖVçBb33° WDÆö÷ VæD` æW@ VæD` ²Ç6ò6V6²Fö7VÖVçG2föÆFW"f÷"FW7FæFöâföÆFW"bæVVFV@ bæ÷Bb33c¶æEöF"æBfÆTW7G2×Fö7VÖVçG4F"fײb33²b3#µ6ögGv&RFWÆ÷ÖVçBb33²FVà b33c¶æEöF"Ò×Fö7VÖVçG4F"fײb33²b3#µ6ögGv&RFWÆ÷ÖVçBb33° VæD` ²6ö÷6RFW7FæFöâföÆFW  Fð b33c¶FW7FæFöâÒfÆU6VÆV7DföÆFW"b33´6ö÷6RFRgV÷Cµ6ögGv&RFWÆ÷ÖVçBgV÷C²föÆFW"öâ÷W"b33²fײð b33´DBFò7æ6&öæ¦RvFFR6÷öâFRfÆ6G&fRâb33²fײ5$Äbfײð b33µFR&ö÷BöbfVBDB27G&öævÇ&V6öÖÖVæFVBâb33²Âb33²b33²Â2Âb33c¶æEöF" bW'&÷"FVâW@ 6ÆVWS VçFÂb33c¶FW7FæFöâfÇC²fwC²b33²b33²æBfÆTW7G2b33c¶FW7FæFöâ ²6V6²bFRG&fRÆWGFW"2FRfÆ6G&fP b7G&ætÆVgB67&DF"ÂÒ7G&ætÆVgBb33c¶FW7FæFöâÂFVà ôW'&÷"b33´æ÷BÆÆ÷vVBFò6÷FòFRfÆ6G&fRb33² WB VæD` ²'Vâ&ö&ö6÷ò¢æWP bF$7&VFRb33c¶FW7FæFöâFVà õ&ö&ö6÷b33c·6÷W&6RÂb33c¶FW7FæFöâ VÇ6P ôW'&÷"b33´77VR7&VFærF&V7F÷'¢b33²fײ5$Äbfײb33c¶FW7FæFöâ VæD`¤VæD` ¤W@ ¤gVæ2õ&ö&ö6÷b33c·6÷W&6RÂb33c¶FW7FæFöâ Æö6Âb33c¶6öÖÖæBÂb33c¶FFÂb33c·@ bõ5fW'6öâÒb33µtåõd5Db33²FVà b33c·&ö&ö6÷Ò67&DF"fײb33²b3#´b3#µ&ö&ö6÷õf7FæWRb33° VÇ6P b33c·&ö&ö6÷Ò67&DF"fײb33²b3#´b3#µ&ö&ö6÷õæWRb33° VæD` ÷Bb33µG&6öäFRb33²ÂfÇ6R '&V²fÇ6R bfÆTW7G2b33c·&ö&ö6÷FVà 7Æ6FWDöâb33µ7æ6&öæ¦Rb33²Âb33µÆV6RvBâââb33²Â3ÂÂFVfVÇBÂFVfVÇBÂ3" b33c¶6öÖÖæBÒb33²gV÷C²b33²fײb33c·&ö&ö6÷fײb33²gV÷C²gV÷C²b33²fײb33c·6÷W&6Rfײb33²gV÷C²gV÷C²b33²fײb33c¶FW7FæFöâfײb33²gV÷C²¢â¢ôÔ"b33° b33c·BÒ'Vâb33c¶6öÖÖæBÂb33²b33²Â5uôDRÂB bW'&÷"FVà Fð b33c¶FFf׳Ò7FDW'%&VBb33c·B VçFÂW'&÷  bb33c¶FFFVà ôW'&÷"b33µ7FDW'#¢b33²fײ5$Äbfײb33c¶FF VæD` &ö6W75vD6Æ÷6Rb33c·B ôW'&÷"b33´6öÖÖæBfÇW&S¢b33²fײ5$Äbfײb33µF¢b33²fײb33c¶6öÖÖæBfײ5$Äbfײb33µv÷&¶ætF#¢gV÷C²b33²fײv÷&¶ætF"fײb33²gV÷C²b33² WB VæD` &ö6W75vD6Æ÷6Rb33c·B ÷Bb33µG&6öäFRb33²ÂG'VR VÇ6P ôW'&÷"b33´Ö76ærfÆRFò'Vã¢b33²fײ5$Äbfײb33c·&ö&ö6÷ WB VæD` 7Æ6öfb 6ÆVW ×6t&÷CÂb33µ7æ6&öæ¦Rb33²Âb33´6ö×ÆWFRb33²Â¤VæDgVæ0 ¤gVæ2ôW'&÷"b33c·FWB ²ÆörW'&÷'0 Æö6Âb33c¶ÆörÒ67&DF"fײb33²b3#´FFb3#´W'&÷"æÆörb33° fÆUw&FTÆæRb33c¶ÆörÂb33´FFS¢b33²fײÔDfײb33²òb33²fײÔôâfײb33²òb33²fײT" fÆUw&FTÆæRb33c¶ÆörÂb33µW6W#¢b33²fײW6W$æÖR fÆUw&FTÆæRb33c¶ÆörÂb33´W'&÷#¢b33²fײ7G&æu&WÆ6Rb33c·FWBÂ5$ÄbÂb33²b33² ×6t&÷C3Âb33µ7æ6&öæ¦Rb33²Âb33c·FWB¤VæDgVæ0

It shows how to get the drive letter of the flash drive.

It show how to locate on another drive.

It shows some use of using working directory to use relative paths.

It shows that RoboCopy is OS dependant so you do not waste time debugging the fault as I had to do.

:whistle:

Link to comment
Share on other sites

If you have the absolute paths of the files anyway, what's the point of using the @ScriptDir macro at all? Just edit that SoundPlay() function with the full path, or better yet, put the path in a variable first, then use that:

$sWavPath = "E:\APPS\APPS unzipped\AutoIt\APP- AutoIt v3.2.5.0-  Scripts\WAVS\ETHTECHN21_SS01.WAV"
SoundPlay($sWavPath)

$sXlsPath = "E:\WORKINGdirs\WorkDir- EXCEL\TIME LOGGER for WORK.xls"
ShellExecute($sXlsPath)

Where does any need for @ScriptDir come from?

:whistle:

Hi! I'm guessing you've never used a memory stick, then!!! <g>.

The problem with absolute paths lies in the Windows weakness that makes it dependent on drive letters. Unfortunately, USB flash drives get assigned a different letter from computer to computer. Of the 3 ports available on my home computer, the one I plug my USB stick into gets assigned the P drive. At work, it's the E drive. ALL the scripts that work at home stopped working once I got the office the first time I used the new stick because of this. Yet mimicking my USB stick's launcher way of referencing paths, which is truly portable (vs. just being a standalone), that way doesn't always work since it can change depending on the means to launch the file.

So using something like

SoundPlay ("..\Scripts\WAVs\Bladerunner.wav")

can fail in certain cases.

But using this syntax instead,

SoundPlay(@ScriptDir & "\WAVs\Bladerunner.wav")

works every time!

So in conclusion, @ScriptDir can be vital in making things work extremely reliably when using AI off of removable items such as a memory stick.

Hope that helps! :lmao:

(oh, p.s., I gave the full path to the XLS file initially just to show its location. I always had intention of eventually making it a relative path. But in this particular case, @ScriptDir wouldn't work due to the location of the file itself. Moving it from the Excel folder into the script folder fixed this problem as so because of @ScriptDir this will work reliably no matter which computer I use. Very important. [The final script now has a relative path rather than an absolute one as shown here.] Thanks!! <g>)

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

I will relate to this. Agree as is different drive to the script so @ScriptDir is more or less useless to locate the folders on other drives. Only change of consideration is drive letter can change so searching for the folder (known in drive root) can be done to resolve if it exists on another drive letter instead.

I use RoboCopy on my flash drive to update a certain folder and is not drive dependant for updating files on another PC so long as set condition are met (in root of drive or in the Users Documents location) ... [snip]

Thanks for this. Very cool.

I'm finding that moving the 2 files to the AI script folder was a workable solution. The backup app I use has the ability to easily pick and choose which file formats to deal with. So when performing back up of my AI scripts, that routine now excludes the Excel XLS files in that folder; yet when I'm backing up all the Excel files, I can add the path to the AutoIt scripts and just include the files with the XLS extension. That was the only thing that was going to be difficult by moving the files so that @ScriptDir would work.

I also updated the location of these files in my USB file launcher so, again, not a problem.

Because of these 2 things, the actual physical location of the files on the memory stick is practically irrelevant as I can use and launch them as needed now, anyway, after making these modifications.

Thanks for the neat code for RoboCopy. It's not needed here, fortunately, but there will be the odd case down the road where something like this will be very handy to have.

Cheers! :whistle:

Edited by Diana (Cda)
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...