John A Meinel пишет:
>
> The other problem, is that I don't know of any way to get the real name of a file. You could use "os.listdir(os.path.dirname(path))" and then search through it for possible names, but you don't know if foO is there because of a rename, or if it is actually a different file.
> It would be nice if you could do:
>
> st = os.stat('foo')
> and have "st" have a st_name or some other property that gives you the exact name on disk.
>
> Does anyone know if that is possible?
I know. Recently I dig through MSDN and found this way to determine real filename without
using os.listdir (it's too expensive in Python). You need pywin32 library for this, or
writing C-extension. Using ctypes is also possible but it's too verbose in Python.
Here the actual code:
import win32file
names_list = win32file.FindFilesW(path_in_question) # returns list of WIN32_FIND_DATA structs
# if path_in_question contains wildcard characters * or ? then we get list of al matching files,
# like with glob function
real_name = names_list[0][8]
Here is example running in bzr.dev tree:
In [4]: import win32file
In [5]: names_list = win32file.FindFilesW('BzR')
In [6]: names_list[0][8]
Out[6]: u'bzr'
In [7]: len(names_list)
Out[7]: 1
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
John A Meinel пишет: os.path. dirname( path))" and then search through it for possible names, but you don't know if foO is there because of a rename, or if it is actually a different file.
>
> The other problem, is that I don't know of any way to get the real name of a file. You could use "os.listdir(
> It would be nice if you could do:
>
> st = os.stat('foo')
> and have "st" have a st_name or some other property that gives you the exact name on disk.
>
> Does anyone know if that is possible?
I know. Recently I dig through MSDN and found this way to determine real filename without
using os.listdir (it's too expensive in Python). You need pywin32 library for this, or
writing C-extension. Using ctypes is also possible but it's too verbose in Python.
Here the actual code:
import win32file FindFilesW( path_in_ question) # returns list of WIN32_FIND_DATA structs
names_list = win32file.
# if path_in_question contains wildcard characters * or ? then we get list of al matching files,
# like with glob function
real_name = names_list[0][8]
Here is example running in bzr.dev tree:
In [4]: import win32file
In [5]: names_list = win32file. FindFilesW( 'BzR')
In [6]: names_list[0][8]
Out[6]: u'bzr'
In [7]: len(names_list) enigmail. mozdev. org
Out[7]: 1
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://
iD8DBQFHTwwMzYr 338mxwCURAi9NAJ 42y5oTAb8nLnAPW UO/DkM2nM7LAwCe L89s 3Ynrl7q0=
q28tkBoR6W5ydoG
=VhtB
-----END PGP SIGNATURE-----