#10 获取目录的代码记录

Open
created 1 year ago by lyb · 0 comments
lyb commented 1 year ago
``` print("获取当前目录") print(os.path.abspath(__file__)) # 获取当前目录 print("获取当前目录") currentPath = os.getcwd() #获取当前目录 print(currentPath) print(os.path.dirname(os.path.abspath(__file__))) print("获取上级目录") print(os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir))) #获取上级目录 print("bbbbbbbbbbbbbbbbbbbbbbbbb") print("获取根目录文件") print(os.listdir('/')) #获取根目录文件 print("ccccccccccccccccccccccccc") print("获取当前目录文件") print(os.listdir()) #获取当前目录文件 print("ddddddddddddddddddddddddd") print(os.system('ls -l')) print("*************************") result1 = os.system('ls') print(result1) # 输出为0 print(f'result1 = {result1}') ``` ``` 用于返回指定路径的内容 def scanfile(path): filelist = os.listdir(path) print(filelist) allfile = scanfile('/home/ma-user/work/cv-cases/case7_u-net_segmentation/checkpoints') ```
lyb self-assigned this 1 year ago
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date

No due date set.

Dependencies

This issue currently doesn't have any dependencies.

Loading…
There is no content yet.