简体   繁体   English

标签的使用不一致

[英]inconsistent use of tabs

I am trying to find all of the .mp3 and .mp4 files in my /Users/ directory in windows 7. Here is my code is bellow. 我试图在Windows 7的/ Users /目录中找到所有的.mp3和.mp4文件。这是我的代码如下。 An ideas on what to do?? 关于该怎么做的想法?

import os
newpath = r'C:\Users\Media' 
    if not os.path.exists(newpath):
      os.makedirs(newpath)
for root, dirs, files in os.walk("/Users"):
     for file in files:
         if file.endswith(".mp3"):
             print(os.path.join(root, file))
             os.rename(os.path.join(root, file), newpath)
for root, dirs, files in os.walk("/Users"):
    for file in files:
         if file.endswith(".mp4"):
             print(os.path.join(root, file))
             os.rename(os.path.join(root, file), newpath)  

Your code is pretty much correct, but the only thing is that, In the code given above there is a tab before first if statement, but that is not required in any sense. 你的代码非常正确,但唯一的是,在上面给出的代码中,在first if语句之前有一个选项卡,但在任何意义上都不需要。 That's why you are getting such an error. 这就是你得到这样一个错误的原因。 Please remove that tab or indentation so as to solve the problem. 请删除该选项卡或缩进以解决问题。 The corrected code will look like as follows: 更正后的代码如下所示:

import os
newpath = r'C:\Users\Media' 
if not os.path.exists(newpath):
      os.makedirs(newpath)
for root, dirs, files in os.walk("/Users"):
     for file in files:
         if file.endswith(".mp3"):
             print(os.path.join(root, file))
             os.rename(os.path.join(root, file), newpath)
for root, dirs, files in os.walk("/Users"):
    for file in files:
         if file.endswith(".mp4"):
             print(os.path.join(root, file))
             os.rename(os.path.join(root, file), newpath)  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM