Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Getting the a file name with proper case
Message
De
17/03/2003 03:32:57
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Divers
Thread ID:
00766432
Message ID:
00766459
Vues:
43
>VFP has the unfortunate problem that all path related functions return filenames and paths in UPPER case. For example, GetFile() returns upper case as does FULLPATH() and even the varoius SYS() functions related to directory values return upper case.
>
>Does anybody know of an API call that you can pass a file or directory path to that will return the fully qualified long filename in proper case back? At least that way I can retrieve the filename and then later convert it into the proper case.
>
>I've played around GetLongPathName and GetFullPathName but neither of these seem to work and simply return the same case as what was passed in. THey basically confirm the file name and that the file exists.


Rick,

I am happy with following piece of code. I haven't found any better. It works its way up using FindFirstFile()
?DiskFileName('C:\Whatever\Folder\or\Filename\)
*---------------------------------------------------------------------------
#Define MAX_PATH 260
function	DiskFilename(FileName)
	
	declare Integer FindFirstFile in win32api string @, String @
	declare Integer FindNextFile in win32api Integer, String @
	declare Integer FindClose in win32api Integer
	
	do case
	case ( right(FileName,1) == '\' )
		return addbs(DiskFilename(left(FileName, len(Filename)-1)))
	
	case empty(FileName)
		return ''
	
	case ( len(FileName) == 2 ) and ( right(FileName,1) == ':' )
			return Filename	&& win2k gives curdir() for C:
	endcase
	
	local Handle, FindFileData, xxx
	FindFileData = space(4+8+8+8+4+4+4+4+MAX_PATH+14)
	Handle = FindFirstFile(@FileName, @FindFileData)
	
	if( Handle < 0 )
		if( !empty(JustFname(Filename)) )
			xxx = JustFname(Filename)
		else
			xxx = FileName
		endif
	else
		=FindClose(Handle)
		xxx = substr(FindFileData, 45, MAX_PATH)
		xxx = left(xxx, at(chr(0), xxx)-1)
	endif
	

	do case
	case empty(justpath(FileName))
		return xxx
	case ( justpath(FileName) == '\' ) and (left(FileName,2) == '\\')	&& unc
		return '\\' + xxx
	otherwise
		return addbs(DiskFilename(JustPath(FileName))) + xxx
	endcase
		
endfunc
*--------------------------------------------------------------------------
Gregory
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform