0

I tried using open but it gives an error that the folder doesn't exist, which makes no sense since this is a command to create a folder, not read one. I saw Automatically creating directories with file output, but there is an error saying this is a Errno 30: Read only system: "/folder". Does anyone know how to avoid Error 30?

My code so far:

import os
filename = "/folder/y.txt"
os.makedirs(os.path.dirname(filename), exist_ok=True)
with open(filename, "w") as f:
    f.write("FOOBAR")
martineau
  • 119,623
  • 25
  • 170
  • 301
Superman123
  • 11
  • 1
  • 3
  • 3
    You don't have write access. – tobias Jul 10 '21 at 21:30
  • 1
    Does this answer your question? [create new folder in python with pathlib and write files into it](https://stackoverflow.com/questions/47518669/create-new-folder-in-python-with-pathlib-and-write-files-into-it) – sehan2 Jul 10 '21 at 21:31
  • @sehan2: That's not the same problem — so, no, it doesn't answer the question. – martineau Jul 10 '21 at 21:46
  • I get the similar problem but code works when I use `"/home/furas/y.txt"` Problem can be that you create folder in main folder `/` and it may have special setting in system for security reason - and maybe this folder already existed before you you use `makedirs` - and because you use `exist_ok=True` so it would run it without error when folder already exist. Better create folders in your home folder. – furas Jul 10 '21 at 23:58
  • I get the similar problem but code works when I use `"/home/furas/y.txt"` Problem can be that you create folder in main folder `/` and it may have special setting in system for security reason. And maybe this folder already existed (with read only settings) before you used `makedirs` - and because you use `exist_ok=True` so it would run without error message so it could look like it created this folder. Better create folders in your home folder. – furas Jul 11 '21 at 00:05
  • Use `filename = "folder/y.txt"`. The leading `/` in your code tries to make a folder at the root of the file system. – Timus Jul 11 '21 at 10:32

1 Answers1

0

I figured i just shouldn't put the slash behind the "folder"filename = "folder/y.txt" os.makedirs(os.path.dirname(filename), exist_ok=True) with open(filename, "w") as f: f.write("FOOBAR")

Superman123
  • 11
  • 1
  • 3