2017-09-04 176 views
0

当我执行单个文件的命令时,它的工作原理。然而,当我想在循环中使用它时,它不起作用。可能是什么问题呢 ? 从子进口通话 进口操作系统,SYS传递exe文件到目录中的所有文件到Python

rootdir = r'C:\\Users\\X\\Desktop\\hump' 

for root, dirs, files in os.walk(rootdir): 
    for file in files: 
     if file.endswith(".ply"):    
      nf = file.replace('.ply', '.txt') 
      os.system("C:\\Users\\X\\Desktop\\fftw-3.3.5 dll64\\ShapeDescriptor.exe --in file --out nf") 
+1

忘记一分钟的子过程,并想象如果您只是想构造一个包含文件名的字符串,您会做什么。 –

+0

我添加了一些像file_name = os.path.join(根,文件),然后将它与下面的答案合并 – edyvedy13

回答

1

传递的filenf值系统调用。这可能是你正在寻找的那个。

os.system("C:\\Users\\X\\Desktop\\fftw-3.3.5 dll64\\ShapeDescriptor.exe --in {0} --out {1}".format(file,nf)) 
+0

我改变了最后一行,但仍然不能得到结果 – edyvedy13

+0

我明白这个问题,因为有空格输入文件... – edyvedy13

相关问题