Statalist


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

st: An ado file for quickly switching working directories


From   Malcolm Wardlaw <[email protected]>
To   [email protected]
Subject   st: An ado file for quickly switching working directories
Date   Mon, 14 Jul 2008 12:46:02 -0500

I have a lot of original data sequestered away in specific working directories that I like to be able to access on the fly when I am doing quick and dirty analysis on data (as opposed to more formal programming where I use do files).

I'm not an expert programmer and, while it works, I'm not sure if this is the most efficient way to go about it. It basically reads an existing text file line by line and takes the first matching variable cue to switch directories. It also provides for a reading of the entire list of potential directories with the variable "list". I'll post the file below. If anyone has any better approaches (or possible extensions), I'd like to hear them. Also, I don't know if there's already a better, pre-constructed file for this. If it's an OK approach, then I suppose I'd just like to share it with everyone if people would like to use it.

-----------------------------------------
wd.ado:
program define wd
version 9.2
if "`1'" == "list" {
type "c:\ado\personal\workingdir.txt"
di("")
di("<--current directory-->")
pwd
di("<--current directory-->")
}
else{

tempname fh
local linenum = 0
file open `fh' using "c:\ado\personal\workingdir.txt", read
file read `fh' line
while r(eof)==0{
local a: word 2 of `line'
if word(`" `macval(line)'"',1)=="`1'"{
cd "`a'"
}
file read `fh' line
}
file close `fh'
}
end
-----------------------------------------
workingdir.txt:

data "c:\data"

ds "c:\my documents\dealscan original\"

dse "c:\my documents\Stata Data\fixed master\"

gold "c:\my documents\Stata Data\Gold data\"

cov "c:\My Documents\Stata Data\Covenant Research\"

ado "c:\ado\personal"

myd "c:\My Documents\Stata Data\"
-----------------------------------------

*
* 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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index