Create a new file with code

str = input('Input text here') str += "\n" file = open('data/t.txt', 'w') file.write(str) file.close() 

Everything works well, I check the data folder - there is a file. Then I change w to a to add something to the file and get the error "[Errno 2] No such file or directory". Again, changing to w - also does not work. I tried to prescribe the path in different ways, including the absolute path. It turns out just as well. When you create a new file with a code, it also creates a text file and the code stops working. The folder is not on the C drive. Tell me, please, what could be the problem?

  • one
    Give the code to reproduce the problem. - Mikhail Murugov

1 answer 1

Pointing

not on drive C

Did you mean shared drive?

In any case, the problem is most likely with cunningly specified access rights. In this case, you can create files, but you can not modify them.

Try running:

 icacls data 

and check your access rights.

Here you can read about icacls.

  • In my case, it helped launch the console as an administrator, then the code starts to work. Thank. - Anaichka