Hello,<div>        The value of n is initialized in the main procedure which calls it. Basically I am trying to find the n&#39;th file in the directory(can be in its sub directories too). As I&#39;ve given the previous mail itself</div>
<div><br></div><div>file = findFile(path)<br>                                 invokes that function.When the path is a directory it just recurses into it. And coming to your idea of storing all the items in a list can&#39;t be used here because my folder contain thousands of files and storing them in a list would eat up my memory.</div>
<div><br></div><div>Thanks for your suggestions,</div><div>Venu</div><div><br><div class="gmail_quote">On Tue, Feb 24, 2009 at 12:49 PM, Gerdus van Zyl <span dir="ltr">&lt;<a href="mailto:gerdusvanzyl@gmail.com">gerdusvanzyl@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">I see a couple of problems with your code:<br>
<br>
1. where is n first given a value and what is it total file count,<br>
etc? also you decrement the value, do you want the last file in the<br>
directory or something?<br>
2. The if os.path.isdir(full_path): .. findFile(full_path) part<br>
doesn&#39;t return or handle the value so it&#39;s not useful so far i can<br>
see. So you either need to &quot;return findFile(full_path) &quot; or &quot;value =<br>
findFile(full_path)&quot;<br>
3. I am not sure of your usage of n, the way i do similiar things is<br>
to build a list and then just get the item i want by index or slicing.<br>
<br>
~g<br>
<div><div></div><div class="Wj3C7c"><br>
On Tue, Feb 24, 2009 at 5:28 AM, venu madhav &lt;<a href="mailto:venutaurus539@gmail.com">venutaurus539@gmail.com</a>&gt; wrote:<br>
&gt; Hello,<br>
&gt;         First of all thanks for your response. I&#39;ve written a function as<br>
&gt; shown below to recurse a directory and return a file based on the value of<br>
&gt; n. I am calling this fucntion from my main code to catch that filename. The<br>
&gt; folder which it recurses through contains a folder having files with unicode<br>
&gt; names (as an example i&#39;ve given earlier.<br>
&gt; -----------------------------------------------------------------------------<br>
&gt; def findFile(dir_path):<br>
&gt;     for name in os.listdir(dir_path):<br>
&gt;         full_path = os.path.join(dir_path, name)<br>
&gt;         print full_path<br>
&gt;         if os.path.isdir(full_path):<br>
&gt;             findFile(full_path)<br>
&gt;         else:<br>
&gt;             n = n - 1<br>
&gt;             if(n ==0):<br>
&gt;                 return full_path<br>
&gt; --------------------------------------------------------------------------------------------------<br>
&gt;                     The problem is in the return statement. In the function<br>
&gt; when I tried to print the file name, it is printing properly but the<br>
&gt; receiving variable is not getting populated with the file name. The below<br>
&gt; code (1st statement) shows the value of the full_path variable while the<br>
&gt; control is at the return statement. The second statement is in the main code<br>
&gt; from where the function call has been made.<br>
&gt; Once the control has reached the main procedure after executing the findFile<br>
&gt; procedure, the third statement gives the status of file variable which has<br>
&gt; type as NoneType and value as None. Now when I try to check if the path<br>
&gt; exists, it fails giving the below trace back.<br>
&gt; ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------<br>
&gt; E:\DataSet\Unicode\UnicodeFiles_8859\001_0006_test_folder\0003testUnicode_ÍÎIÐNOKÔÕÖ×ØUÚÛÜUUßaáâãäåæicéeëeíîidnokôõö÷øuúûüuu.txt.txt<br>
&gt; ------------------------------------------------------------------------------------------------------------------------------------------------------------------------<br>
&gt; file = findFile(fpath)<br>
&gt; -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------<br>
&gt; file<br>
&gt; NoneType<br>
&gt; None<br>
&gt; -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------<br>
&gt; This is the final trace back:<br>
&gt; Traceback (most recent call last):<br>
&gt;   File &quot;C:\RecallStubFopen.py&quot;, line 268, in &lt;module&gt;<br>
&gt;     if os.path.exists(file):<br>
&gt;   File &quot;C:\Python26\lib\genericpath.py&quot;, line 18, in exists<br>
&gt;     st = os.stat(path)<br>
&gt; TypeError: coercing to Unicode: need string or buffer, NoneType found<br>
&gt; ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------<br>
&gt; Please ask if you need any further information.<br>
&gt;<br>
&gt; Thank you,<br>
&gt; Venu<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; On Mon, Feb 23, 2009 at 11:32 PM, Chris Rebert &lt;<a href="mailto:clp2@rebertia.com">clp2@rebertia.com</a>&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; On Mon, Feb 23, 2009 at 5:51 AM, <a href="mailto:venutaurus539@gmail.com">venutaurus539@gmail.com</a><br>
&gt;&gt; &lt;<a href="mailto:venutaurus539@gmail.com">venutaurus539@gmail.com</a>&gt; wrote:<br>
&gt;&gt; &gt; Hi all,<br>
&gt;&gt; &gt;          I am trying to find the attributes of afile whose name has<br>
&gt;&gt; &gt; non english characters one like given below. When I try to run my<br>
&gt;&gt; &gt; python scirpt, it fails giving out an error filename must be in string<br>
&gt;&gt; &gt; or UNICODE. When i try to copy the name of the file as a strinig, it<br>
&gt;&gt; &gt; (KOMODO IDE) is not allowing me to save the script saying that it<br>
&gt;&gt; &gt; cannot convert some of the characters in the current encoding which is<br>
&gt;&gt; &gt; Western European(CP-1252).<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; 0010testUnicode_ėíîïðņōóôõöũøųúûüýþĸ !#$%&amp;&#39;()+,-.<br>
&gt;&gt; &gt; 0123456789;=@ABCD.txt.txt<br>
&gt;&gt;<br>
&gt;&gt; (1) How are you entering or retrieving that filename?<br>
&gt;&gt; (2) Please provide the exact error and Traceback you&#39;re getting.<br>
&gt;&gt;<br>
&gt;&gt; Cheers,<br>
&gt;&gt; Chris<br>
&gt;&gt;<br>
&gt;&gt; --<br>
&gt;&gt; Follow the path of the Iguana...<br>
&gt;&gt; <a href="http://rebertia.com" target="_blank">http://rebertia.com</a><br>
&gt;<br>
&gt;<br>
</div></div>&gt; _______________________________________________<br>
&gt; python-win32 mailing list<br>
&gt; <a href="mailto:python-win32@python.org">python-win32@python.org</a><br>
&gt; <a href="http://mail.python.org/mailman/listinfo/python-win32" target="_blank">http://mail.python.org/mailman/listinfo/python-win32</a><br>
&gt;<br>
&gt;<br>
</blockquote></div><br></div>