Statalist


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

Re: st: making Stata read do-files


From   Alan Riley <ariley@stata.com>
To   statalist@hsphsun2.harvard.edu
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]_yyyymmdd.do, 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
needs.

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

   DNAreport_1.do

is no different than a file named

   dnareport_1.do

or

   DNAREPORT_1.DO


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
(ariley@stata.com)
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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