Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: RE: RE: RE: RE: RE: RE: RE: global macro for system directory?


From   Eric Booth <ebooth@ppri.tamu.edu>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: RE: RE: RE: RE: RE: RE: RE: global macro for system directory?
Date   Sat, 9 Jan 2010 17:40:54 -0600

<>

Edit:  This line needs double quotes to work with multiple paths in any of the file location locals:
foreach d in `mydirs' `server_dir' `backup_dir'  {

so, it should be:
foreach d in "`mydirs'"  "`server_dir'"  "`backup_dir'"  {



EAB
__
Eric A. Booth
Public Policy Research Institute
Texas A&M University
ebooth@ppri.tamu.edu
Office: +979.845.6754


On Jan 9, 2010, at 5:30 PM, Eric Booth wrote:

> <>
> 
> I'm not sure what you mean by re-routing the filepaths, but I think Martin is right that you are looking for some kind of find/replace.  You can do this across all your do-files at once, rather than by opening each individual file (( if you are careful about specifying the correct directories to search/replace file paths, and you're sure that this process won't accidentally overwrite filepaths somewhere in those files that are critical for other programs/tasks)) 
> I did something like this when I moved from a Windows machine to a Mac.  I had a lot do-files which included references to locations on my Windows machine, and these do-files were stored in several locations:  my harddrive (`mydirs', in the code below), server (`server_dir'), and my external HD (`bkp_dir').    You could adapt the code I used for this process:
> 
> *-----------------------BEGIN CODE
> //directories where my do-files were located
> local mydirs "/users/eric_a_booth//"   "/users/eric_a_booth/project/code//" 
> local server_dir  "/volumes/projectfiles/coderepository//"
> local bkp_dir "/volumes/ENCRYPT_BACKUP/eric_a_booth//"
> 
> //filepaths to change:
> local from "C:\BSdata\BSproject\BSebooth\BS"
> local to "/users/eric_a_booth/"
> /*  note: 
> filefilter requires "\BS" instead of just a backslash "\"
> */
> ****
> 
> foreach d in `mydirs' `server_dir' `backup_dir' {
> 		//maindir 
> global files: dir "`d'/" files "*.do", respectcase
> tokenize `"$files"'
> while "`1'" != "" {
> 	filefilter "`d'/`1'" "`d'/`1'2", from("`from'") to("`to'") replace
> 	copy "`d'/`1'2" "`d'/`1'", replace
> 	erase "`d'/`1'2"
> 		di "file `1' in directory `d' converted "
>  	macro shift
> 		}		
> 		//subdir
> global all: dir "`d'" dirs "*", respectcase
> foreach j of global all {
> di "`j'"
> global files: dir "`d'`j'/" files "*.do", respectcase
> tokenize `"$files"'
> while "`1'" != "" {
> 	filefilter "`d'`j'/`1'" "`d'`j'/`1'2", from("`from'") to("`to'") replace
> 	copy "`d'`j'/`1'2" "`d'`j'/`1'", replace
> 	erase "`d'`j'/`1'2"
> 			di "file `1' in directory `d'`j'  converted "
>  	macro shift
> 			}
> 		}	
> 	}
> *-----------------------END CODE
> This will search the folders/directories you specify, plus one level of directories below that level.  You can delete the "subdir" part if you don't want this (or use a loop to extend this to more sub-levels if you'd like).  Again, take care when making these changes across many files/folders all at once.
> 
> ~ Eric
> __
> Eric A. Booth
> Public Policy Research Institute
> Texas A&M University
> ebooth@ppri.tamu.edu
> Office: +979.845.6754
> 
> 
> On Jan 9, 2010, at 4:58 PM, David Wallace wrote:
> 
>> 
>> I have a similar issue with migrating Stata to a new laptop and running my .do file.  Can I change my hardcoded file paths in all my old .do files by specifying a macro that can reroute the filepaths used in a .do file?  So if my .do file says   " use "C:\Documents and Settings\DW\My Documents\thesis.dta", clear " can I specify an macro that will reroute all the "C:\Documents and Settings\DW\My Documents" part in .do files to something like "C:\Documents and Settings\administrator\Documents\"  ????
>> 
>> 
>> 
>> 
>> 
>> -----Original Message-----
>> From: owner-statalist@hsphsun2.harvard.edu
>> [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Hoffman, George
>> Sent: Samstag, 9. Januar 2010 05:33
>> To: statalist@hsphsun2.harvard.edu
>> Subject: st: global macro for system directory?
>> 
>> I recently reinstalled stata 10 on my computer with a new os (windows 7). On
>> my old computer, I had installed in "c:\program files\stata". On the new
>> computer, it was in "c:\program files\stata10" by default. I had previously
>> written a bunch of ado and do files for data and log file manipulation that
>> referenced hardcoded directories under "c:\ptogram files\stata".
>> 
>> I know that the sysdir command will reveal the STATA directory to be the
>> install directory. Is there a way to retrieve that into a macro or tempvar
>> that I can then reference from a do or ado file?
>> 
>> Yes, it would all work fine if I just renamed my stata install dir - but I'd
>> rather not hardcode if possible.
>> 
>> Thanks,
>> George Hoffman
>> 
>> 
>> 
>> *
>> *   For searches and help try:
>> *   http://www.stata.com/help.cgi?search
>> *   http://www.stata.com/support/statalist/faq
>> *   http://www.ats.ucla.edu/stat/stata/
>> 
>> 
>> 
>>     Get your new Email address!
>> Grab the Email name you&#39;ve always wanted before someone else does!
>> http://mail.promotions.yahoo.com/newdomains/sg/
>> 
>> 
>> *
>> *   For searches and help try:
>> *   http://www.stata.com/help.cgi?search
>> *   http://www.stata.com/support/statalist/faq
>> *   http://www.ats.ucla.edu/stat/stata/
> 
> 
> 
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/




*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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