Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 24th, 2012, 05:57 PM
EJF EJF is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2005
Posts: 54 EJF User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 3 m 21 sec
Reputation Power: 8
Opening certain files within a directory

I have a very basic question about creating a list of files. I would like to:

1. open a directory specified by a path

2. add all files that match a certain pattern onto a file list (let's say files that start with "AML_" followed by 6 capital letters followed by an underscore and then 6 numbers and ending in ".sam")

3. close the directory

Now I can go through each file in the list and process it appropriately. I do this a lot in perl, but I'm new to python and I'm having trouble figuring out this basic operation.

Thank you.

Eric

Reply With Quote
  #2  
Old December 24th, 2012, 08:46 PM
Nyktos Nyktos is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 75 Nyktos User rank is Corporal (100 - 500 Reputation Level)Nyktos User rank is Corporal (100 - 500 Reputation Level)Nyktos User rank is Corporal (100 - 500 Reputation Level)Nyktos User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 1 Day 3 h 5 m 49 sec
Reputation Power: 2
Look at the os module for functions that interact with the file system (in particular the function os.listdir is what you want on that end) and the re module for regular expressions.

Reply With Quote
  #3  
Old December 24th, 2012, 09:14 PM
metulburr metulburr is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 10 metulburr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 43 m 57 sec
Reputation Power: 0
os.listdir() will list a directorys' content

instead of re module using regular expression you could also parse out the unwated contents via the glob.glob()

Reply With Quote
  #4  
Old December 25th, 2012, 11:03 AM
EJF EJF is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2005
Posts: 54 EJF User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 3 m 21 sec
Reputation Power: 8
Thanks all. I got it to work. I really appreciate the help.

Eric

Reply With Quote
  #5  
Old December 25th, 2012, 03:39 PM
dwblas dwblas is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2009
Posts: 291 dwblas User rank is Corporal (100 - 500 Reputation Level)dwblas User rank is Corporal (100 - 500 Reputation Level)dwblas User rank is Corporal (100 - 500 Reputation Level)dwblas User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 3 Days 18 h 33 m 54 sec
Reputation Power: 7
Too late probably, but look at glob.glob in the future
Code:
files = glob.glob( "AML*" ) 

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Opening certain files within a directory

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap