-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathffc.py
33 lines (26 loc) · 1.14 KB
/
ffc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import os
import shutil
import argparse
def file_folder_creator(directory):
# List all files in the directory
files = os.listdir(directory)
# Iterate over each file
for file in files:
# Get the full path of the file
file_path = os.path.join(directory, file)
# Check if it is a file (not a subdirectory)
if os.path.isfile(file_path):
# Extract the file name without extension
file_name = os.path.splitext(file)[0]
# Create a folder with the same name as the file (if it doesn't exist)
folder_path = os.path.join(directory, file_name)
os.makedirs(folder_path, exist_ok=True)
# Move the file to the created folder
new_file_path = os.path.join(folder_path, file)
shutil.move(file_path, new_file_path)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Create Folders for each file in the given directory')
parser.add_argument('directory_path', type=str,
help='Path to directory containing files.')
args = parser.parse_args()
file_folder_creator(args.directory_path)