[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: making Stata read do-files

From   Alan Riley <>
Subject   Re: st: making Stata read do-files
Date   Tue, 15 Apr 2008 09:51:01 -0500

Gabi Huiber is using the extended macro function -dir- under Windows
and is having a problem with uppercase letters in filenames:

> I am having a problem with uppercase letters in file names.
> I am trying to impose some version control on a bunch of do-files of
> the type [filename], that have been saved weekly with
> various changes over the past two years or so.
> In the first stage of this job I just want to read their names, then
> collect the yyyymmdd part in a matrix. But I am hitting a snag with
> files where the alphanumeric part contains uppercase characters. My
> code goes like this:
> [snip]
> local `k'list: dir "${dofrom}" files "`k'*.do"
> local `k'clean: list clean `k'list
> local `k'num: list sizeof `k'clean
> di "`k'"
> di ``k'num'
> [snip]

Gabi has some files that begin with the prefix "DNAreport_", but when
the local macro `k' above contains that prefix, nothing is put into
the local macro ``k'list' by -dir-.  That results in the final two
lines of the code displaying

> DNAreport_
> 0

and a subsequent part of Gabi's code that does not expect to see
0 files fails with an error.

Let me first explain what Gabi can do in the code above to fix it
for now.  After that I'll explain what is happening and what we
(StataCorp) should do in the future about this.

Gabi can replace the first line of the code above,

   local `k'list: dir "${dofrom}" files "`k'*.do"

with the following two lines:

   local lowerk = strlower("`k'")
   local `k'list: dir "${dofrom}" files "`lowerk'*.do"

The -dir- extended macro function, under Windows, sees all filenames
as lowercase.  So, Gabi can lowercase the pattern which -dir- is using
to match filenames, and then -dir- will return the list of files Gabi

Read on only if you are interested in some technical details.

Why does -dir- work this way under Windows?

Windows does not have true case-sensitive filenames.  Macintosh OS X
and Unix both have true case-sensitive filenames, so there is no issue
with those operating systems.

In Windows, a file named

is no different than a file named



Gabi can see this in a Windows command window (not to be confused
with Stata's Command window) by changing to the directory where the
DNAreport_*.do files exist and typing

   C:\somedirectory> dir DNA*

   C:\somedirectory> dir dna*

In both cases, the same files will be shown.

Stata knows that Windows does not care about the case of filenames.
There are routines in Stata that need to make a list of all filenames
of a certain type (think -adoupdate-), and under Windows, those
routines need to be assured that they are finding, say, *.ado files,
no matter whether Windows has stored some of them with capital letters
in their names or not.

However, there are cases where users such as Gabi do care about
the case of filenames under Windows, and Stata needs to support that.
In a future update we will add a Windows-only option to the -dir-
extended macro function (perhaps 'respectcase').  Without the option,
-dir- will behave as it does now.  With the option, -dir- will pay
attention to case when matching files, and the list of files returned
by -dir- will preserve the case of the filenames in Windows.

--Alan Riley
*   For searches and help try:

© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index