当前位置: 首页>>代码示例>>Python>>正文


Python Path.listdir方法代码示例

本文整理汇总了Python中exe.engine.path.Path.listdir方法的典型用法代码示例。如果您正苦于以下问题:Python Path.listdir方法的具体用法?Python Path.listdir怎么用?Python Path.listdir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在exe.engine.path.Path的用法示例。


在下文中一共展示了Path.listdir方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: render

# 需要导入模块: from exe.engine.path import Path [as 别名]
# 或者: from exe.engine.path.Path import listdir [as 别名]
    def render(self, request):
        if "sendWhat" in request.args:
            if request.args['sendWhat'][0] == 'dirs':
                pathdir = Path(unquote(request.args['node'][0].decode('utf-8')))
                l = []
                if pathdir == '/' and sys.platform[:3] == "win":
                    for d in get_drives():
                        try:
                            if is_readable(Path(d)):
                                icon = None
                            else:
                                icon = '../jsui/extjs/resources/themes/images/gray/grid/hmenu-lock.gif'
                            l.append({"realtext": d, "text": d, "id": d + '\\', "icon": icon})
                        except:
                            pass
                else:
                    for d in pathdir.dirs():
                        try:
                            if not d.name.startswith('.') or sys.platform[:3] == "win":
                                if not iswinlink(d.abspath()):
                                    if is_readable(d):
                                        icon = None
                                    else:
                                        icon = '../jsui/extjs/resources/themes/images/gray/grid/hmenu-lock.gif'
                                    l.append({"realtext": d.name, "text": getname(d), "id": d.abspath(), "icon": icon})
                        except:
                            pass
            elif request.args['sendWhat'][0] == 'both':
                pathdir = Path(unquote(request.args['dir'][0].decode('utf-8')))
                items = []
                if pathdir == '/' and sys.platform[:3] == "win":
                    for drive in get_drives():
                        d = Path(drive + '\\')
                        items.append({"name": drive, "realname": drive + '\\', "size": 0, "type": 'directory', "modified": 0,
                                      "is_readable": is_readable(d),
                                      "is_writable": is_writable(d)})
                else:
                    parent = pathdir.parent
                    if (parent == pathdir):
                        realname = '/'
                    else:
                        realname = parent.abspath()
                    items.append({"name": '.', "realname": pathdir.abspath(), "size": pathdir.size, "type": "directory", "modified": int(pathdir.mtime),
                                  "is_readable": is_readable(pathdir),
                                  "is_writable": is_writable(pathdir)})
                    items.append({"name": '..', "realname": realname, "size": parent.size, "type": "directory", "modified": int(parent.mtime),
                                  "is_readable": is_readable(parent),
                                  "is_writable": is_writable(parent)})
                    try:
                        for d in pathdir.listdir():
                            try:
                                if not d.name.startswith('.') or sys.platform[:3] == "win":
                                    if not iswinlink(d.abspath()):
                                        if d.isdir():
                                            pathtype = "directory"
                                        elif d.isfile():
                                            if is_readable(d):
                                                pathtype = repr(mimetypes.guess_type(d.name, False)[0])
                                            else:
                                                pathtype = "file"
                                        elif d.islink():
                                            pathtype = "link"
                                        else:
                                            pathtype = "None"
                                        items.append({"name": getname(d), "realname": d.abspath(), "size": d.size, "type": pathtype, "modified": int(d.mtime),
                                          "is_readable": is_readable(d),
                                          "is_writable": is_writable(d)})
                            except:
                                pass
                        G.application.config.lastDir = pathdir
                    except:
                        pass
                l = {"totalCount": len(items), 'results': len(items), 'items': items}
            return json.dumps(l).encode('utf-8')
        elif "query" in request.args:
            query = request.args['query'][0]
            pathdir = Path(unquote(request.args['dir'][0].decode('utf-8')))
            items = []
            if pathdir == '/' and sys.platform[:3] == "win":
                for d in get_drives():
                    items.append({"name": d, "realname": d + '\\', "size": 0, "type": 'directory', "modified": 0})
            else:
                parent = pathdir.parent
                if (parent == pathdir):
                    realname = '/'
                else:
                    realname = parent.abspath()
                for d in pathdir.listdir():
                    try:
                        if d.isdir():
                            pathtype = "directory"
                        elif d.isfile():
                            if is_readable(d):
                                pathtype = repr(mimetypes.guess_type(d.name, False)[0])
                            else:
                                pathtype = "file"
                        elif d.islink():
                            pathtype = "link"
                        else:
                            pathtype = "None"
#.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:103,代码来源:

示例2: render

