# Define the folder sources and destinations
MainDir = 'C:/Test/'
LoadingDir = 'C:/Test/Loading/'
ArchiveDir = 'C:/Test/Archive/'
#-----------------------------------------------------------------------------------------------------------------------
# Function to move only .json files from main directory into Loading directory
#-----------------------------------------------------------------------------------------------------------------------
def MoveToLoading(MainDir, LoadingDir):
# Verify if MainDir and ArchiveDir exist as directories
os.mkdir(LoadingDir)
if os.path.isdir(MainDir) and os.path.isdir(LoadingDir):
# Count the number of files in Main drectory
Mcount = len(glob.glob1(MainDir,"*.json"))
# Iterate over all json files in main directory
for filePath in glob.glob(MainDir + '\*json'):
# Move each json file to Loading directory
shutil.move(filePath, LoadingDir);
# Print number of files that are moved from Main to Loading Directory
print(str(Mcount) + " " + "Files are moved from Main to Loading Directory")
else:
# Print if no files were present to move
print("Loading or Main directory doesnt exist")