gpt4 book ai didi

Python subprocess.call - 添加一个变量到 subprocess.call

转载 作者:太空宇宙 更新时间:2023-11-04 09:10:53 27 4
gpt4 key购买 nike

<分区>

我正在尝试用 Python 编写一个简单的程序,从我的下载文件夹中获取所有音乐文件并将它们放入我的音乐文件夹中。我使用的是 Windows,我可以使用 cmd 提示符移动文件,但出现此错误:

WindowsError: [错误 2] 系统找不到指定的文件

这是我的代码:

#! /usr/bin/python

import os
from subprocess import call

def main():
os.chdir("C:\\Users\Alex\Downloads") #change directory to downloads folder

suffix =".mp3" #variable holdinng the .mp3 tag
fnames = os.listdir('.') #looks at all files

files =[] #an empty array that will hold the names of our mp3 files

for fname in fnames:
if fname.endswith(suffix):
pname = os.path.abspath(fname)
#pname = fname
#print pname

files.append(pname) #add the mp3 files to our array
print files

for i in files:
#print i
move(i)

def move(fileName):
call("move /-y "+ fileName +" C:\Music")
return

if __name__=='__main__':main()

我看过 subprocess图书馆和无数其他文章,但我仍然不知道我做错了什么。

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com