laonuo commited on
Organize dataset into subdirectories
Browse filesThis view is limited to 50 files because it contains too many changes. Β
See raw diff
- .gitignore +1 -0
- flatten_files.py +37 -0
- organize_files.py +32 -0
- test/{0033354.jpg β 003/0033354.jpg} +0 -0
- test/{0033355.jpg β 003/0033355.jpg} +0 -0
- test/{0033356.jpg β 003/0033356.jpg} +0 -0
- test/{0033357.jpg β 003/0033357.jpg} +0 -0
- test/{0033358.jpg β 003/0033358.jpg} +0 -0
- test/{0033359.jpg β 003/0033359.jpg} +0 -0
- test/{0033360.jpg β 003/0033360.jpg} +0 -0
- test/{0033361.jpg β 003/0033361.jpg} +0 -0
- test/{0033362.jpg β 003/0033362.jpg} +0 -0
- test/{0033363.jpg β 003/0033363.jpg} +0 -0
- test/{0033364.jpg β 003/0033364.jpg} +0 -0
- test/{0033365.jpg β 003/0033365.jpg} +0 -0
- test/{0033366.jpg β 003/0033366.jpg} +0 -0
- test/{0033367.jpg β 003/0033367.jpg} +0 -0
- test/{0033368.jpg β 003/0033368.jpg} +0 -0
- test/{0033369.jpg β 003/0033369.jpg} +0 -0
- test/{0033370.jpg β 003/0033370.jpg} +0 -0
- test/{0033371.jpg β 003/0033371.jpg} +0 -0
- test/{0033372.jpg β 003/0033372.jpg} +0 -0
- test/{0033373.jpg β 003/0033373.jpg} +0 -0
- test/{0033374.jpg β 003/0033374.jpg} +0 -0
- test/{0033375.jpg β 003/0033375.jpg} +0 -0
- test/{0033376.jpg β 003/0033376.jpg} +0 -0
- test/{0033377.jpg β 003/0033377.jpg} +0 -0
- test/{0033378.jpg β 003/0033378.jpg} +0 -0
- test/{0033379.jpg β 003/0033379.jpg} +0 -0
- test/{0033380.jpg β 003/0033380.jpg} +0 -0
- test/{0033381.jpg β 003/0033381.jpg} +0 -0
- test/{0033382.jpg β 003/0033382.jpg} +0 -0
- test/{0033383.jpg β 003/0033383.jpg} +0 -0
- test/{0033384.jpg β 003/0033384.jpg} +0 -0
- test/{0033385.jpg β 003/0033385.jpg} +0 -0
- test/{0033386.jpg β 003/0033386.jpg} +0 -0
- test/{0033387.jpg β 003/0033387.jpg} +0 -0
- test/{0033388.jpg β 003/0033388.jpg} +0 -0
- test/{0033389.jpg β 003/0033389.jpg} +0 -0
- test/{0033390.jpg β 003/0033390.jpg} +0 -0
- test/{0033391.jpg β 003/0033391.jpg} +0 -0
- test/{0033392.jpg β 003/0033392.jpg} +0 -0
- test/{0033393.jpg β 003/0033393.jpg} +0 -0
- test/{0033394.jpg β 003/0033394.jpg} +0 -0
- test/{0033395.jpg β 003/0033395.jpg} +0 -0
- test/{0033396.jpg β 003/0033396.jpg} +0 -0
- test/{0033397.jpg β 003/0033397.jpg} +0 -0
- test/{0033398.jpg β 003/0033398.jpg} +0 -0
- test/{0033399.jpg β 003/0033399.jpg} +0 -0
- test/{0033400.jpg β 003/0033400.jpg} +0 -0
.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
.specstory
|
flatten_files.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import shutil
|
| 3 |
+
|
| 4 |
+
def flatten_directory(path):
|
| 5 |
+
"""
|
| 6 |
+
Flattens the directory structure by moving files from subdirectories to the parent directory.
|
| 7 |
+
"""
|
| 8 |
+
print(f"Flattening files in: {path}")
|
| 9 |
+
if not os.path.isdir(path):
|
| 10 |
+
print(f"Error: Directory not found at {path}")
|
| 11 |
+
return
|
| 12 |
+
|
| 13 |
+
# Walk through the directory
|
| 14 |
+
for dirpath, dirnames, filenames in os.walk(path):
|
| 15 |
+
# Don't process the root directory itself in the first iteration
|
| 16 |
+
if dirpath == path:
|
| 17 |
+
continue
|
| 18 |
+
|
| 19 |
+
for filename in filenames:
|
| 20 |
+
# Construct full old and new paths
|
| 21 |
+
old_file_path = os.path.join(dirpath, filename)
|
| 22 |
+
new_file_path = os.path.join(path, filename)
|
| 23 |
+
|
| 24 |
+
# Move the file to the parent directory
|
| 25 |
+
shutil.move(old_file_path, new_file_path)
|
| 26 |
+
print(f"Moved: {old_file_path} -> {new_file_path}")
|
| 27 |
+
|
| 28 |
+
# After moving all files, if the subdirectory is empty, remove it
|
| 29 |
+
if not os.listdir(dirpath):
|
| 30 |
+
os.rmdir(dirpath)
|
| 31 |
+
print(f"Removed empty directory: {dirpath}")
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
if __name__ == "__main__":
|
| 35 |
+
flatten_directory('train')
|
| 36 |
+
flatten_directory('test')
|
| 37 |
+
print("File flattening complete.")
|
organize_files.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import shutil
|
| 3 |
+
|
| 4 |
+
def organize_directory(path):
|
| 5 |
+
"""
|
| 6 |
+
Organizes files in a directory into subdirectories based on the first 3 characters of the filename.
|
| 7 |
+
"""
|
| 8 |
+
print(f"Organizing files in: {path}")
|
| 9 |
+
if not os.path.isdir(path):
|
| 10 |
+
print(f"Error: Directory not found at {path}")
|
| 11 |
+
return
|
| 12 |
+
|
| 13 |
+
for filename in os.listdir(path):
|
| 14 |
+
file_path = os.path.join(path, filename)
|
| 15 |
+
if os.path.isfile(file_path):
|
| 16 |
+
# Create subdirectory based on the first 3 characters
|
| 17 |
+
subdir_name = filename[:3]
|
| 18 |
+
subdir_path = os.path.join(path, subdir_name)
|
| 19 |
+
|
| 20 |
+
if not os.path.exists(subdir_path):
|
| 21 |
+
os.makedirs(subdir_path)
|
| 22 |
+
print(f"Created directory: {subdir_path}")
|
| 23 |
+
|
| 24 |
+
# Move the file
|
| 25 |
+
new_file_path = os.path.join(subdir_path, filename)
|
| 26 |
+
shutil.move(file_path, new_file_path)
|
| 27 |
+
print(f"Moved: {file_path} -> {new_file_path}")
|
| 28 |
+
|
| 29 |
+
if __name__ == "__main__":
|
| 30 |
+
organize_directory('train')
|
| 31 |
+
organize_directory('test')
|
| 32 |
+
print("File organization complete.")
|
test/{0033354.jpg β 003/0033354.jpg}
RENAMED
|
File without changes
|
test/{0033355.jpg β 003/0033355.jpg}
RENAMED
|
File without changes
|
test/{0033356.jpg β 003/0033356.jpg}
RENAMED
|
File without changes
|
test/{0033357.jpg β 003/0033357.jpg}
RENAMED
|
File without changes
|
test/{0033358.jpg β 003/0033358.jpg}
RENAMED
|
File without changes
|
test/{0033359.jpg β 003/0033359.jpg}
RENAMED
|
File without changes
|
test/{0033360.jpg β 003/0033360.jpg}
RENAMED
|
File without changes
|
test/{0033361.jpg β 003/0033361.jpg}
RENAMED
|
File without changes
|
test/{0033362.jpg β 003/0033362.jpg}
RENAMED
|
File without changes
|
test/{0033363.jpg β 003/0033363.jpg}
RENAMED
|
File without changes
|
test/{0033364.jpg β 003/0033364.jpg}
RENAMED
|
File without changes
|
test/{0033365.jpg β 003/0033365.jpg}
RENAMED
|
File without changes
|
test/{0033366.jpg β 003/0033366.jpg}
RENAMED
|
File without changes
|
test/{0033367.jpg β 003/0033367.jpg}
RENAMED
|
File without changes
|
test/{0033368.jpg β 003/0033368.jpg}
RENAMED
|
File without changes
|
test/{0033369.jpg β 003/0033369.jpg}
RENAMED
|
File without changes
|
test/{0033370.jpg β 003/0033370.jpg}
RENAMED
|
File without changes
|
test/{0033371.jpg β 003/0033371.jpg}
RENAMED
|
File without changes
|
test/{0033372.jpg β 003/0033372.jpg}
RENAMED
|
File without changes
|
test/{0033373.jpg β 003/0033373.jpg}
RENAMED
|
File without changes
|
test/{0033374.jpg β 003/0033374.jpg}
RENAMED
|
File without changes
|
test/{0033375.jpg β 003/0033375.jpg}
RENAMED
|
File without changes
|
test/{0033376.jpg β 003/0033376.jpg}
RENAMED
|
File without changes
|
test/{0033377.jpg β 003/0033377.jpg}
RENAMED
|
File without changes
|
test/{0033378.jpg β 003/0033378.jpg}
RENAMED
|
File without changes
|
test/{0033379.jpg β 003/0033379.jpg}
RENAMED
|
File without changes
|
test/{0033380.jpg β 003/0033380.jpg}
RENAMED
|
File without changes
|
test/{0033381.jpg β 003/0033381.jpg}
RENAMED
|
File without changes
|
test/{0033382.jpg β 003/0033382.jpg}
RENAMED
|
File without changes
|
test/{0033383.jpg β 003/0033383.jpg}
RENAMED
|
File without changes
|
test/{0033384.jpg β 003/0033384.jpg}
RENAMED
|
File without changes
|
test/{0033385.jpg β 003/0033385.jpg}
RENAMED
|
File without changes
|
test/{0033386.jpg β 003/0033386.jpg}
RENAMED
|
File without changes
|
test/{0033387.jpg β 003/0033387.jpg}
RENAMED
|
File without changes
|
test/{0033388.jpg β 003/0033388.jpg}
RENAMED
|
File without changes
|
test/{0033389.jpg β 003/0033389.jpg}
RENAMED
|
File without changes
|
test/{0033390.jpg β 003/0033390.jpg}
RENAMED
|
File without changes
|
test/{0033391.jpg β 003/0033391.jpg}
RENAMED
|
File without changes
|
test/{0033392.jpg β 003/0033392.jpg}
RENAMED
|
File without changes
|
test/{0033393.jpg β 003/0033393.jpg}
RENAMED
|
File without changes
|
test/{0033394.jpg β 003/0033394.jpg}
RENAMED
|
File without changes
|
test/{0033395.jpg β 003/0033395.jpg}
RENAMED
|
File without changes
|
test/{0033396.jpg β 003/0033396.jpg}
RENAMED
|
File without changes
|
test/{0033397.jpg β 003/0033397.jpg}
RENAMED
|
File without changes
|
test/{0033398.jpg β 003/0033398.jpg}
RENAMED
|
File without changes
|
test/{0033399.jpg β 003/0033399.jpg}
RENAMED
|
File without changes
|
test/{0033400.jpg β 003/0033400.jpg}
RENAMED
|
File without changes
|