Using sprintf and $ assignment

Hi, 

I am facing trouble with the $ assignment to any wave name and feeling very confused. Kindly see the code below. The operation is supposed to be straightforward. I want waves "binMZ_%d" to be moved to their corresponding folders "Jan_%d" where %d value goes from 22 to 31. However, the code below is not compiling. The error notice says "A non-existent data folder was referenced while accessing a child data folder.". I'm currently testing for "binMZ_%d" but I want to do the same for tseries, binMS2D and binMS2D_err as well. 

The second question I have is how to tell the code that filename0 is a folder name, filename1 is a wave and so on. This has been really frustrating me because I have multiple files from multiple folders to work with and I don't know how else to run everything under one for loop. Please help! 

Similarly, I had to delete some empty folders from the data browser. So I wrote: deletefolder/Z $filename but I got an error saying $ cannot be used in this way.. totally stuck here. 

Function moverfolder()
variable i
string filename0
string filename1
string filename2
string filename3
string filename4

for(i=22;i<32;i+=1)
sprintf filename0,"Jan_%d",i
sprintf filename1,"binMZ_%d",i
sprintf filename2,"tseries_%d",i
sprintf filename3,"binMS2D_%d",i
sprintf filename4,"binMS2D_err%d",i

movewave $filename1,root:$filename0:$filename1
setdatafolder root:
endfor
end

Many Thanks and Regards, 

Peeyush 

 

I should also mention that I have already manually created the Jan_22, Jan_23... Jan_31 datafolders in which I want waves to be moved. Ideally, I wanted the program to also create the folders and then move waves into them.

So I wrote: newdatafolder $filename0 within the for loop 

but got the same error: "A non-existent data folder was referenced while accessing a child data folder."

So I manually created the folders and now I want to move waves into them via the program above. 

Maybe take a look at data folder references,

DisplayHelpTopic "DFREF"

DFREF dfr=$"root:DataFolderName"
wave wave1=root:$"NameOfWave"
movewave wave1 dfr:$"nameofwave"

 

The following modified & simplified version of your function works on Igor8, W10

Function moverfolder()
variable i

string dfname
string filename1

for(i=22;i<26;i+=1)
sprintf dfname, "root:Jan_%d:", i
sprintf filename1,"Jan_%d",i

movewave $filename1,$dfname
endfor
end

Your source waves can be in any folder as long as it is the current one.  I think the problem was in defining the destination folder.  I had to play around to get it working.  There is probably a way to do it using something like your original syntax, but this version works.  Note that the source wave and destination folder are named the same only because that was the first string that I grabbed and I was too lazy to change it.

 

Jeff

 

Regarding your second question:

- For folders use:

DFREF dfr = root:$myFolderName

or if the string contains a full path

DFREF dfr = $myFolderPath

- For waves use:

wave/SDFR=dfr mywave = $waveNameStr

... but there are many other ways.

Regarding your third question, simply use (assuming you want to delete a data folder in Igor and not in the Windows file system):

KillDataFolder/Z $folderStr

 

Hi All, 

Thank you so much for your responses! They certainly helped, and I was able to get through the bottleneck. I deeply appreciate it!

Many Thanks and Regards, 

Peeyush