Path issues with the DIR function

J

Jon Sherry

Hi all,
I'm working on a template installer that customizes a set of templates
and then installs them into the user's default template folder. I've
been getting the path with "ActiveDocument.Path" so that the installer
will work regardless of where it's located, or what platform.

Additionally, I want to use DIR to loop through the files in the
Install Templates folder, so that additional templates can be added to
the folder later without having to modify the program.

Thing is, I discovered that if I set the path explicity:

MyPath = "Macintosh HD:Users:jsherry:Desktop:Install:"

Dir correctly loops the correct number of times, and returns the names
of the files in the Install folder.

If I set the path this way:

MyPath = ActiveDocument.Path

the scope of Dir is narrowed, and the loop iterates once, returning
only the name of the ActiveDocument.

Is there some way out of this? If I have to specify a path, then I'll
need a different path for Mac and Windows, and maybe for OS9 and OSX,
as well.

I've only tested in Word v.X, 10.1.5, so far.

Thanks, so much
-jb
 
J

John McGhie [MVP - Word]

Hi Jon:

It's so long since I used DIR that I have forgotten how it's supposed to
work, but something in the back of my mind tells me that you set the path by
calling it once specifying a path, then call it without specifying a path
after that to have it return the next item in the list each time.

I seem to also remember that on the PC, the DIR command sets the Active
Path, whereas on the Mac it does not.

However, I am wondering why you would not return the path you are seeking
directly with Application.NormalTemplate.Path... Or even
Application.StartupPath

Putting your files in a folder of the correct name is not going to guarantee
success: you need to query Word to find out which path it is actually using.
The user can customise both his template location and his startup path, if
he does, your association will fail.

Hope this helps

from "Jon said:
Hi all,
I'm working on a template installer that customizes a set of templates
and then installs them into the user's default template folder. I've
been getting the path with "ActiveDocument.Path" so that the installer
will work regardless of where it's located, or what platform.

Additionally, I want to use DIR to loop through the files in the
Install Templates folder, so that additional templates can be added to
the folder later without having to modify the program.

Thing is, I discovered that if I set the path explicity:

MyPath = "Macintosh HD:Users:jsherry:Desktop:Install:"

Dir correctly loops the correct number of times, and returns the names
of the files in the Install folder.

If I set the path this way:

MyPath = ActiveDocument.Path

the scope of Dir is narrowed, and the loop iterates once, returning
only the name of the ActiveDocument.

Is there some way out of this? If I have to specify a path, then I'll
need a different path for Mac and Windows, and maybe for OS9 and OSX,
as well.

I've only tested in Word v.X, 10.1.5, so far.

Thanks, so much
-jb

--

Please respond only to the newsgroup to preserve the thread.

John McGhie, Consultant Technical Writer,
McGhie Information Engineering Pty Ltd
Sydney, Australia. GMT + 10 Hrs
+61 4 1209 1410, mailto:[email protected]
 
J

Jon Sherry

John,



John McGhie said:
Hi Jon:

It's so long since I used DIR that I have forgotten how it's supposed to
work, but something in the back of my mind tells me that you set the path by
calling it once specifying a path, then call it without specifying a path
after that to have it return the next item in the list each time.

Yes, this is what the docs say. I kept taking the example from the VBA
help (the Mac VBA help has a PC only example), and modifying it for my
needs and it kept failing. When I finally set a path like:

Mypath = "Macintosh HD:Users/Admin/Desktop/Install Templates"

it worked as advertised.
I seem to also remember that on the PC, the DIR command sets the Active
Path, whereas on the Mac it does not.

Interesting. I assume the active path is like the current directory,
i.e. if one executes DOS commands they execute in the Active Path. This
same feature should work fine with the Unix shell, if MS implements it.
However, I am wondering why you would not return the path you are seeking
directly with Application.NormalTemplate.Path... Or even
Application.StartupPath

I'm setting the path to "install" the templates, using:

Options.DefaultFilePath(wdUserTemplatesPath)

Users will save the folder to their desktop, or go to a server volume,
and run the installer from there. THe installer doc is in the same
folder as the templates to be installed.

I'm using ActiveDocument.Path to get the current location of the files,
so it doesn't matter where the installer.doc is opened from.
Putting your files in a folder of the correct name is not going to guarantee
success: you need to query Word to find out which path it is actually using.
The user can customise both his template location and his startup path, if
he does, your association will fail.

This exactly what I said my initial post. I don't want to put an
absolute path, nor do I want to make my ignorant users find their
templates folder. That's why I've written a sub-routine to copy the
templates set to their templates folder, after customizing them from a
form they fill out.

I've got a folder with an Install.doc and some templates to be
installed into the user's user templates path. I want to get the path
to the Installer folder, and then run Dir to loop through the templates
in the folder, updating some fields on the templates, and then saving
the templates to the templates path.

Problem is that Dir only works when an absolute path is specified to
the installer folder. I even tried getting the path to the installer
with Application.MacroContainer.Path, but the same thing happens.

The path looks correct, but Dir only finds the installer in the folder,
instead of finding all the files, as it does when the path is absolute.

hmm.
 
J

John McGhie [MVP - Word]

Hi John:

from "Jon said:
Interesting. I assume the active path is like the current directory,
i.e. if one executes DOS commands they execute in the Active Path. This
same feature should work fine with the Unix shell, if MS implements it.

Yes, it is probably the "current directory" and I used the wrong term for
it. I doubt very much whether it will work in the Unix Shell, and since
Microsoft's stated position is no future development of VBA, I doubt if it
ever will.

All new stuff is going into dot-Net/C-sharp, and Microsoft has no plans to
bring that to the Mac. They are still waiting for sufficient demand to
appear on the Mac to justify a mega-expensive project to port dot-Net to the
Mac.

Dot-Net is huge, and there's just not enough installed base, let alone
solution development, happening on the Mac to make it worth it. But watch
this space: some of us are campaigning vigorously.

People here can help *a lot* by regularly writing or posting to MSWISH
asking for dot-Net, ActiveX or features they provide. You can search for
"mswish" in Google to get the correct addresses.

Hint: The first person to see your request won't have much comprehension of
it, so be polite, be supportive, and include justification for why you want
it giving examples of how you would use it. That way, someone who knows
dot-Net and the Mac well will be the next person to see your post :)

Cheers
I'm setting the path to "install" the templates, using:

Options.DefaultFilePath(wdUserTemplatesPath)

Users will save the folder to their desktop, or go to a server volume,
and run the installer from there. THe installer doc is in the same
folder as the templates to be installed.

I'm using ActiveDocument.Path to get the current location of the files,
so it doesn't matter where the installer.doc is opened from.


This exactly what I said my initial post. I don't want to put an
absolute path, nor do I want to make my ignorant users find their
templates folder. That's why I've written a sub-routine to copy the
templates set to their templates folder, after customizing them from a
form they fill out.

I've got a folder with an Install.doc and some templates to be
installed into the user's user templates path. I want to get the path
to the Installer folder, and then run Dir to loop through the templates
in the folder, updating some fields on the templates, and then saving
the templates to the templates path.

Problem is that Dir only works when an absolute path is specified to
the installer folder. I even tried getting the path to the installer
with Application.MacroContainer.Path, but the same thing happens.

The path looks correct, but Dir only finds the installer in the folder,
instead of finding all the files, as it does when the path is absolute.

hmm.

--

Please respond only to the newsgroup to preserve the thread.

John McGhie, Consultant Technical Writer,
McGhie Information Engineering Pty Ltd
Sydney, Australia. GMT + 10 Hrs
+61 4 1209 1410, mailto:[email protected]
 
P

Paul Berkowitz

When I finally set a path like:

Mypath = "Macintosh HD:Users/Admin/Desktop/Install Templates"

it worked as advertised.

Use colons throughout for better results

Mypath = "Macintosh HD:Users:Admin:Desktop:Install Templates"
 
J

Jon Sherry

Sorry Paul, that was just me being harried when I mixed separators that
way. But, boy is it good that I made that mistake. I was just checking
my complete test code before posting it here, and figured it out.


I specified the path explicity like this:
'MyPath = "Macintosh HD:Users:jsherry:Desktop:Install:"
and it works.

When I specified the path like this:
MyPath = ActiveDocument.Path
it doesn't work.

I've been checking the path with this:
MsgBox (MyPath) 'Show the path.
and finally noticed the problem.

Setting the installer path like this:
MyPath = ActiveDocument.Path & ":" '

Works!

I appreciate having the opportunity to bounce this off you guys.

-jb
 
P

Paul Berkowitz

Yes, I wasn't sure whether the location was a folder or a file. In
colon-type paths you need a final ":" at the end if it's a folder.
(Actually, in real AppleScript, at least in OS 10.3 and I think 10.2, that
final colon is not necessary for folders. But evidently VBA Mac still
requires it.)

--
Paul Berkowitz
MVP Entourage
Entourage FAQ Page: <http://www.entourage.mvps.org/toc.html>
AppleScripts for Entourage: <http://macscripter.net/scriptbuilders/>

Please "Reply To Newsgroup" to reply to this message. Emails will be
ignored.

PLEASE always state which version of Entourage you are using - 2001 or X.
It's often impossible to answer your questions otherwise.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top