如何将终端命令添加到我的 Python 脚本中?我有一个包含更多图像/视频的图像/视频/文件夹的巨大文件夹,我想将它们组织在一个 HTML 文件 (FirstPage.html) 中。
该脚本首先列出目录中的所有文件:
def listFiles():
command = "ls"
output = Popen(command, stdout=PIPE) #This is the only way i found to run LS in terminal and get the output
x = str(output.stdout.read())
x = x[2:-3]
x += (" ")
x = re.sub(r"\\n", " ", x)
y = ""
finalLIST = list()
for o in x:
if o == " ":
finalLIST.append(str(y))
y = ""
else:
y += o
return finalLIST #returns a list with all files …Run Code Online (Sandbox Code Playgroud)