linux 不用cd和ls,如何使用CD和LS之类的Linux终端命令?

如何向Python脚本添加终端命令?

我有一个大文件夹的图片/视频/文件夹更多的图像/视频,我想把它们组织在一个HTML文件(首页.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 in the current directory

然后检查文件是图像还是视频,如果是视频,则添加到HTML文件中:

^{pr2}$

如果它是一个图像,它会添加:image

代码是:def organize():

DIRECTORIES = listFiles()

IMAGE = [".png", ".jpg"]

VIDEO = [".webm", ".mp4"]

for x in DIRECTORIES:

if not re.search(".", x):

#This means that it is a directory

#I want to CD into this directory and run listFiles() and then organize() it. How i do it?

else:

for y in IMAGE:

ADDimg = "\n\"imagem\"/\n"

if re.search(y, x):

with open(FirstPage.html) as f:

for line in f:

if line = "":

f.write(ADDimg)

break

f.write(ADDimg)

for y in VIDEO:

ADDvideo = """\n

"""\" type="video/WebM/mp4">

Video not suported!

\n

"""

if re.search(y, x):

with open(FirstPage.html) as f:

for line in f:

if line = "":

f.write(ADDvideo)

break

这是第一页.html以下内容:

The first page

我希望这个脚本列出目录中的文件,将其中的所有图像/视频添加到HTML文件中,然后cd到那里的文件夹中,并递归地执行相同的操作。有什么建议吗?在

谢谢!在

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值