linux - 循环不解压我的文件...代码不进入循环

标签 linux python-2.7 ftplib unrar

大家早上好

我的代码有问题。我会解释,我在我的 linux 实例上有一个本地 FTP 服务器的连接。我想探索我所有的目录以解压缩我的文件“.rar”,但是当我启动我的脚本时,只有目录显示正在工作。

我不知道为什么。

def showDirectories(ftp):

  output=' /var/www/folder/Output'
  ftp.cwd('/FolderFiles')
  ftp.retrlines('LIST')
  directories = ftp.nlst()

  if directories not in ['..', '.']:
    i=0
    while i < len(directories):
      folder = directories[i]+'/'
      i+=1
      for root, dirs, files in os.walk(folder, topdown=False):
        for name in files:
          rarFiles=os.path.join(root, name)
          print(rarFiles)
          unrar = "unrar x "+rarFiles+output
          print("unrar commande"+str(unrar))
          download= os.system(unrar)
          print(download)
        ftp.cwd('..')
      print("")

结果如下:

[root@ip-10-0-2-52 folder]# python test.py
Connected! Welcome msg is "220 (vsFTPd 3.0.2)"
Connected !

drwxr-xr-x    2 0        0              90 Feb 11 14:42 DescriptiveData
drwxr-xr-x    2 0        0              75 Feb 11 14:42 Financials
drwxr-xr-x    2 0        0              87 Feb 11 14:42 OwnershipHisto

谢谢你的帮助

最佳答案

感谢您的帮助,我终于找到了使我的脚本正常工作的解决方案。

这是我的更新

def downloadFile(path,target):

  for root, dirs, files in os.walk(path, topdown=False):
    for name in files:
      rarFiles=os.path.join(root, name)
      print(rarFiles)
      unrar = "unrar x "+rarFiles+target
      print("unrar commande"+str(unrar))
      download= os.system(unrar)
      print(download)

downloadFile('*****','*****')

关于linux - 循环不解压我的文件...代码不进入循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54668496/

相关文章:

python - 使用 Python ftplib 完成 FTPS 传输后出错

linux - OS X/Linux 上的 bash 脚本练习

linux - Unix/Linux - 多个应用程序使用相同的环境变量但值不同?

c - gcc: -DVAR=-linux 在 Linux 上未按预期工作

python - 抓取维基百科信息框的一部分

python - 如何将字符串仅附加到列表中的辅音?

python - 在导入之前/期间注入(inject)变量

python - 使用 ftplib 进行多线程上传

python - Python FTP 应用程序中的代理

regex - 如何从文件中复制正则表达式匹配项?需要从日志文件中获取所有 MAC 地址