I would like to know how can I open and navigate through folders in the OS in Python the same way I can do it in MATLAB. I have tried using some os
functions but none of them seems to make a lot of sense for what I need.
Basically, I need a code where I open a folder on Windows, get the directory, search for the filename I want and read the data inside. I have a MATLAB code that does this exact process below:
P = fileparts(mfilename('fullpath')); %Opening a folder
nfolder = uigetdir(P,'Select the file directory'); %Opens a File Open/Save window to find the folder where the sequence is
if~ischar(nfolder)
disp('Invalid Directory')
return;
end
prefix = nfolder; %Directory
comp = '/name-of-the-file';
ext = '.extension';
fname = [prefix comp ext]; %Path
delimiterIn=' ';
headerlinesIn=11;
Db=importdata(fname,delimiterIn,headerlinesIn); %Import the data (basically numbers)
Db=Db.data;
I would really appreciate any help