我试图通过Windows 10的命令行,以Python或VBA代码,用Winrar自动归档一个目录中的文件夹。 考虑到可能有空格,我把所有路径都用引号括起来。
然而我在Python或VBA中都遇到了同样的错误。
"'C:/Program'未被识别为内部或外部命令、可操作程序或批处理文件。"
下面是一个未完成的Python代码尝试样本。
def folders_2_Winrar(source_path:str, archive_path:str, password:str='', winrar_path:str='"C:/Program Files/WinRAR/winrar.exe"')->None:
import os
folder_list = path_entries(source_path)['folders'] ## separate function that returns a list of folders in a directory
for f in folder_list:
rar = '"'+ archive_path + os.path.basename(f) +'.rar'+'"'
f = r'"'+f+'\*.*"'
cmd = winrar_path+' a -hp' + password + ' -ep1 ' + rar + ' ' + f
os.system(cmd)
# test the function
folders_2_Winrar("E:/Test/Source", "E:/Test\\Archive/","123")
有什么问题是我不能掌握的?