Skip to content

Instantly share code, notes, and snippets.

@magicshui
Created December 29, 2011 08:29
Show Gist options
  • Save magicshui/1532928 to your computer and use it in GitHub Desktop.
Save magicshui/1532928 to your computer and use it in GitHub Desktop.
move the desktop files to D disk
import os,shutil,sys,datetime
org_path=["C:\\Users\\AolneShui\\Desktop"]
des_path=["D:\\MyDesktop\\"+str(datetime.date.today())]
def MoveDirAndFiles(srcPath,dstPath):
allChangeFileList=os.listdir(srcPath)
for changeFileItem in allChangeFileList:
changeFilePath=os.path.join(srcPath,changeFileItem)
if(os.path.isdir(changeFilePath)):
dstAddPath=os.path.join(dstPath,changeFileItem)
if(os.path.exists(dstAddPath)):
try :
MoveDirAndFiles(changeFilePath,dstAddPath)
except :
print("Error:--->"+dstAddPath)
else:
try:
shutil.copytree(changeFilePath,dstAddPath,False)
shutil.rmtree(changeFilePath)
print("Moved:-->>"+dstAddPath)
except Exception as e:
print("Error:-->"+dstAddPath+":::>>>>"+str(e))
else:
try:
shutil.move(changeFilePath,dstPath)
print("Moved:-->>"+changeFilePath)
except Exception as e:
print("Error:--->"+changeFilePath+":::>>>>"+str(e))
def go():
if not os.path.exists(des_path[0]):
os.mkdir(des_path[0])
MoveDirAndFiles(org_path[0],des_path[0])
go()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment