I know this is probably a very common question, and I've already seen posts, here, here and here asking similar questions. But these posts relate to writing to a file. I want to create a file in a specific directory.
Specifically, I am trying to populate a folder with many .mp3 files.
Here's what I've tried so far:
import os
if not os.path.isdir('testing'):
os.mkdir('testing')
dir_path = 'testing'
file_path = 'foo.mp3'
with open(dir_path, 'x') as f:
f.write(file_path, os.path.basename(file_path))
I tried 'x' because I saw here that this creates a file and raises an error if the file does not exist. I am not getting this error, but I am getting this:
PermissionError: [Errno 13] Permission denied: 'testing'
I saw in the first post I've linked that this happens when I'm trying to "open a file, but my path is a folder". I am not trying to open a file though, I am trying to open a directory and add a file to that directory.
I also looked at the answer to this post, but the answerer is writing to a file not creating a file.
I might be overcomplicating things. Everything I could look up online has to do with writing to a file, not creating a file. I'm sure the task is very simple. What have I done wrong?