Skip to content

Instantly share code, notes, and snippets.

@AriTheElk
Last active December 15, 2015 06:28
Show Gist options
  • Save AriTheElk/5216118 to your computer and use it in GitHub Desktop.
Save AriTheElk/5216118 to your computer and use it in GitHub Desktop.
Recursively searches for files with the specified extension in the source folder and moves them into the destination folder. You can replace "fileExtension == extension" with "fileExtension != extension" to move every file except for the specified extension.
import sys, os
source = "./Source_Folder/"
destination = "./Destination_Folder/"
extension = ".xml"
fileList = []
for root, folders, files in os.walk(source):
for f in files:
fileName, fileExtension = os.path.splitext(os.path.join(root,f))
if (fileExtension == extension):
fileList.append(os.path.join(root,f))
for f in fileList:
os.rename(f,destination + f.split('/')[-1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment