python 文件和目录示例

python 文件和目录示例:

# coding: utf-8
import os 
import shutil  


#硬盘的电影目录
FindPath0=u"E:/电影/2012电影"
filenames0=os.listdir(FindPath0) 


#U盘的电影目录
FindPath1=u"F:/电影"
#目录不存在就创建
if not(os.path.exists(FindPath1)):  
    os.makedirs(FindPath1)

filenames1=os.listdir(FindPath1) 



#保存所有已近看过的电影
AreadySeeMoviePath=u"E:/电影/2012电影_已看过的"
#目录不存在就创建
if not(os.path.exists(AreadySeeMoviePath)):  
    os.makedirs(AreadySeeMoviePath)

#自动处理已看过的电影并把未看过的电影放入U盘
for name0 in filenames0:
    
    movefilePath=os.path.join(FindPath0,name0) 
    print("movefilePath")  
    
    for name1 in filenames1:
        if (name0==name1):
            #移动文件到AreadySeeMoviePath
            tmpfile=os.path.join(AreadySeeMoviePath,name0)             
            shutil.copy(movefilePath, tmpfile)
            os.remove(movefilePath)
            print("Move File")


以上只是个简单示例,用于将看过的电影移动到一个新的文件夹中

你可能感兴趣的:(python 文件和目录示例)