List files in a folder, in the parent directory - python-3.x

I know you can list the files of a directory with:
os.listdir('FOLDER_DIR')
But how do i list the files in a folder that exists in a directory above where i am right now?
For example, consider the following folder structure:
----PARENT
-------sub_dir1
-------sub_dir2
If my python program is in sub_dir2, how can i list the contents of folder sub_dir1, without changing directory?

The answer is os.listdir('../sub_dir1')

Related

How to write files of the same name to a directory using Python

I would like to write files of the same name to a directory using Python. Like when downloading the same file from a browser.
I have an existing directory containing the files "aaa.py" and "aaa(1).py".
I would like to add several versions of a file named "aa.py".
The resulting directory should contain:
"aaa.py"
"aaa(1).py"
"aa.py"
"aa(1).py"
"aa(2).py"
etc.

How can I find ._6182142_V1.csv in my folder?

I write this code in jupyther with python, to get the files in the folder
import os
path, dirs, files = next(os.walk("/Volumes/Samsung_T5/6182142"))
print(files)
and I get this result
Files in the folder
But I don't understand why this file "._6182142_V1.csv" is displayed to me even though I can't see it in the folder.
Real Folder
Can someone tell me how to view this file in the folder?
Thank you
A file starting with ._ is likely hidden on your OS. If you view the hidden files, you should see it.

Find and list all files/folders in a folder in Haxe

This question is in principal the same like these ones here
How to read all files in a folder from Java?
How do I list all files of a directory?
...
But is there a way to do the same in on sys target platforms in Haxe, without running ls / dir via sys.io.Process and parsing the results?
Yes, you can use sys.FileSystem.readDirectory(path) for this.
Returns the names of all files and directories in the directory specified by path.
If path does not denote a valid directory, an exception is thrown.
If path is null, the result is unspecified.
If you need files to be listed recursively, this article from the Haxe Code Cookbook is a good reference (there's a section titled "Recursive loop through all directories / files").

how to always open a file in your project folder

Right now, whenever I open a file in my python folder, I would have to do this:
f = open("/Users/LazyLinh/PycharmProjects/TimeGenGUI/mass.mas12.txt", "r")
Even though TimeGenGUI is my python folder, and the file mass.mas12.txt does show up under my project files. Is there a way I can always address this file as part of my python folder or find the full directory of this file, as the full directory can change if I change the folder's location?
Thank you!
Oh thanks to #zondo's recommendation, I've figured out the problem. My __init__.py is in a package under TimeGenGUI, so as soon as I put the file into the folder for this package instead of parent folder TimeGenGUI, I can use open("mass.mas12.txt", "r")!

no such file or directory (cygwin)

I am trying to install a solver (SCIP) with cygwin. After unpacking the folder consists of another 5 folders. The manual says I have to go in folder A and use make. Here, I get the message that one file was not found:
zimpl/bool.h: No such file or directory
This file is in folder B in the path zimpl/src/bool.h. How can I link this file from folder B that cygwin can use it while using make in folder A?
The support says:
Blockquote The error you postet looks like your zimpl softlink is incorrect. If you use a relative path, make sure that it is relative to the position where
the link is created. Most softlinks are created directly in the lib
directory, the zimpl softlink, however, is in a subdirectory of the lib
directory, so you have to go up two directories to get to the main SCIP
directory.
However I am not sure how to check the softlinks.
Thanks!

Resources