# 需要导入模块: from exe.engine.path import Path [as 别名]
# 或者: from exe.engine.path.Path import listdir [as 别名]
    def render(self, request):
        if "sendWhat" in request.args:
            if request.args['sendWhat'][0] == 'dirs':
                #Because this might be absolute and mess up...
                
                
                path_dir_str = unquote(request.args['node'][0].decode('utf-8'))
                path_dir_str = self.get_dirpath_for_request(
                                                request, path_dir_str)
                pathdir = Path(path_dir_str)
                
                
                l = []
                if pathdir == '/' and sys.platform[:3] == "win":
                    for d in get_drives():
                        try:
                            if is_readable(Path(d)):
                                icon = None
                            else:
                                icon = '../jsui/extjs/resources/themes/images/gray/grid/hmenu-lock.gif'
                            l.append({"realtext": d, "text": d, "id": d + '\\', "icon": icon})
                        except:
                            pass
                else:
                    for d in pathdir.dirs():
                        try:
                            if not d.name.startswith('.') or sys.platform[:3] == "win":
                                if not iswinlink(d.abspath()):
                                    if is_readable(d):
                                        icon = None
                                    else:
                                        icon = '../jsui/extjs/resources/themes/images/gray/grid/hmenu-lock.gif'
                                    l.append({"realtext": d.name, "text": getname(d), "id": self.abs_to_user_path(d.abspath(), request), "icon": icon})
                        except:
                            pass
            elif request.args['sendWhat'][0] == 'both':
                req_pathdir_str = unquote(request.args['dir'][0].decode('utf-8'))
                pathdir_str = self.get_dirpath_for_request(
                                               request, req_pathdir_str)
                pathdir = Path(pathdir_str)
                items = []
                if pathdir == '/' and sys.platform[:3] == "win":
                    for drive in get_drives():
                        d = Path(drive + '\\')
                        items.append({"name": drive, "realname": drive + '\\', "size": 0, "type": 'directory', "modified": 0,
                                      "is_readable": is_readable(d),
                                      "is_writable": is_writable(d)})
                else:
                    parent = pathdir.parent
                    if (parent == pathdir):
                        realname = '/'
                    else:
                        realname = self.abs_to_user_path(parent.abspath(), request)
                    items.append({"name": '.', "realname": self.abs_to_user_path(pathdir.abspath(), request), "size": pathdir.size, "type": "directory", "modified": int(pathdir.mtime),
                                  "is_readable": is_readable(pathdir),
                                  "is_writable": is_writable(pathdir)})
                    items.append({"name": '..', "realname": realname, "size": parent.size, "type": "directory", "modified": int(parent.mtime),
                                  "is_readable": is_readable(parent),
                                  "is_writable": is_writable(parent)})
                    try:
                        for d in pathdir.listdir():
                            try:
                                if not d.name.startswith('.') or sys.platform[:3] == "win":
                                    if not iswinlink(d.abspath()):
                                        if d.isdir():
                                            pathtype = "directory"
                                        elif d.isfile():
                                            if is_readable(d):
                                                pathtype = repr(mimetypes.guess_type(d.name, False)[0])
                                            else:
                                                pathtype = "file"
                                        elif d.islink():
                                            pathtype = "link"
                                        else:
                                            pathtype = "None"
                                        items.append({"name": getname(d), "realname": self.abs_to_user_path(d.abspath(), request), "size": d.size, "type": pathtype, "modified": int(d.mtime),
                                          "is_readable": is_readable(d),
                                          "is_writable": is_writable(d)})
                            except:
                                pass
                        #this was before just pathdir - check this
                        if G.application.config.appMode != Config.MODE_WEBAPP:
                            G.application.config.lastDir = pathdir
                        else:
                            self.session.webservice_config.lastDir = req_pathdir_str
                    except:
                        pass
                l = {"totalCount": len(items), 'results': len(items), 'items': items}
            return json.dumps(l).encode('utf-8')
        elif "query" in request.args:
            query = request.args['query'][0]
            path_dir_str = unquote(request.args['dir'][0].decode('utf-8'))
            path_dir_str = self.get_dirpath_for_request(request,path_dir_str)
            pathdir = Path(path_dir_str)
            items = []
            if pathdir == '/' and sys.platform[:3] == "win":
                for d in get_drives():
                    items.append({"name": d, "realname": d + '\\', "size": 0, "type": 'directory', "modified": 0})
            else:
                parent = pathdir.parent
#.........这里部分代码省略.........
开发者ID:UstadMobile,项目名称:exelearning-ustadmobile-work,代码行数:103,代码来源:dirtree.py


注:本文中的exe.engine.path.Path.listdir方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。