How do I get the directory to produce names in alphabetical order?

R

Robert Macy

This may be OT for WinXP, but here is the problem:

Running Word 2003 on WinXP I use a macro to print some 120 documents.
The order come out random and each print run has to be collated to put
them into alphabetical order!

Of course the documents all come up in Windows Explorer in any order
selectable, yet the macro prints in the order the documents appear on
the drive in DOS memory and ignore any other order. As a result I
have to collate these documents back into order!

There must be at least two ways to do this. The first, and this is
what I tried to do, was copy into a pristine location the files so
that they would already be 'laid down' in order. That almost worked,
but I have to add documents from time to time and that shifts it all
around again. If this were Win98, I could include a statement in the
autoexec.bat file to order the directories, then when Word under macro
control goes to get its list, it would get the list in alphabetical
order. The second, must relate to the macro command in Word, but I
couldn't find anything about that.

So, the question is

How do I get DOS to order the directory so that when Word, under macro
control, prints the douments in the necessary alphabetical order?

Robert
 
P

Pegasus [MVP]

Robert Macy said:
This may be OT for WinXP, but here is the problem:

Running Word 2003 on WinXP I use a macro to print some 120 documents.
The order come out random and each print run has to be collated to put
them into alphabetical order!

Of course the documents all come up in Windows Explorer in any order
selectable, yet the macro prints in the order the documents appear on
the drive in DOS memory and ignore any other order. As a result I
have to collate these documents back into order!

There must be at least two ways to do this. The first, and this is
what I tried to do, was copy into a pristine location the files so
that they would already be 'laid down' in order. That almost worked,
but I have to add documents from time to time and that shifts it all
around again. If this were Win98, I could include a statement in the
autoexec.bat file to order the directories, then when Word under macro
control goes to get its list, it would get the list in alphabetical
order. The second, must relate to the macro command in Word, but I
couldn't find anything about that.

So, the question is

How do I get DOS to order the directory so that when Word, under macro
control, prints the douments in the necessary alphabetical order?

Robert

This is not a DOS or a Windows issue but a Word issue. I recommend you
repost it in a Word newsgroup - that's where the Word experts dwell.
 
T

Tim Slattery

Robert Macy said:
This may be OT for WinXP, but here is the problem:

Running Word 2003 on WinXP I use a macro to print some 120 documents.
The order come out random and each print run has to be collated to put
them into alphabetical order!

Of course the documents all come up in Windows Explorer in any order
selectable, yet the macro prints in the order the documents appear on
the drive in DOS memory and ignore any other order. As a result I
have to collate these documents back into order!

What file system is your disk using? In the FAT systems, files can be
stored in any order, and simply traversing the directory will bring
them back in whatever order they are stored in. In NTFS, files are
stored in a BTree, therefore traversing the directory brings them back
in alphabetical order.

I don't know whether the fact that you're using a Word macro would
impact this, but I doubt it.

Another possibility: is it possible to have your macro retrieve a list
of file names, sort that list, then iterate over the list and print
each file?
 
R

Robert Macy

What file system is your disk using? In the FAT systems, files can be
stored in any order, and simply traversing the directory will bring
them back in whatever order they are stored in. In NTFS, files are
stored in a BTree, therefore traversing the directory brings them back
in alphabetical order.

I don't know whether the fact that you're using a Word macro would
impact this, but I doubt it.

Another possibility: is it possible to have your macro retrieve a list
of file names, sort that list, then iterate over the list and print
each file?

Thank you for your reply.
The memory stick is a FAT directory. The main computer is NTFS
Interesting concept to include sorting in the macro. I originally
posted here because DOS in the Win98 controls the order, and I thought
that the DOS of WinXP did something similar here.

Robert
 
T

Tim Slattery

Thank you for your reply.
The memory stick is a FAT directory. The main computer is NTFS
Interesting concept to include sorting in the macro. I originally
posted here because DOS in the Win98 controls the order, and I thought
that the DOS of WinXP did something similar here.

DOS's "dir" app can sort the names it retrieves, that's the only
control DOS has over this.

There is no DOS in WinXP or Vista. There is a 32-bit command console
that has many of the same commands (like dir), but it's much more
capable. If you do a "dir" without specifying a sort in XP or Vista,
you'll get filenames in alphabetical order if the file system is NTFS,
in a FAT file system they'll be in whatever order. It's a function of
the file system, not the OS.
 
P

Pegasus [MVP]

Tim Slattery said:
DOS's "dir" app can sort the names it retrieves, that's the only
control DOS has over this.

There is no DOS in WinXP or Vista. There is a 32-bit command console
that has many of the same commands (like dir), but it's much more
capable. If you do a "dir" without specifying a sort in XP or Vista,
you'll get filenames in alphabetical order if the file system is NTFS,
in a FAT file system they'll be in whatever order. It's a function of
the file system, not the OS.

--
Tim Slattery
MS MVP(Shell/User)
(e-mail address removed)
http://members.cox.net/slatteryt

Under all OSs based on WinNT the order of files under the "dir" command
depends on the setting of the environmental variable %dircmd%, e.g. set
dircmd=/on, regardless of the file system. If this variable is not specified
then you get the files in the order you mentioned in your reply.
 
T

Tim Slattery

Pegasus said:
Under all OSs based on WinNT the order of files under the "dir" command
depends on the setting of the environmental variable %dircmd%, e.g. set
dircmd=/on, regardless of the file system. If this variable is not specified
then you get the files in the order you mentioned in your reply.

Thanks, I didn't know that. It seems the dircmd environment variable
can be used to set switches that you want the "dir" command to use
each time you invoke it. "/on" tells "dir" to order its output by file
name. There's a brief discussion here:
http://windowsitpro.com/article/art...---using-the-dircmd-environment-variable.html
 
R

Robert Macy

Thanks, I didn't know that. It seems the dircmd environment variable
can be used to set switches that you want the "dir" command to use
each time you invoke it. "/on" tells "dir" to order its output by file
name. There's a brief discussion here:http://windowsitpro.com/article/articleid/71976/jsi-tip-0651---using-...

Thank you for that URL.

The article had a 'brief' way to set the variable DIRCMD, and only
took 20 minutes to pick around until I found what I 'think' it was
talking about.

I'll try and see what happens.

Robert
 
R

Robert Macy

Thanks, I didn't know that. It seems the dircmd environment variable
can be used to set switches that you want the "dir" command to use
each time you invoke it. "/on" tells "dir" to order its output by file
name. There's a brief discussion here:http://windowsitpro.com/article/articleid/71976/jsi-tip-0651---using-...

Tim,

Thank you for your URL

The description in that URL on how to add/set the variable was a bit
vague but after 20 minutes of poking around I added the variable,
DIRCMD to the environment list and set its value to /ON. The example
in the URL was slightly different value, but the example also had an =
sign which can't be done.

Will try out and let everyone know.

Robert
 
B

Bill in Co.

Actually I think just dir /o defaults to sorting by name, so you don't need
to explicitly use dir /on (IIRC)
 
P

Pegasus [MVP]

Bill in Co. said:
Actually I think just dir /o defaults to sorting by name, so you don't
need to explicitly use dir /on (IIRC)

Yes, that's what Tim said all along - for NTFS partitions!
 
T

Tim Slattery

Pegasus said:
Yes, that's what Tim said all along - for NTFS partitions!

No, that's not what I said. When you traverse an NTFS directory -
whether using the dir command, or OP's Word macro, or a C program -
*without* specifying any sort, the filenames will come out in
alphabetical order. That's not the same as talking about default
values of the dir command's switch.
 

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