How to read a directory path from a txt file

S

Samuel Kamau

I have created a txt file with various paths to directories. The paths look like this
/home/wachkama/Desktop/api/genshi
/home/wachkama/Desktop/www/portal/schedule
/home/wachkama/Desktop/show/help.genshi

How do i read this paths in python ?
 
R

Rustom Mody

I have created a txt file with various paths to directories. The paths look like this

/home/wachkama/Desktop/api/genshi

/home/wachkama/Desktop/www/portal/schedule

/home/wachkama/Desktop/show/help.genshi



How do i read this paths in python ?

for x in open("filenames.txt"):
print x

Assuming your filenames are in a file called filenames.txt in current directory

Also in practice:
1. You probably want print x.strip()
2. You dont want a print but whatever is the code you want
 
C

Chris Angelico

I have created a txt file with various paths to directories. The paths look like this
/home/wachkama/Desktop/api/genshi
/home/wachkama/Desktop/www/portal/schedule
/home/wachkama/Desktop/show/help.genshi

How do i read this paths in python ?

This sounds like homework. You'll need to go back to the problem
you've been given, figure out what you're actually trying to
accomplish, and then break that down into several pieces. We're happy
to help you learn, but we will not just do the assignment for you, as
that's counter-productive for all of us.

If it *isn't* homework, please explain in much more detail what it is
you're trying to do here.

ChrisA
 
S

Samuel Kamau

I have created a txt file with various paths to directories. The paths look like this

/home/wachkama/Desktop/api/genshi

/home/wachkama/Desktop/www/portal/schedule

/home/wachkama/Desktop/show/help.genshi



How do i read this paths in python ?

I have permission issues with my web server. So I have written part of my script to read and write the current paths in the web servers with its username and group name into a txt file. I want my script to replace the new permissions on my web server with the permissions written on my txt file. So The last part of my script is the tricky part. How to read the txt file and go to all the paths and rewrite the permissions as per what is on the txt file.
 
S

Samuel Kamau

Hacks to fix permissions problems are dangerous. There is probably a

better way to fix this issue.

The issue is that i use jenkins to deploy my files to the web server. Jenkins takes possession of all files as username and group name. This over right the right permissions on the web server. I want the script to be restoring the right privileges after jenkins deploys a new build.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top