directory

How to delete files with specific patterns in python?

How to delete files with specific patterns in python? Question: I have a bunch of files in the directory web, I need to match the pattern and delete the appropriate files.The files are in the following order 1520_22.txt, 1530_22.txt, 1540_22.txt, new_pwd_v1_asia_1530_22.json, new_pwd_v1_eur_1540_22.json, new_pwd_v1_aus_1520_22.json Each json file has a corresponding text file identified by the number …

Total answers: 1

Python not importing module from same directory

Python not importing module from same directory Question: They are in the same directory and I have the path set to the correct folder so I have no idea why it can’t find the python file Expecting it to open the file to access a class. Code is as follows: import pandas as pd import …

Total answers: 1

How to change file name in a folder based on a DataFrame column

How to change file name in a folder based on a DataFrame column Question: I have a folder consists several files in the directory E:folder and looks like the following. -folder -old1.jpg -old2.jpg -old3.jpg -… and I would like to change the name of these files based on the dataframe df column "new_name". new_name abc1 …

Total answers: 1

How to copy contents of a directory with the same name into another directory in python

How to copy contents of a directory with the same name into another directory in python Question: How can I copy contents of a directory with the same name into another directory? Directory1 File1.txt Directroy1 File2.txt I want it to end up like Directory1 File1.txt File2.txt Right now I am trying to use the shutil.move() …

Total answers: 2

os.listdir returns the error: no such file or directory even though the directory actually exists

os.listdir returns the error: no such file or directory even though the directory actually exists Question: This is my project files structure: and this is my main.py script: if __name__ == ‘__main__’: leukemia_dir = "../dataset/leukemia" # if I click here, I get redirected to the folder file_names = os.listdir(leukemia_dir) # << won’t work Unfortunately, os.listdir(leukemia_dir) …

Total answers: 2

Directory name error when creating dir in python out of the blue

Directory name error when creating dir in python out of the blue Question: So i am using a method i made to save some plots of data, and i have automated the process by saving the plots in a sub folder in my current working directory, that has the name of the first and last …

Total answers: 1

Randomly splitting 1 file from many files based on ID

Randomly splitting 1 file from many files based on ID Question: In my dataset, I have a large number of images in jpg format and they are named [ID]_[Cam]_[Frame].jpg. The dataset contains many IDs, and every ID has a different number of image. I want to randomly take 1 image from each ID into a …

Total answers: 3

python: splitting filenames to order sequentially

python: splitting filenames to order sequentially Question: I have filenames like this: ‘./images/X_0_image0.png’, ‘./images/X_0_image1.png’, ‘./images/X_0_image10.png’, ‘./images/X_0_image100.png’, ‘./images/X_0_image101.png’, in a directory containing a lot. How do I read the content such that I obtain a list of paths and filenames sorted in ascending order like for a human count, i.e. not having X_0_image100.png appear after X_0_image10.png. …

Total answers: 1

Read specific folder's name from folder's path Python

Read specific folder's name from folder's path Python Question: I’m trying to read the folder name at the specific place from the file path. My current code: import os # search for and input multiple files def get_files(source): matches = [] for root, dirnames, filenames in os.walk(source): for filename in filenames: matches.append(os.path.join(root, filename)) return matches …

Total answers: 1

How to get the path from content root in python?

How to get the path from content root in python? Question: Suppose that I have a working directory called directory 1. This directory has an app.py file and a directory file called directory2. Inside directory2 I have a text file called example.txt. Is there a way of finding the path of example.txt using a command …

Total answers: 1