absolute-path

constructing absolute path with os.path.join()

constructing absolute path with os.path.join() Question: I’d like to construct an absolute path in python, while at the same time staying fairly oblivious of things like path-separator. edit0: for instance there is a directory on the root of my filesystem /etc/init.d (or C:etcinit.d on w32), and I want to construct this only from the elements …

Total answers: 5

How to eliminate absolute path in zip archive if absolute paths for files are provided?

How to eliminate absolute path in zip archive if absolute paths for files are provided? Question: I have two files in two different directories, one is ‘/home/test/first/first.pdf’, the other is ‘/home/text/second/second.pdf’. I use following code to compress them: import zipfile, StringIO buffer = StringIO.StringIO() first_path = ‘/home/test/first/first.pdf’ second_path = ‘/home/text/second/second.pdf’ zip = zipfile.ZipFile(buffer, ‘w’) zip.write(first_path) …

Total answers: 6

Do I need to pass the full path of a file in another directory to open()?

Do I need to pass the full path of a file in another directory to open()? Question: I have a folder with ten files in it which I want to loop through. When I print out the name of the file my code works fine: import os indir = ‘/home/des/test’ for root, dirs, filenames in …

Total answers: 5

Get absolute paths of all files in a directory

Get absolute paths of all files in a directory Question: How do I get the absolute paths of all the files in a directory that could have many sub-folders in Python? I know os.walk() recursively gives me a list of directories and files, but that doesn’t seem to get me what I want. Asked By: …

Total answers: 13

How to get an absolute file path in Python

How to get an absolute file path in Python Question: Given a path such as "mydir/myfile.txt", how do I find the file’s absolute path in Python? E.g. on Windows, I might end up with: "C:/example/cwd/mydir/myfile.txt" Asked By: izb || Source Answers: >>> import os >>> os.path.abspath(“mydir/myfile.txt”) ‘C:/example/cwd/mydir/myfile.txt’ Also works if it is already an absolute …

Total answers: 11