14

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 ?

Babel
  • 589
  • 2
  • 9
  • 23

2 Answers2

30

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

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

Aleksandr Kovalev
  • 3,508
  • 4
  • 34
  • 36
1

if you are trying to create your folder inside root directory (/), another simple way could be to add '.' before that. so say your /directory becomes ./directory

Ruchit Dalwadi
  • 311
  • 1
  • 2
  • 13