I was coding sorter for downloads folder. I'm getting this error, I tried to change permissions:
chmod: Unable to change file mode on Users: Operation not permitted
import os
from_dir = os.path.dirname('/Users/user/Downloads/')
working_dir = os.walk(from_dir)
to_dir = os.path.dirname('/User/user/Downloads/New Folder/')
def move(folder):
for roots, dirs, files in folder:
for file in files:
src_folder = from_dir + '/' + file
to_folder = to_dir + '/' + file
if not os.path.exists(to_dir):
os.makedirs(to_dir)
os.rename(src_folder, to_folder)
move(working_dir)
Maybe there is another way to write this code just without touching root folders?
Full error:
Traceback (most recent call last):
File "/Users/beknazarnurbek/Documents/PycharmProjects/Move Files/move.py", line 19, in <module>
move(working_dir)
File "/Users/beknazarnurbek/Documents/PycharmProjects/Move Files/move.py", line 14, in move
os.makedirs(to_dir)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/os.py", line 211, in makedirs
makedirs(head, exist_ok=exist_ok)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/os.py", line 211, in makedirs
makedirs(head, exist_ok=exist_ok)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/os.py", line 211, in makedirs
makedirs(head, exist_ok=exist_ok)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/os.py", line 221, in makedirs
mkdir(name, mode)
OSError: [Errno 30] Read-only file system: '/User'
You have set writable permission to this folder. Just use in terminal chmod:
chmod -R 777 /absolute/path/to/your/folder