日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python中的文件父路径怎么表达_python中的文件父路径怎么表达_如何在Python中访问父目录...

發(fā)布時間:2023/12/1 python 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python中的文件父路径怎么表达_python中的文件父路径怎么表达_如何在Python中访问父目录... 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

所以我有一個朋友給我的Python腳本,但是我沒有Python的經(jīng)驗。代碼如下:from os import path, chdir, listdir, mkdir, getcwd

from sys import argv

from zipfile import ZipFile

from time import sleep

#Defines what extensions to look for within the file (you can add more to this)

IMAGE_FILE_EXTENSIONS = ('.bmp', '.gif', '.jpg', '.jpeg', '.png', '.tif', '.tiff')

#Changes to the directory in which this script is contained

thisDir,_ = path.split(path.abspath(argv[0]))

chdir(thisDir)

#Lists all the files/folders in the directory

fileList = listdir('.')

for file in fileList:

#Checks if the item is a file (opposed to being a folder)

if path.isfile(file):

#Fetches the files extension and checks if it is .docx

_,fileExt = path.splitext(file)

if fileExt == '.docx':

#Creates directory for the images

newDirectory = path.join(thisDir + "\Extracted Items", file + " - Extracted Items")

if not path.exists(newDirectory):

mkdir(newDirectory)

currentFile = open(file, "r")

for line in currentFile:

print line

sleep(5)

#Opens the file as if it is a zipfile

#Then lists the contents

try:

zipFileHandle = ZipFile(file)

nameList = zipFileHandle.namelist()

for archivedFile in nameList:

#Checks if the file extension is in the list defined above

#And if it is, it extracts the file

_,archiveExt = path.splitext(archivedFile)

if archiveExt in IMAGE_FILE_EXTENSIONS:

zipFileHandle.extract(archivedFile, newDirectory)

if path.basename(archivedFile) == "document.xml":

zipFileHandle.extract(archivedFile, newDirectory)

if path.basename(archivedFile) == "document.xml.rels":

zipFileHandle.extract(archivedFile, newDirectory)

except:

pass

對于newDirectory = path.join(thisDir + "\Extracted Items", file + " - Extracted Items")的行

我想修改它以訪問thisDir的父目錄,然后創(chuàng)建\Extracted Items文件夾。有人知道在python中訪問父目錄的最佳方式是什么嗎?在

總結

以上是生活随笔為你收集整理的python中的文件父路径怎么表达_python中的文件父路径怎么表达_如何在Python中访问父目录...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。