|
From: theozh <th...@gm...> - 2017-05-25 13:17:20
|
Thanks, John & Ethan for your immediate response. > There are some example of gnuplot's strong variable capabilities here that > should solve your needs. > http://gnuplot.sourceforge.net/demo/stringvar.html > @John, thanks for the link, but strong string variable capabilities? Are you serious? It would be nice to find the last key (e.g. '\') in a word. Or at least a function to reverse a string. Best would be of course regular expressions ;-). > Assuming that the subdirectories are not themselves named Datasomething, Well, I cannot be sure that this will always be the case. > I'd use something like > > chop(fullname) = fullname[ strstrt(fullname,"Data") : * ] > > plot for [FileName in FileList] FileName u 1:2 w l title chop(FileName) > @Ethan, yes, this works with the above mentioned limitations. Based on your suggestion, the following is a cumbersome workaround for a function to extract the file name (at least to 6 levels of subdirectories, but can be extended). TestFile = 'C:\sub1\sub2\sub3\sub4\Data007.dat' chop1(FullName) = FullName[strstrt(FullName,'\')+1:*] chop2(FullName) = chop1(FullName)[strstrt(chop1(FullName),'\')+1:*] chop3(FullName) = chop2(FullName)[strstrt(chop2(FullName),'\')+1:*] chop4(FullName) = chop3(FullName)[strstrt(chop3(FullName),'\')+1:*] chop5(FullName) = chop4(FullName)[strstrt(chop4(FullName),'\')+1:*] chop6(FullName) = chop5(FullName)[strstrt(chop5(FullName),'\')+1:*] chop(FullName) = chop6(FullName)[strstrt(chop6(FullName),'\')+1:*] FileName = chop(TestFile) print FileName If anybody knows a more elegant or smarter solution, please let me know. |