Hi everyone,

I intend to capture a folder path in a macro and use it later in a program to save files to after the end of my DO file. This path shall be capture programmatically through the window command and not manually through the "cd" command

I found this code helpful but it also include the file name with it. I only need the directory path excluding file name.
Code:
capture window fopen D_dta "Select a dataset to use:" xlsx
1. So, is there a way to either directly capture the directory path
2. I tried to use the tokenize command to substitute the last token (file name) with white space.
But, I don't know how to programmatically get the last token instead of manually entering it, and it does not work too.

Code:
tokenize "xyz\sample\test\sample.xlsx",p("\")
global newpath:subinstr global D_dta "`7'" "",all
di "$newpath"
Appreciate you help.