Hello,<div> The value of n is initialized in the main procedure which calls it. Basically I am trying to find the n'th file in the directory(can be in its sub directories too). As I'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'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"><<a href="mailto:gerdusvanzyl@gmail.com">gerdusvanzyl@gmail.com</a>></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't return or handle the value so it's not useful so far i can<br>
see. So you either need to "return findFile(full_path) " or "value =<br>
findFile(full_path)"<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 <<a href="mailto:venutaurus539@gmail.com">venutaurus539@gmail.com</a>> wrote:<br>
> Hello,<br>
> First of all thanks for your response. I've written a function as<br>
> shown below to recurse a directory and return a file based on the value of<br>
> n. I am calling this fucntion from my main code to catch that filename. The<br>
> folder which it recurses through contains a folder having files with unicode<br>
> names (as an example i've given earlier.<br>
> -----------------------------------------------------------------------------<br>
> def findFile(dir_path):<br>
> for name in os.listdir(dir_path):<br>
> full_path = os.path.join(dir_path, name)<br>
> print full_path<br>
> if os.path.isdir(full_path):<br>
> findFile(full_path)<br>
> else:<br>
> n = n - 1<br>
> if(n ==0):<br>
> return full_path<br>
> --------------------------------------------------------------------------------------------------<br>
> The problem is in the return statement. In the function<br>
> when I tried to print the file name, it is printing properly but the<br>
> receiving variable is not getting populated with the file name. The below<br>
> code (1st statement) shows the value of the full_path variable while the<br>
> control is at the return statement. The second statement is in the main code<br>
> from where the function call has been made.<br>
> Once the control has reached the main procedure after executing the findFile<br>
> procedure, the third statement gives the status of file variable which has<br>
> type as NoneType and value as None. Now when I try to check if the path<br>
> exists, it fails giving the below trace back.<br>
> ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------<br>
> E:\DataSet\Unicode\UnicodeFiles_8859\001_0006_test_folder\0003testUnicode_ÍÎIÐNOKÔÕÖ×ØUÚÛÜUUßaáâãäåæicéeëeíîidnokôõö÷øuúûüuu.txt.txt<br>
> ------------------------------------------------------------------------------------------------------------------------------------------------------------------------<br>
> file = findFile(fpath)<br>
> -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------<br>
> file<br>
> NoneType<br>
> None<br>
> -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------<br>
> This is the final trace back:<br>
> Traceback (most recent call last):<br>
> File "C:\RecallStubFopen.py", line 268, in <module><br>
> if os.path.exists(file):<br>
> File "C:\Python26\lib\genericpath.py", line 18, in exists<br>
> st = os.stat(path)<br>
> TypeError: coercing to Unicode: need string or buffer, NoneType found<br>
> ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------<br>
> Please ask if you need any further information.<br>
><br>
> Thank you,<br>
> Venu<br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
> On Mon, Feb 23, 2009 at 11:32 PM, Chris Rebert <<a href="mailto:clp2@rebertia.com">clp2@rebertia.com</a>> wrote:<br>
>><br>
>> On Mon, Feb 23, 2009 at 5:51 AM, <a href="mailto:venutaurus539@gmail.com">venutaurus539@gmail.com</a><br>
>> <<a href="mailto:venutaurus539@gmail.com">venutaurus539@gmail.com</a>> wrote:<br>
>> > Hi all,<br>
>> > I am trying to find the attributes of afile whose name has<br>
>> > non english characters one like given below. When I try to run my<br>
>> > python scirpt, it fails giving out an error filename must be in string<br>
>> > or UNICODE. When i try to copy the name of the file as a strinig, it<br>
>> > (KOMODO IDE) is not allowing me to save the script saying that it<br>
>> > cannot convert some of the characters in the current encoding which is<br>
>> > Western European(CP-1252).<br>
>> ><br>
>> > 0010testUnicode_ėíîïðņōóôõöũøųúûüýþĸ !#$%&'()+,-.<br>
>> > 0123456789;=@ABCD.txt.txt<br>
>><br>
>> (1) How are you entering or retrieving that filename?<br>
>> (2) Please provide the exact error and Traceback you're getting.<br>
>><br>
>> Cheers,<br>
>> Chris<br>
>><br>
>> --<br>
>> Follow the path of the Iguana...<br>
>> <a href="http://rebertia.com" target="_blank">http://rebertia.com</a><br>
><br>
><br>
</div></div>> _______________________________________________<br>
> python-win32 mailing list<br>
> <a href="mailto:python-win32@python.org">python-win32@python.org</a><br>
> <a href="http://mail.python.org/mailman/listinfo/python-win32" target="_blank">http://mail.python.org/mailman/listinfo/python-win32</a><br>
><br>
><br>
</blockquote></div><br></div>