symlink

How to get the files inside a directory link with python

How to get the files inside a directory link with python Question: This is probably super easy, but after an hour of trying, I haven’t been able to find it. From a specific folder inside a database called /Database/Images/, I manually created a folder link with Windows and placed it at, /Tests/Images. With that done, …

Total answers: 1

The question of unix symbolic inspired from the usage of python venv executable symlink

The question of unix symbolic inspired from the usage of python venv executable symlink Question: Question brief description After creation of venv (either via python -m venv .venv/ or virtualenv .venv/), a files tree will be created. There is a file .venv/bin/python or python3, python3.<x>. It is a unix symbolic link to /usr/bin/python. But how …

Total answers: 1

python – symlink to another symlink without following the latter symlink

python – symlink to another symlink without following the latter symlink Question: I want to create a symbolic link (A) to another symbolic link (B) which point to an actual file (C) on macOS with python >= 3.10: A -> B -> C I tried this: from pathlib import Path A = Path(‘/path/to/src’) B = …

Total answers: 1

Symlink (auto-generated) directories via Snakemake

Symlink (auto-generated) directories via Snakemake Question: I am trying to create a symlink-directory structure for aliasing output directories in a Snakemake workflow. Let’s consider the following example: A long time ago in a galaxy far, far away, somebody wanted to find the best ice cream flavour in the universe and conducted a survey. Our example …

Total answers: 2

Getting the target of a symbolic link with pathlib

Getting the target of a symbolic link with pathlib Question: Is there a way to get the target of a symbolic link using pathlib? I know that this can be done using os.readlink(). I want to create a dictionary composed by links and their target files. links = [link for link in root.rglob(‘*’) if link.is_symlink()] …

Total answers: 2

Python can't open symlinked file

Python can't open symlinked file Question: Python is unable to open my simlinked file. I made sure the file exists and I can access it. I was under the impression that symlinks are resolved on the OS level so Python would never know about it. therold@therold:~/Programming/ML/deeptank/dataset/inc (master)$ ls -lisa /Users/therold/Programming/ML/deeptank/dataset/inc/training/tanks/matilda-iv_689.png 7870541 8 lrwxr-xr-x 1 therold …

Total answers: 6

`os.symlink` vs `ln -s`

`os.symlink` vs `ln -s` Question: I need to create a symlink for every item of dir1 (file or directory) inside dir2. dir2 already exists and is not a symlink. In Bash I can easily achieve this by: ln -s /home/guest/dir1/* /home/guest/dir2/ But in python using os.symlink I get an error: >>> os.symlink(‘/home/guest/dir1/*’, ‘/home/guest/dir2/’) Traceback (most …

Total answers: 3

How to delete a symbolic link in python?

How to delete a symbolic link in python? Question: I have been trying to delete some symbolic links in my working directory, but I am facing some issues. os.remove also removes the actual contents of the original folder of the link os.shutil throws up an error in case of symbolic links. Is there a way …

Total answers: 5

Can sphinx link to documents that are not located in directories below the root document?

Can sphinx link to documents that are not located in directories below the root document? Question: I am using Sphinx to document a non-Python project. I want to distribute ./doc folders in each submodule, containing submodule_name.rst files to document that module. I then want to suck those files into the master hierarchy to create a …

Total answers: 8

Creating a relative symlink in python without using os.chdir()

Creating a relative symlink in python without using os.chdir() Question: Say I have a path to a file: /path/to/some/directory/file.ext In python, I’d like to create a symlink in the same directory as the file, that points to the file. I’d like to end up with this: /path/to/some/directory/symlink -> file.ext I can do this fairly easily …

Total answers: 4