如何使用 Python 打开和浏览 Windows 文件夹?

问题描述

我想知道如何在 Python 中打开和浏览 OS 中的文件夹,就像在 MATLAB 中一样。我曾尝试使用一些 os 函数,但它们似乎对我所需要的没有多大意义。

基本上,我需要一个代码,用于在 Windows 上打开文件夹、获取目录、搜索我想要的文件名并读取其中的数据。我有一个 MATLAB 代码,它在下面执行这个确切的过程:

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;

我真的很感激任何帮助

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)