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

Re: st: mkdir with local

From   "David Elliott" <[email protected]>
To   [email protected]
Subject   Re: st: mkdir with local
Date   Mon, 24 Sep 2007 09:47:40 -0300

One can add a refinement to this in the event the directory has
already been created (e.g. with a previous run of the program):

local name test_directory
cd C:\
capture confirm file "./`name'/nul" // check if `name' subdir exists
if _rc { // _rc will be >0 if it doesn't exist
	!md "`name'"

// my do file
save "C:/`name'/current_data.dta"  // optionally add -,replace-

(1) "nul" allows you to use the -confirm file- command to check the
existence of a directory.  Even an empty directory has a "device"
called "nul" that can be checked.  (I'm sure there are others who can
give a better technical explanation of "nul" in this context)
(2) by using the ./ notation for the present working directory, the
code works from any directory location - avoid hard-coding paths
whenever possible and use relative paths - your programs will usually
work even if you move them and data to new directories.  You just have
to edit the base path in the cd statement.

DC Elliott
*   For searches and help try:

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