-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathscript.py
More file actions
executable file
·29 lines (23 loc) · 827 Bytes
/
script.py
File metadata and controls
executable file
·29 lines (23 loc) · 827 Bytes
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
import os
def add_gitkeep(folder):
gitkeep_path = os.path.join(folder, '.gitkeep')
# Check if the folder is empty
if not os.listdir(folder):
# Check if .gitkeep file doesn't exist already
if not os.path.exists(gitkeep_path):
# Create the .gitkeep file
with open(gitkeep_path, 'w'):
pass
print(f'.gitkeep added to {folder}')
else:
print(f'{gitkeep_path} already exists in {folder}')
else:
print(f'{folder} is not empty')
def add_gitkeep_recursive(root_folder):
for root, dirs, files in os.walk(root_folder):
for d in dirs:
folder_path = os.path.join(root, d)
add_gitkeep(folder_path)
# Provide the root folder path here
root_folder = './'
add_gitkeep_recursive(root_folder)