makedirs gives OSError: [Errno 13] Permission denied: '/pdf_files'

Babel picture Babel · Sep 1, 2015 · Viewed 19.6k times · Source

I'm trying to create a folder inside a folder, first I check if that directory exists and create it if necessary:

name = "User1"
if not os.path.exists("/pdf_files/%s" % name):
    os.makedirs('/pdf_files/%s' % name )

Problem is that i'm getting an error : OSError: [Errno 13] Permission denied: '/pdf_files'

This folder named: pdf_file that I created have all permissions: drwxrwxrwx or '777'

I searched about this and I saw some solutions but none of them solved my problem. Can somebody help me ?

Answer

Aleksandr Kovalev picture Aleksandr Kovalev · Sep 1, 2015

You are trying to create your folder inside root directory (/).

Change /pdf_files/%s to pdf_files/%s or /home/username/pdf_files/%s