<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'Recursive File Read, update' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'Recursive File Read, update' posted on the 'Python' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2012 Programmers Heaven</copyright>
    <pubDate>Wed, 23 May 2012 23:48:31 -0700</pubDate>
    <lastBuildDate>Wed, 23 May 2012 23:48:31 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>Recursive File Read, update</title>
      <link>http://www.programmersheaven.com/mb/python/411577/411577/recursive-file-read-update/</link>
      <description>hi,&lt;br /&gt;
&lt;br /&gt;
I am very new to python and thanks for your support.&lt;br /&gt;
&lt;br /&gt;
I am trying to write a program to read all the .DAT files in the given folder and its sub folders. &lt;br /&gt;
&lt;br /&gt;
Then in each of the .DAT file, I want to replace a perticular string - this string appears within first 10 lines in the file.&lt;br /&gt;
&lt;br /&gt;
For example: The files have below string on line 4 or 7.&lt;br /&gt;
&lt;span style="color: Blue;"&gt;Name : TESTNAME&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
I want to update (append) the name with the filename. The output is like&lt;br /&gt;
&lt;span style="color: Blue;"&gt;Name : FILENAME_TESTNAME&lt;/span&gt;&lt;br /&gt;
(FILENAME is the name of the file without .DAT extension)&lt;br /&gt;
&lt;br /&gt;
any help... thanks.&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/python/411577/411577/recursive-file-read-update/</guid>
      <pubDate>Wed, 06 Jan 2010 04:34:34 -0700</pubDate>
      <category>Python</category>
    </item>
    <item>
      <title>Re: Recursive File Read, update</title>
      <link>http://www.programmersheaven.com/mb/python/411577/415519/re-recursive-file-read-update/#415519</link>
      <description>#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import os&lt;br /&gt;
def get_immediate_subdirectories(dir):&lt;br /&gt;
    return [name for name in os.listdir(dir)&lt;br /&gt;
            if os.path.isdir(os.path.join(dir, name))]&lt;br /&gt;
&lt;br /&gt;
def get_file(dir):&lt;br /&gt;
     return [name for name in os.listdir(dir)&lt;br /&gt;
             if os.path.isfile(os.path.join(dir,name))]    &lt;br /&gt;
&lt;br /&gt;
if __name__=='__main__':&lt;br /&gt;
     list=[]&lt;br /&gt;
     list=get_immediate_subdirectories(os.getcwd())   &lt;br /&gt;
     print list&lt;br /&gt;
     filelist=[]&lt;br /&gt;
     for dir in list:&lt;br /&gt;
          fileall=get_file(dir)&lt;br /&gt;
          for file in fileall:&lt;br /&gt;
               filename,extension=file.split('.')&lt;br /&gt;
               if extension=='py':&lt;br /&gt;
                  filename+='__TESTNAME'&lt;br /&gt;
                  #filelist.append('in dir='+dir)&lt;br /&gt;
                  filelist.append(filename)&lt;br /&gt;
          print filelist&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/python/411577/415519/re-recursive-file-read-update/#415519</guid>
      <pubDate>Fri, 16 Apr 2010 03:21:19 -0700</pubDate>
      <category>Python</category>
    </item>
  </channel>
</rss>
