directory

Move file using specific nav path to another folder

Move file using specific nav path to another folder Question: I have a list of navigation paths to specific files, which all come from different folders. I’d like to move them all to a new folder. Specifically, my data is formatted in two columns in a dataframe, where I’d like to move each file to …

Total answers: 1

Why do some os functions ignore trailing spaces on Windows?

Why do some os functions ignore trailing spaces on Windows? Question: I’ve tried the example program below on both Windows and Linux with Python 3.11.0. import os if __name__ == "__main__": directory_name = "foo " file_name = "bar.txt" os.mkdir(directory_name) print(os.path.exists(directory_name)) out_path = os.path.join(directory_name, file_name) try: with open(out_path, "w") as bar_file: pass print(f"Successfully opened {repr(out_path)}.") except …

Total answers: 1

How to get listdir of a path with it path

How to get listdir of a path with it path Question: i want this >>> from os import listdir >>> listdir(g:/new folder) [g:/new folder/file 1, g:/new folder/file 2] but i’m getting this >>> from os import listdir >>> listdir(g:/new folder) [file 1, file 2] Asked By: Frost Dream || Source Answers: import os directory = …

Total answers: 2

Python cannot find a directory

Python cannot find a directory Question: I wrote a code like this with jupyter notebook in a project; import os image_path = r’C:UsersaysDesktopIR1.jpg’ image_files = os.listdir(image_path) img = cv2.imread(os.path.join(image_path,image_files)) cv2.imshow(‘image’,img) it gives an error like; [WinError 3] The system cannot find the path specified: ‘C:UsersaysDesktopIR1.jpg’ i was trying to print an image and i had …

Total answers: 2

`path.basename` like function, but to get the root of a path

`path.basename` like function, but to get the root of a path Question: os.path has the basename function that returns the last folder/file of the given path, i wonder if there is a easy way to get the root of a path (and why there’s not a function to it in the os.path module) >>> from …

Total answers: 2

Renaming characters in multiple files in a folder

Renaming characters in multiple files in a folder Question: I’m trying to rename files in a folder with import os. Folder I want to replace the ‘SN’ in all these files with ‘NG’. I have tried with the code ` filenames = os.listdir(serial_dir) #serial_dir is the right path for filename in filenames: dst = filename.replace(‘SN’, …

Total answers: 1

"Moving a directory into itself" error in Python

"Moving a directory into itself" error in Python Question: I have an application which sorts files upon receiving the path to the folder containing the files. However, there’s a line of code where I’m supposedly moving a directory into itself, but I can’t see how that’s happening since I’m doing the same thing with the …

Total answers: 1