laonuo commited on
Commit
32e4bc9
Β·
unverified Β·
1 Parent(s): ec7c9bd

Organize dataset into subdirectories

Browse files
This view is limited to 50 files because it contains too many changes. Β  See raw diff
Files changed (50) hide show
  1. .gitignore +1 -0
  2. flatten_files.py +37 -0
  3. organize_files.py +32 -0
  4. test/{0033354.jpg β†’ 003/0033354.jpg} +0 -0
  5. test/{0033355.jpg β†’ 003/0033355.jpg} +0 -0
  6. test/{0033356.jpg β†’ 003/0033356.jpg} +0 -0
  7. test/{0033357.jpg β†’ 003/0033357.jpg} +0 -0
  8. test/{0033358.jpg β†’ 003/0033358.jpg} +0 -0
  9. test/{0033359.jpg β†’ 003/0033359.jpg} +0 -0
  10. test/{0033360.jpg β†’ 003/0033360.jpg} +0 -0
  11. test/{0033361.jpg β†’ 003/0033361.jpg} +0 -0
  12. test/{0033362.jpg β†’ 003/0033362.jpg} +0 -0
  13. test/{0033363.jpg β†’ 003/0033363.jpg} +0 -0
  14. test/{0033364.jpg β†’ 003/0033364.jpg} +0 -0
  15. test/{0033365.jpg β†’ 003/0033365.jpg} +0 -0
  16. test/{0033366.jpg β†’ 003/0033366.jpg} +0 -0
  17. test/{0033367.jpg β†’ 003/0033367.jpg} +0 -0
  18. test/{0033368.jpg β†’ 003/0033368.jpg} +0 -0
  19. test/{0033369.jpg β†’ 003/0033369.jpg} +0 -0
  20. test/{0033370.jpg β†’ 003/0033370.jpg} +0 -0
  21. test/{0033371.jpg β†’ 003/0033371.jpg} +0 -0
  22. test/{0033372.jpg β†’ 003/0033372.jpg} +0 -0
  23. test/{0033373.jpg β†’ 003/0033373.jpg} +0 -0
  24. test/{0033374.jpg β†’ 003/0033374.jpg} +0 -0
  25. test/{0033375.jpg β†’ 003/0033375.jpg} +0 -0
  26. test/{0033376.jpg β†’ 003/0033376.jpg} +0 -0
  27. test/{0033377.jpg β†’ 003/0033377.jpg} +0 -0
  28. test/{0033378.jpg β†’ 003/0033378.jpg} +0 -0
  29. test/{0033379.jpg β†’ 003/0033379.jpg} +0 -0
  30. test/{0033380.jpg β†’ 003/0033380.jpg} +0 -0
  31. test/{0033381.jpg β†’ 003/0033381.jpg} +0 -0
  32. test/{0033382.jpg β†’ 003/0033382.jpg} +0 -0
  33. test/{0033383.jpg β†’ 003/0033383.jpg} +0 -0
  34. test/{0033384.jpg β†’ 003/0033384.jpg} +0 -0
  35. test/{0033385.jpg β†’ 003/0033385.jpg} +0 -0
  36. test/{0033386.jpg β†’ 003/0033386.jpg} +0 -0
  37. test/{0033387.jpg β†’ 003/0033387.jpg} +0 -0
  38. test/{0033388.jpg β†’ 003/0033388.jpg} +0 -0
  39. test/{0033389.jpg β†’ 003/0033389.jpg} +0 -0
  40. test/{0033390.jpg β†’ 003/0033390.jpg} +0 -0
  41. test/{0033391.jpg β†’ 003/0033391.jpg} +0 -0
  42. test/{0033392.jpg β†’ 003/0033392.jpg} +0 -0
  43. test/{0033393.jpg β†’ 003/0033393.jpg} +0 -0
  44. test/{0033394.jpg β†’ 003/0033394.jpg} +0 -0
  45. test/{0033395.jpg β†’ 003/0033395.jpg} +0 -0
  46. test/{0033396.jpg β†’ 003/0033396.jpg} +0 -0
  47. test/{0033397.jpg β†’ 003/0033397.jpg} +0 -0
  48. test/{0033398.jpg β†’ 003/0033398.jpg} +0 -0
  49. test/{0033399.jpg β†’ 003/0033399.jpg} +0 -0
  50. 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