0

I got this Python script that reads media files from USB stick.

It used to run fine, today when I executing it with python path/to/main.py, it keeps giving me OS Error: [Errno 13] Permission denied: media/myName/usbName when the script runs the command os.listdir().

os.listdir() simply checks what folders and files are in the main folder. It doesn't write anything, so why is there a permission error?

I can use the USB stick just fine, open, add and delete files in it myself. I'm not very experienced with Linux, what might be the issue?

Some kind of permission, etc. setting for the script file or the usb drive that somehow magically changed without me doing anything?

Using Lubuntu 14.04.

1
  • This might give a hint: I installed the same OS on my laptop and ran the exact same script on it, no errors, no permission issues. Also, I just deleted every "folder" in /media/myName, plugged the drive and ran the script again. Ran fine. Why do the folders remain in media/myName after the drive is physically unplugged? Does that give a hint? Commented Sep 26, 2015 at 9:06

1 Answer 1

0

If you want to walk all the subfolders, then try os.walk. Following example shows how to use it.

import os for (dirPath, dirNames, fileNames) in os.walk(rootPath): for fileName in fileNames: filePath = dirPath + '\\' + fileName print(filePath) for dirName in dirNames: path = dirPath + '\\' + dirName print(path) 
0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.