Я получаю следующие ошибки:
Traceback (most recent call last):
File "file_mover.py", line 41, in <module>
shutil.copy(f, os.path.join(path_to_export_two, Path("/image/")))
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\shutil.py", line 245, in copy
copyfile(src, dst, follow_symlinks=follow_symlinks)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\shutil.py", line 120, in copyfile
with open(src, 'rb') as fsrc:
FileNotFoundError: [Errno 2] No such file or directory: '8ballshake1@8x.png'
При выполнении этого кода:
# Making the substrings is more difficult then anticipated prolly just use Java tbh
# LOWERCASE, LOWERCASE THE FOLDERS
import shutil
import os
from pathlib import Path
assets_path = Path("/Users/Jackson Clark/Desktop/uploads")
export_path = Path("/Users/Jackson Clark/Desktop/uploads")
source = os.listdir(assets_path)
"""
NOTE: Filters.js is the important file
The logic:
- Go through each file in the assets_path directory
- Rename the files to start with RoCode (this could be a seperate script)
- Create a new directory with the first four characters of the files name
- Create two sub directories with the names 'image' and 'thumb'
- Copy the file to both the 'image' and 'thumb' directories
That should be all, but who knows tbh
"""
"""
Good links:
https://www.pythonforbeginners.com/os/python-the-shutil-module
https://stackabuse.com/creating-and-deleting-directories-with-python/
"""
for f in source:
f_string = str(f)
folder_one_name = f_string[0:2]
folder_two_name = f_string[2:4]
path_to_export_one = os.path.join(export_path, folder_one_name)
path_to_export_two = os.path.join(export_path, folder_one_name, folder_two_name)
os.mkdir(path_to_export_one)
os.mkdir(path_to_export_two)
os.mkdir(os.path.join(path_to_export_two, Path("/image/")))
os.mkdir(os.path.join(path_to_export_two, Path("/thumb/")))
shutil.copy(f, os.path.join(path_to_export_two, Path("/image/")))
shutil.copy(f, os.path.join(path_to_export_two, Path("/thumb/")))
Мне просто нужен код для создания двух папок, первая из которых названа первыми двумясимволы файла, который читает скрипт, а вторая папка (которая является подпапкой первой) с именами 3-й и 4-й символы имени файла, который читает скрипт.Увы, я получаю ошибки выше.