(1) How are you entering or retrieving that filename?
(2) Please provide the exact error and Traceback you're getting.
Cheers,
Chris
Hello,
First of all thanks for your response. I've written a function
as shown below to recurse a directory and return a file based on the
value of n. I am calling this fucntion from my main code to catch that
filename. The folder which it recurses through contains a folder
having files with unicode names (as an example i've given earlier.
-----------------------------------------------------------------------------
def findFile(dir_path):
for name in os.listdir(dir_path):
full_path = os.path.join(dir_path, name)
print full_path
if os.path.isdir(full_path):
findFile(full_path)
else:
n = n - 1
if(n ==0):
return full_path
--------------------------------------------------------------------------------------------------
The problem is in the return statement. In the
function when I tried to print the file name, it is printing properly
but the receiving variable is not getting populated with the file
name. The below code (1st statement) shows the value of the full_path
variable while the control is at the return statement. The second
statement is in the main code from where the function call has been
made.
Once the control has reached the main procedure after executing the
findFile procedure, the third statement gives the status of file
variable which has type as NoneType and value as None. Now when I try
to check if the path exists, it fails giving the below trace back.
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
E:\DataSet\Unicode\UnicodeFiles_8859\001_0006_test_folder
\0003testUnicode_ÃÃŽIÃNOKÔÕÖרUÚÛÜUUßaáâãäåæicéeëeÃîidnokôõö÷øuúûüuu.txt.txt
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
file = findFile(fpath)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
file
NoneType
None
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
This is the final trace back:
Traceback (most recent call last):
File "C:\RecallStubFopen.py", line 268, in <module>
if os.path.exists(file):
File "C:\Python26\lib\genericpath.py", line 18, in exists
st = os.stat(path)
TypeError: coercing to Unicode: need string or buffer, NoneType found
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Please ask if you need any further information.
Thank you,
Venu