Needing a WinXP Python variant of a line of code

R

Ron Rogers Jr.

I have this line of code that's written with Linux in mind:

path_to_nethack_logfile = os.popen("locate logfile | grep
nethackdir").read()

and I'm wanting a Windows equivalent, any suggggestions?


Thanks.

CronoCloud (Ron Rogers Jr.)
 
J

John Zenger

import os, os.path

path_to_nethack_logfile = ""
for root, dirs, files in os.walk("c:\\"):
if 'nethackdir' in root:
logs = [x for x in files if 'logfile' in x]
if len(logs) > 0:
path_to_nethack_logfile = os.path.join(root, logs[0])
exit
 
R

Ron Rogers Jr.

John said:
import os, os.path

path_to_nethack_logfile = ""
for root, dirs, files in os.walk("c:\\"):
if 'nethackdir' in root:
logs = [x for x in files if 'logfile' in x]
if len(logs) > 0:
path_to_nethack_logfile = os.path.join(root, logs[0])
exit

Thank you. I guess I should do more reading, since I hadn't read about
os.walk yet. I shouldn't even be trying to do what I'm doing so early in
my learning. It will eventually be a Nethack logfile parse script.


CronoCloud (Ron Rogers Jr.)
 

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,774
Messages
2,569,596
Members
45,131
Latest member
IsiahLiebe
Top