Questions tagged [os.path]

Python module implementing common pathname manipulations

502 questions
-1
votes
2 answers

What does the os.path.join in python 2.7 do?

I have the following line of code which I think is not correct: path_dir = os.path.abspath(os.path.join(os.path.dirname(__file__))) where os.path.dirname(__file__) looks for a script. I understand that os.path.abspath() gives you the absolute path…
Jay
  • 33
  • 1
  • 4
-1
votes
2 answers

os.path.isdir() gives always true

Hi I write a simple python code it will check folder/dir is exist or not in the /usr/share/* file but it's fail to check import os try: os.path.isdir('/usr/share/sqlmap') print 'sqlmap found' except OSError: print "Sqlmap not…
-1
votes
1 answer

Not getting full path when using os.path.abspath in conjunction with os.listdir

I am trying to use the following line of code to get all the pathnames of files in a given directory: trainDB = [os.path.abspath(x) for x in os.listdir("C:/Users/sean/Documents/uni/ANLP/Data/Train/DrugBank")] But the ouput is like…
seanysull
  • 720
  • 1
  • 8
  • 24
-1
votes
1 answer

How to create and name a new folder from tkinter Entry widget input?

I want the input, someone has put into the Entry widget (E1) of my Tkinter GUI, to be the name of the new folder, because every time someone inputs something, I need to have a new folder named after the input: def create(): folder = E1.get() …
hccavs19
  • 165
  • 3
  • 9
-1
votes
1 answer

copy content of directory from a list of directories

I want to automate copying directory contents to another folder. I found this post (Copy directory contents into a directory with python) and would like to make it so that I can run a for loop. This is my code so far, however I am getting an error…
Spencer Trinh
  • 743
  • 12
  • 31
-1
votes
2 answers

Replacing file names in directory from text file

I would like to use Python to rename the files in a directory called myShow from a .txt file that contains the "target" names: realNameForEpisode1 realNameForEpisode2 realNameForEpisode3 The hierarchy looks like: episodetitles.txt myShow ├──…
Vivek Jha
  • 257
  • 2
  • 10
-1
votes
2 answers

os.path.basename to outfile

For every input file processed (see code below) I am trying to use "os.path.basename" to write to a new output file - I know I am missing something obvious...? import os import glob import gzip dbpath = '/home/university/Desktop/test' for infile…
jnorth
  • 115
  • 7
-1
votes
2 answers

Python find out if a folder exists

I am trying to find out if a folder exists but for some reason cannot. I am generating a string, and use os.path.isdir to find out if a folder with that string`s name already exists. The thing is - I get 'False' regardless. import os my_Folder_Name…
Yair
  • 859
  • 2
  • 12
  • 27
-1
votes
2 answers

os.walk(directory) - AttributeError: 'tuple' object has no attribute 'endswith'

I am trying to make a script in python to search for certain type of files (eg: .txt, .jpg, etc.). I started searching around for quite a while (including posts here in SO) and I found the following snippet of code: for root, dirs, files in…
geo1230
  • 242
  • 4
  • 15
-1
votes
2 answers

What directory does os.path.join start at?

I made a script in the past to mass rename any file greater than x characters in a directory. When I made that script I had a source directory which you would need to input manually. Any file that was over x characters in that directory would be…
user5081090
-1
votes
1 answer

Python - WindowsError: [Error 2] the system could not find the file specified: ... afterusign os.path.getsize

import os import sys rootdir = sys.argv[1] print os.path.abspath(rootdir) with open('output.txt','r') as fout: for root, subFolders, files in os.walk(rootdir): for file in files: path = os.path.abspath(file) print path …
MarianM
  • 3
  • 2
-1
votes
1 answer

os.path doesn't seem to work on Windows 8

One of the people using a Jython script I wrote had the error: AttributeError: 'module' object has no attribute 'path' After investigation, it turns out that the error occurs when the code runs os.path. Actually, I found out that os.path is not…
Taurus Olson
  • 3,153
  • 2
  • 26
  • 21
-2
votes
1 answer

Move files to folder made by user input with the same name

I have a directory containing the following: name.xlsx I use the following code to have a user input names for the folder(s) they would like to create in that directory. dirPath = ‘dir_path’ naFold = input(“Enter name: ”) lst = naFold.split(“,…
GooseCake
  • 33
  • 8
-2
votes
1 answer

Why slash in dictionary have a wrong amount?

import os print(os.path.abspath("test1/test")) print({1: os.path.abspath("test1/test")}) D:\ZTK\autotest\Learn\test1\test {1: 'D:\ZTK\autotest\Learn\test1\test'}
-2
votes
2 answers

os.path.join to create filename in python with datetime not working in mac

I am trying to generate a filename in python on mac to record data everyday so that the filename has date in filename. Please refer the command below. oi_filename=…
1 2 3
33
34