New To Python

Creating list of commands and running them on windows terminal

Page 1 of 1

3 Replies - 911 Views - Last Post: 16 June 2010 - 05:51 PM Rate Topic: -----

#1 mat.roscoe  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 26-November 07

New To Python

Posted 16 June 2010 - 01:11 PM

Hello Internet!

I am new to Python and I think this is a bit of an easy question but i have not been able to find to much on google when I search for it. What I am trying to do is to run a program that requires me to input a .txt file one at a time. I would like to automate this to take each file in a directory and run it through the program (on the windows command prompt) one by one and then to place the output in a desired folder. Any help at all would be appreciated.

Thanks in advance for your help!
Mat

This post has been edited by mat.roscoe: 16 June 2010 - 01:20 PM


Is This A Good Question/Topic? 0
  • +

Replies To: New To Python

#2 Motoma  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 452
  • View blog
  • Posts: 796
  • Joined: 08-June 10

Re: New To Python

Posted 16 June 2010 - 01:29 PM

You've chosen a good language to work with! I would suggest looking up the os.listdir() and os.system() functions.
Was This Post Helpful? 0
  • +
  • -

#3 mat.roscoe  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 26-November 07

Re: New To Python

Posted 16 June 2010 - 02:04 PM

View PostMotoma, on 16 June 2010 - 12:29 PM, said:

You've chosen a good language to work with! I would suggest looking up the os.listdir() and os.system() functions.


Thanks! I have been moving slowly and I have been able to get a listing of all the files/directories within the desired directory I am wondering if you new a method / function that I could use to trim the list down to only files that have the '.txt' extension. Here is what I have so far:

#!/usr/bin/python
import os, string

Directory = os.getcwd()

print( os.listdir( Directory ) )

This post has been edited by mat.roscoe: 16 June 2010 - 02:05 PM

Was This Post Helpful? 0
  • +
  • -

#4 Motoma  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 452
  • View blog
  • Posts: 796
  • Joined: 08-June 10

Re: New To Python

Posted 16 June 2010 - 05:51 PM

In that case, you most likely want to use glob.glob:
>>> from glob import glob
>>> glob('*.txt')
['LICENSE.txt', 'NEWS.txt', 'README.txt']


Was This Post Helpful? 1
  • +
  • -

Page 1 of 1