![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Stripping out extension in file name | devs | Shell Programming and Scripting | 9 | 05-14-2008 04:53 AM |
| How to get file extension | shirleyeow | Shell Programming and Scripting | 17 | 01-17-2008 08:40 AM |
| trim file name extension???? | vishal_ranjan | AIX | 1 | 07-31-2007 09:34 AM |
| distinguish the extension of a file | tbeghain | AIX | 2 | 06-13-2007 11:15 AM |
| Check file extension | mahalakshmi | Shell Programming and Scripting | 6 | 12-27-2006 01:15 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Run a program for every file with a given extension
Hey all
I have written a python program that takes as input the name of a data file with the extension .lc I would like to write a shell script that finds all of the .lc files in a set of branching directories and runs the program. Any help? |
|
||||
|
here's a snippet. Use the sys.stdin.readlines() method in your python script
Code:
import sys print sys.stdin.readlines() Code:
# find /path-type f -name "*.lc" -print | ./test1.py ['/path/user/test.lc\n', '/path/test/test1.lc\n'] Last edited by ghostdog74; 09-20-2008 at 09:11 AM.. |
|
||||
|
you can find those files in Python itself. this way, you don't have to maintain an extra shell script.
some of the modules in Python you can use to find files are: os.walk(), glob , os.path.splitext() etc... here's a snippet: Code:
#!/usr/bin/python
import os
for root,dir,files in os.walk("/home"):
for file in files:
if file[-3:]==".lc":
fullpath=os.path.join(root,file)
do_something(fullpath)
Code:
find /path -type f -name "*.lc" -print > file # or pipe to you python program |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|