Creating Dynamic File Names Within a Do Loop

Use this forum to post questions about syntax problems or general programming issues. Questions on implementing a particular aspect of econometrics should go in "Econometrics Issues" below.

Creating Dynamic File Names Within a Do Loop

Postby Gregory » Tue Aug 12, 2008 1:17 pm

Not sure what I'm doing wrong here. I'd like to save results on each iteration of a Do loop and append the iteration number, i, to each file name. But when I run this code, I am prompted for a location to save, and the forward slashes in my file path have been converted to hyphens.

Code: Select all
declare string theFilePath
declare string longFileName

compute theFilePath = "/Users/gregory/Documents/Folder A/"

do i=1,5

* Some stuff goes here

compute longFileName = theFilePath + "My File" + i + ".xls"
open copy &longFileName
copy(format=xls,org=col) theStart+i theEnd+i hhs

End do i
Gregory
 
Posts: 20
Joined: Mon Nov 13, 2006 9:05 am
Location: Montreal

Postby TomDoan » Wed Aug 13, 2008 11:58 am

It sounds as if that path doesn't exist. (COPY will create a new file in an existing folder, but it won't create a new folder). The -'s seem to be the Mac OS X file dialog's method of dealing with input file names with /'s in them. I haven't been able to find a good description of why it does that. At any rate, it looks as if having a path to a valid folder will avoid the problem.
TomDoan
 
Posts: 2720
Joined: Wed Nov 01, 2006 5:36 pm

Postby Gregory » Wed Aug 13, 2008 4:20 pm

TomDoan wrote:It sounds as if that path doesn't exist.


You're absolutely right. Missing sub-folder. Thank you, Tom.

Gregory
Gregory
 
Posts: 20
Joined: Mon Nov 13, 2006 9:05 am
Location: Montreal


Return to Help With Programming

Who is online

Users browsing this forum: No registered users and 1 guest