Created
April 17, 2020 21:27
-
-
Save mujeebishaque/340683c669d65db0cc7fce182c075ed7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import os | |
parser = argparse.ArgumentParser(description="Python3 script to create folders") | |
parser.add_argument("-o", "--output_dir", type=str, required=False, help="Add path to output folder") | |
parser.add_argument("-n", "--number_of_folders", type=int, required=True, help="Total number of folders") | |
args = vars(parser.parse_args()) | |
CONFIRMED = False | |
SUCCESS = False | |
if args['number_of_folders'] == 0 or args['number_of_folders'] < 0: | |
print(""" | |
ERRORS | |
---------------------------------------------------------------- | |
1 ---> Make sure that number of folders parameter i.e. -n flag has value greater than 0. | |
2 ---> You might have entered a negative number. | |
EXITING | |
---------------------------------------------------------------- | |
""") | |
exit() | |
if not args['output_dir'] or args['output_dir'] == '': | |
print( | |
''' | |
ISSUES | |
------------------------------------------------------------ | |
1 ---> No output directory specified. Folders will be created in current directory. | |
Do you want to proceed[Yes/No]? | |
''' | |
) | |
user_input = str(input()) | |
if user_input.lower() == 'yes' or user_input.lower() == 'y': | |
CONFIRMED = True | |
else: | |
print("---> Exiting Program") | |
exit() | |
if CONFIRMED: | |
current_folder = None | |
for folder in range(int(args['number_of_folders'])): | |
if not os.path.exists(os.getcwd() + os.sep + "folder_{folder}") and not os.path.isdir(os.getcwd() + os.sep + "folder_{folder}"): | |
current_folder = f"folder_{folder}" | |
try: | |
os.mkdir(f"folder_{folder}") | |
except: | |
print("Folder with same name is already present. continue and proceed to create new or stop?[Yes/No]") | |
user_input = str(input()) | |
if user_input.lower() == 'yes' or user_input.lower() == 'y': | |
os.rmdir(f"folder_{folder}") | |
os.mkdir(f"folder_{folder}") | |
SUCCESS = True | |
if SUCCESS: | |
print("Folder[s] created successfullly!") | |
else: | |
print("Unable to create folders!") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment