-2

I have built a flask application which I have uploaded to cloud server, precisely ubuntu 18.04, in one of my python file i have reference a folder which for example the name of the folder is blog_details

but after assigning a variable name and even use path to point to the folder, yet the server is telling me file or folder not found

mind you i have change the ownership of the folder and the folder before it to the user of the server and not the root

FOLDER_NAME = "blog_details/"
path = os.getcwd() + FOLDER_NAME
os.chdir(path)

please is there a way to do this? and also is there a way to create a txt file the server also returns file not found, right from my python svript i never had any of this issue in my windows 10

 with open('content2.txt', 'w') as f:
       f.write(title + '\n\n')

Thanks in advance

nath
  • 123
  • 2
  • 9
  • When the computer tells you a file doesn’t exist, it’s nearly always right. A typical beginner mistake is supplying the wrong directory name. Your question contains no information to help us tell you the correct path. Maybe read [Difference between `./` and `~/`](https://stackoverflow.com/a/55342466/874188) – tripleee Aug 22 '20 at 18:27
  • if you follow up my explanation, thesame code works fine on my windows machine.... have you push your code to a cloud instance before? if so you would undertsand what i'm trying to say, a working code on you machine might get to a linux server and returns a n erro, which is quite common – nath Aug 22 '20 at 18:29
  • We can help you figure out the correct path if you supply enough information to help us help you. – tripleee Aug 22 '20 at 18:31
  • /home/medium/blog_details this is the full path – nath Aug 22 '20 at 19:37
  • server may start code from different folder then you expect and you should check what you get with `print( os.gecwd() )`. You can also display `os.listdir( os.getcwd() )` to see what you have in this folder. If you know full path then use it instead of `os.getcwd() + FOLDER_NAME`. In other questions you can find how to use `sys.argv` with `os.path.dirname()` and `os.path.abspath()` to get real folder with code and problably with your data. – furas Aug 22 '20 at 22:54
  • BTW: `os.getcwd()` gives path without `/` and the end and you may need to add `/` like `os.getcwd() + '/' + FOLDER_NAME` or better `os.path.join(os.getcwd(), FOLDER_NAME)`. Your current code may search `/home/mediumblog_detail` instead of `/home/medium/blog_detail` – furas Aug 22 '20 at 22:59
  • thank you for your advice, it works fine now – nath Aug 23 '20 at 05:00

1 Answers1

0

i was able to fix this

**

FOLDER_NAME = "/home/medium/blog_details"
path = os.getcwd()
new_path = path + FOLDER_NAME

**

nath
  • 123
  • 2
  • 9