Skip to content

Instantly share code, notes, and snippets.

@calvinnor
Created September 25, 2019 14:41
Show Gist options
  • Save calvinnor/b1056e23e0df2aa5baa1a1a109ea2f65 to your computer and use it in GitHub Desktop.
Save calvinnor/b1056e23e0df2aa5baa1a1a109ea2f65 to your computer and use it in GitHub Desktop.
Move Drawables Between 2 Modules
import os
from shutil import move
sourceDirectory = input("Enter Source Directory eg: app/src/main/res: ")
destinationDirectory = input("Destination Directory eg: feature/src/main/res: ")
drawableFileName = input("Drawable File Name With Extension: ")
fileAbsolutePathsToMove = []
directoryPathsToMove = []
print()
print("--------------------------------------")
print("----------- Starting Move ------------")
print("--------------------------------------")
print()
# Find the files matching our input
for dirPath, dirNames, fileNames in os.walk(sourceDirectory):
sourceDirectoryPath = dirPath[len(sourceDirectory):]
for fileName in [f for f in fileNames]:
if fileName == drawableFileName:
directoryPathsToMove.append(sourceDirectoryPath)
fileAbsolutePathsToMove.append(os.path.join(dirPath, fileName))
print("Found file at directories:", directoryPathsToMove)
# Move files to destination
for fileIndex in range(0, len(fileAbsolutePathsToMove)):
fileAbsolutePath = fileAbsolutePathsToMove[fileIndex]
directoryToMake = directoryPathsToMove[fileIndex]
absoluteDirectoryToMake = destinationDirectory + directoryToMake
# Create directory if not exists
if not os.path.exists(absoluteDirectoryToMake):
os.makedirs(absoluteDirectoryToMake)
# finally move the file
move(fileAbsolutePath, os.path.join(absoluteDirectoryToMake, drawableFileName))
print()
print("--------------------------------------")
print("----------- Completed Move -----------")
print("--------------------------------------")
print()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment