小编0U0*_*0e0的帖子

我如何使用像 CD 和 LS 这样的 Linux 终端命令?

如何将终端命令添加到我的 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)

html python linux python-3.5

6
推荐指数
1
解决办法
1813
查看次数

标签 统计

html ×1

linux ×1

python ×1

python-3.5 ×1