Shortening File Names in Load into DataFolder Procedure
n.black
I have made my own "loadwave" procedure for my data and that includes some basic manipulations and stuff.
What I want to do now is:
1) Write a procedure to create a datafolder that i can loadwaves from my file into.
2) Extend that to loading every file in a folder such that on igor it will look like root:Foldername:filename
Currently i'm manually making a data folder loading my files one at a time (I have a lot of files and am now going mad!)
I read through the datafolder tutorial and the programming with datafolders in the manual. But my problem is that my file names are too long for me to do the usual steps like:
String extension = "." + ParseFilePath(4, fileName, ":", 0, 0) // e.g., ".dat"
String dfName = RemoveEnding(fileName, extension)
NewDataFolder/O/S :$dfName
String dfName = RemoveEnding(fileName, extension)
NewDataFolder/O/S :$dfName
(NB copied from Hrodstein's tutorial)
A typical file for me is named like so: "01.pile of parameters.txt" where the first two characters tells me which 'Run' I'm in.
I don't mind having a dummy datafolder name that i can change later, but if i want to have this as part of a mass folder loader I can foresee trouble ahead. ie I need something that loops through datafolder names and finds one not used like if datafolder1 exists it will produce datafolder2.
Ideally it would be nice to have a new datafolder named "scan01" where the 01 is taken from the first two characters of the file name.
Is there a function similar to "RemoveEnding"?
Thanks anyone who can help!
Best wishes,
N
NewDataFolder/O/S :$ShortDFName
will do the job. It extracts the fist two characters (0 to 1) of dfName and puts it behind a fixed part of the name.
I necessary you can also add a counter
ShortDFName=ShortDFName+"_"+num2str(Cntr)
.You loop structure might look like
Variable Cntr=0
String ShortDFName="Run_"+dfName[0,1]
Do
If (DataFolderExists("root:"+ShortDFName+"_"+num2str(Cntr)))
Cntr+=1
Else
NewDataFolder /S root:$ShortDFName+"_"+num2str(Cntr)
Break
EndIf
While (1)
You probably want to avoid relative paths in this case (" :$dfName ")
HJ
August 26, 2015 at 03:49 am - Permalink
For this wish, look to the built in function "UniqueName", which will append a numeric suffix to a name to make it unique for its type of object. Also, take a look at the other functions for working with names: "CheckName: and "CleanupName".
August 26, 2015 at 06:03 am - Permalink
That's a really handy piece of code. I combined it with a function from the Datafolder tutorial GetLeafName() which was really handy.
So if anyone else has a similar problem I recommend going through the procedure in that tutorial experiment.
Thanks HJ.
August 26, 2015 at 08:03 am - Permalink