Home > OS >  How to use "../" in VS CODE to acces a folder outside the current folder
How to use "../" in VS CODE to acces a folder outside the current folder

Time:06-27

I've been trying to access a folder outside my current folder, however when I Use "../images/image.png" it gives a FileNotFound error. Now running this code in IDLE gives no error and works perfectly. How can i use ../ in Vs code?

Using pygame.display.set_icon(pygame.image.load(f"./images/ui/logo.png")) which gives :- FileNotFoundError: No such file or directory. running it in IDLE 3.9, doesnt give me any error

CodePudding user response:

The first thing to understand is that if the code in vscode involves paths, everything is retrieved for the root directory based on the workspace. Even if you use "." in a deep directory under the workspace, this still represents the workspace directory, instead of the current directory.

So what we need to do is to change our thinking and import the files you want with the workspace as the root directory.

This also means that ".." will not appear in vscode. Because all the files we need are in the workspace, we will not use the parent directory outside the workspace.

For example,

"./images/ui/logo.png"

enter image description here

If you place it like this, you can retrieve the file anywhere in the workspace without complex positioning based on the current file.

You can refer to this issue. It has similar problems with you.

CodePudding user response:

I am assuming that both folders are in the same directory. This means that you should use “./“ instead of “../“ :)

  • Related