|
#1
|
|||
|
|||
Odd error trying to get a directory.
Hi.
I am having a strange issue. When I use the following extremely basic code snippet, the return sometimes works properly, and other times I get a completely different outcome. ... platformType is passed to the function Code:
Dim p, ppfile, ppfso, ppcmd, ppShell, ppPath ' Create the full path to the command file Set ppShell = CreateObject("Wscript.Shell") ppPath = ppShell.CurrentDirectory ppfile = ppPath & "\" & platformType & ".pp" ' Message box for Debugging Only msgbox ppfile 'Open the command file Set ppfso = CreateObject("Scripting.FileSystemObject") Set p = ppfso.OpenTextFile(ppfile, ForReading) ... c:\users\donnie\scripts and then construct the full filename which is supposed to be something like "c:\users\donnie\scripts\9k.pp" Sometimes it works properly, and most other times I get "c:\windows\system32\9k.pp" as the returned path instead, which of course leads to a File not Found. Thanks, Donnie Last edited by cboyack; 04-15-2021 at 02:40 PM. Reason: Please use [CODE] and [/CODE] tags to denote areas of code |
#2
|
|||
|
|||
Quote:
Please see this forum post for options that may alleviate this problem. For fun, you may want to try running the script code listed there as well, just to see how easily the current directory can change depending on context.
__________________
Thanks, --Cameron VanDyke Software Technical Support support@vandyke.com (505) 332-5730 |
#3
|
|||
|
|||
crt.ScriptFullName
I see this returns the full filename but how would I chop the script name off of the end in order to end up with just the full path?
Thanks |
#4
|
|||
|
|||
First off, I'll copy the script from the other post just so anyone else viewing can see what we're discussing:
Code:
# $language = "Python" # $interface = "1.0" import os strDir1 = os.getcwd() strDir2 = os.path.dirname(os.path.realpath(".")) strDir3 = os.path.dirname(os.path.realpath(__file__)) strDir4 = os.path.dirname(crt.ScriptFullName) crt.Dialog.MessageBox("dir1: {}\ndir2: {}\ndir3: {}\ndir4: {}".format( strDir1, strDir2, strDir3, strDir4)) I would have expected that something like: Code:
ppPath = os.path.dirname(crt.ScriptFullName) What changes have you made to the script?
__________________
Thanks, --Cameron VanDyke Software Technical Support support@vandyke.com (505) 332-5730 |
#5
|
|||
|
|||
That would be in Python.
I am using VBScript... I found the answer. Code:
Set ppShell = CreateObject("Scripting.FileSystemObject") ppPath = ppShell.GetParentFolderName(crt.ScriptFullName) ppFile = ppPath & "\" & platformType & ".pp" Donnie Last edited by dsp00k; 04-21-2021 at 11:56 PM. |
#6
|
|||
|
|||
Hi Donnie,
I apologize for not catching that from your initial message. Should've been clear since you were using Wscript... Anyways, I'm glad that you were able to discover a solution to obtain the containing folder's path in VBScript.
__________________
Thanks, --Cameron VanDyke Software Technical Support support@vandyke.com (505) 332-5730 |
![]() |
Thread Tools | |
Display Modes | Rate This Thread |
|
|