Folder path verification

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
PepsiHog
Automation Wizard
Posts: 517
Joined: Wed Apr 08, 2009 4:19 pm
Location: Florida

Folder path verification

Post by PepsiHog » Thu Nov 25, 2021 1:19 pm

Happy Thanksgiving! Happy Holiday!

I am working on a macro that I have a browse button. It is for selecting a folder. After you finish your selections, you click OK. I want/need to verify the path of the folder exists. To that end, I searched the internet for a VBS routine. I found this one;

Code: Select all

VBSTART
function ShowParentFolderName(filespec)
   var fso, s = "";
   fso = new ActiveXObject("Scripting.FileSystemObject");
   s += fso.GetParentFolderName(filespec);
   return(s);
End Function
VBEND
Thing is.....it no work. So that's why I stopped in at this fine establishment today. Word out there is, you just ask for what you need here, and some mighty kind folks will help you out. Sounds like a pretty good place, if you ask me.

So I'm uh-asking. Will some kind, mighty friendly folk, please help me out and show me how to use this in MS? Also, I'm open for any suggestions(related to my quest).

Mighty appreciative,
PepsiHog
Windows 7

PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2024) AND enjoy programming. (That's my little piece of heaven!)

The immensity of the scope of possibilities within Macro Scheduler pushes the user beyond just macros!

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Folder path verification

Post by JRL » Tue Nov 30, 2021 4:29 pm

I could not make your found routine work so I wrote a new one. returns "1" if the folder exists and "0" if it does not

I have a question for you:
Why are you not using IfDirExists> which is native?

Code: Select all

VBSTART
function ShowParentFolderName(filespec)
   set fso = CreateObject("Scripting.FileSystemObject")
   filespec = fso.GetAbsolutePathname(filespec)
   ShowParentFolderName = 1
   if not fso.FolderExists(filespec) then
     ShowParentFolderName = 0
   end if
End Function
VBEND

Let>vPath=C:\windowsddert
VBEval>ShowParentFolderName("%vPath%"),res
MDL>res

Let>vPath=C:\windows
VBEval>ShowParentFolderName("%vPath%"),res
MDL>res

//Why not use this instead?
IfDirExists>vPath
  MDL>Folder "%vPath%" exists
Else
  MDL>Folder "%vPath%" does not exist
Endif

Let>vPath=C:\windowsddert
IfDirExists>vPath
  MDL>Folder "%vPath%" exists
Else
  MDL>Folder "%vPath%" does not exist
Endif

User avatar
PepsiHog
Automation Wizard
Posts: 517
Joined: Wed Apr 08, 2009 4:19 pm
Location: Florida

Re: Folder path verification

Post by PepsiHog » Wed Dec 01, 2021 6:39 pm

Hi, JRL,
That is a really good question. Is "I didn't think of using it" a really good answer? Here's the thing. I can't remember what macro this was for. I'm sure I will remember eventually. Maybe then I'll have a better answer for you.

Either way, thanks for the help,
PepsiHog
Windows 7

PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2024) AND enjoy programming. (That's my little piece of heaven!)

The immensity of the scope of possibilities within Macro Scheduler pushes the user beyond just macros!

User avatar
PepsiHog
Automation Wizard
Posts: 517
Joined: Wed Apr 08, 2009 4:19 pm
Location: Florida

Re: Folder path verification

Post by PepsiHog » Wed Dec 01, 2021 6:57 pm

Ok, I found the macro this was for. And the answer is......I didn't think of it.

You are a REALLY outgoing person. You knew I could just use IfDirExists, and still spent the time to write some vb script for me. That's pretty awesome. Thank you. Also, I did not know you knew vb, but I do now. Source noted.

PepsiHog
Windows 7

PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2024) AND enjoy programming. (That's my little piece of heaven!)

The immensity of the scope of possibilities within Macro Scheduler pushes the user beyond just macros!

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Folder path verification

Post by JRL » Wed Dec 01, 2021 10:43 pm

PepsiHog wrote:Also, I did not know you knew vb, but I do now. Source noted.
muy pequeño
Also, about as much Spanish as I know.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts