简体   繁体   English

Python跨平台文件浏览器

[英]Python cross platform file explorer

I need to scan a hard disk and display folders and files in some sort of file explorer. 我需要扫描硬盘,并在某种文件浏览器中显示文件夹和文件。 I need to do this cross platform. 我需要做这个跨平台。 Since I thought this a quite common a task I tried to find a library for this task but didn't find anything. 由于我认为这是一项非常常见的任务,因此我尝试为该任务找到一个库,但未找到任何内容。

The exact use case: Via a web interface a user browses his filesystem (ideally including not only all mounted harddisks but also any mounted shared drives, remote locations. Expanding a folder on the web UI would trigger a call to the python component making a user's harddisk browsable via web. 确切的用例:用户通过Web界面浏览其文件系统(理想情况下不仅包括所有已安装的硬盘,而且还包括所有已安装的共享驱动器,远程位置。在Web UI上展开文件夹将触发对python组件的调用,从而使用户可通过Web浏览的硬盘。

The format of choice for the python/javascript communication is json. python / javascript通信的选择格式是json。

While I know python offers many tools for doing it yourself I don't want to deal with OS differences (getting mounts) and encoding issues. 虽然我知道python提供了许多工具来自己做,但我不想处理OS的差异(获取挂载)和编码问题。

EDIT: To had to be more precise after the first answers (sorry for that missing in my inital post): 编辑:必须在第一个答案之后更加精确(对不起,我的初始帖子中缺少该内容):

Thanks. 谢谢。

Do you want this file explorer to run in the shell, or would you like a GUI? 您是否要在外壳中运行此文件资源管理器,还是需要GUI?

If you just want to do it in a shell, I suggest looking at os.listdir; 如果您只想在shell中进行操作,建议您查看os.listdir;。 the os.path functions also come in handy. os.path函数也很方便。 Using listdir, you can easily write a recursive directory lister in around a dozen lines. 使用listdir,您可以轻松地在大约12行中编写一个递归目录列表器。

There's a "simple" cross-platform GUI example in the GTK2 tutorial which uses the GTK TreeView object; GTK2教程中有一个“简单”的跨平台GUI示例,该示例使用GTK TreeView对象。 the example program is called filelisting.py . 该示例程序称为filelisting.py

IMO, the GTK2 tutorial is quite good, but as with any GUI framework there's a fair bit of material to learn if you want to become a competent GTK2 programmer. IMO,GTK2教程相当不错,但是与任何GUI框架一样,如果您想成为一名合格的GTK2程序员,则需要学习很多材料。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM