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.
Gregory
Posts: 20
Joined: Mon Nov 13, 2006 8:05 am

Creating Dynamic File Names Within a Do Loop

Unread post by Gregory »

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
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Unread post by TomDoan »

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.
Gregory
Posts: 20
Joined: Mon Nov 13, 2006 8:05 am

Unread post by Gregory »

TomDoan wrote:It sounds as if that path doesn't exist.
You're absolutely right. Missing sub-folder. Thank you, Tom.

Gregory
Post Reply