Using IfDirExists or other Dir functions on Shared Folders

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
winstein
Pro Scripter
Posts: 84
Joined: Mon Nov 26, 2012 3:44 pm

Using IfDirExists or other Dir functions on Shared Folders

Post by winstein » Mon Apr 03, 2017 10:22 am

When I tested the IfDirExists function on a shared folder path, like this:

Code: Select all

IfDirExists>\\192.168.1.0
    MessageModal>I can access this server
EndIf
It will return the True indicator, even though the directory doesn't exist for the user. Is there a way to determine of a certain shared folder directory is accessible?

Thanks for reading.
PPQ

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

Re: Using IfDirExists or other Dir functions on Shared Folde

Post by JRL » Mon Apr 03, 2017 1:15 pm

Let's start with, you're not checking for a folder you're testing an IP address which is similar to testing for a computer name. There needs to be a resource on the computer that you test for if you expect to test for the existence of a directory. Next, even if the resource can be seen by a user, that doesn't mean they have permissions set up to be able to read or write to the resource. A user that has no permissions of any kind for a particular resource will still be able to test for the existence of the resource if they know the name. If there is a file or folder within the resource and the use has no permissions to use the resource, the file or folder will not exist for them. They will not be able to see it.

That said: I have no computers or other devices with an IP address "192.168.1.0"", yet if I run your script I get a positive result. The message tells me I can access the server. So there is something amiss with the IfDirExists> function.

A little more testing shows that IfDirExists> will give a positive result for "\\" plus any text. For example, this script will test positive

Code: Select all

IfDirExists>\\nonexistentcomputername
    MessageModal>I can access this server
EndIf
Add a nonexistent folder and the test will fail:

Code: Select all

IfDirExists>\\nonexistentcomputername\Resource1
    MessageModal>I can access this server
EndIf


I would recommend you test a little deeper into the server. Something like:

Code: Select all

IfDirExists>\\192.168.1.0\MyResource\MyFolder
    MessageModal>I can access this server
EndIf
Or better yet, if everyone who has permissions to "see" the folder also has permissions to read/write, maybe use writeln> to write to and create a temporary file, check the WriteLn> result variable be be sure it is 0 (zero) and if it is 0 then the user has rights to the folder. Then delete the temp file.

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