For selecting a folder which contains data files I use the following code:
ChoiceDialog[{FileNameSetter[Dynamic[dir], "Directory"], Dynamic[dir]}];
dir
(as string) is the full path name of the folder.
How can I extract the deepest folder name? For examples:
dir = "F:\\20160111\\data\\folder1";
I would like to extract "folder1
".
Can that be read directly with ChoiceDialog
? Or do I have to search in the dir
string?
Example on how I do it:
dirLength = StringLength[dir];
start = StringPosition[dir, "\\"];
start = Max[Flatten[start]];
deepestFolder=StringTake[dir, -(dirLength - start)];
Print[deepestFolder]
"folder1"
FileBaseName
and friends. $\endgroup$