Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
I need to do ADIR enhancement..
Message
From
12/09/2001 05:37:39
 
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00555009
Message ID:
00555405
Views:
19
>>>Hi!
>>>
>>>There is an Windows API function to get short file name from long (do not remember which, let me know if you cannot find it).
>>>
>>>Just a suggestion:
>>>Try: ADIR(aDirs,"DHS"), "MSCREATE.DIR" folder is usually marked as hidden, but ADIR(aDirs,"D") do not see hidden directories. Just check if this is true...
>>>
>>>Good reason to upgrade to VFP7 - ADIR in there allows getting short file names in result array, as well as return file names in original case (in older versions files are in all uppercase).
>>>
>>
>>Well, I have post the API function call at the below, I've found it.
>>I am using Chinese VFP but still not yet Chin. VFP 7.0 out.. :(
>>
>
>There are FAQs demonstrating how to use ADIR() to recursively build a list of files, as well as equivalent functions that rely on the Windows Script Host Scripting.FileSystemObject and Shell.Application automation objects. You might also look at Bela Bodec's bbGetDIR.OCX, available for download in the Files section here on UT.




Thanks for advance, my FDIR function is done.

Just use Table designer to create a FILEDIR.dbf

Fpath C(128)
Filename C(128)
FileSize N(20)
FileDate D
FileTime C(8)
Attr C(5)
Ext C(3)
FShortNam C(128)

Usage is very simple:

FDIR([C:\Windows\System], [*.dll], .T.)

it will give all data into FileDir.dbf with all dll file detail recursively in system directoy.

Now, I got a problem, Change Path problem for some space in is fixed.
For example, "C:\My Document"
But if the path got a symbol is &,
such as C:\B&W then the program got crush.. :(
therefore I cancel the function..

do you have any good idea to do?
Thanks for help.

code post below:


PROCEDURE FDIR
LPARAMETERS pPATH, pFILTER, pRECUR, pATTR

LPCOUNT = PCOUNT()
DO CASE
CASE LPCOUNT = 0
	MESSAGEBOX([Usage: FDIR(Path, Filter, Recursive, Attribute)], 16, [Wrong Use])
	RETURN

CASE LPCOUNT = 1
	lpPATH = ALLTRIM(UPPER(pPATH))
	lpFILTER = [*.*]	&& ALL FILE
	lpRECUR = .F.	&& NO SUBSTR
	lpATTR = []		&& ALL FILE

CASE LPCOUNT = 2
	lpPATH = ALLTRIM(UPPER(pPATH))
	lpFILTER = pFILTER
	lpRECUR = .F.	&& NO SUBSTR
	lpATTR = []		&& ALL FILE

CASE LPCOUNT = 3
	lpPATH = ALLTRIM(UPPER(pPATH))
	lpFILTER = pFILTER
	lpRECUR = pRECUR
	lpATTR = []		&& ALL FILE

CASE LPCOUNT = 4
	lpPATH = ALLTRIM(UPPER(pPATH))
	lpFILTER = pFILTER
	lpRECUR = pRECUR
	lpATTR = pATTR

ENDCASE

IF ! USED([FILEDIR])
	SET SAFETY OFF
	SELECT 0
	USE FILEDIR EXCL IN 0
	SELECT FILEDIR
	ZAP
ENDIF

SELECT FILEDIR

LCURPATH = SYS(5) + SYS(2003)
ON ERROR CANCEL
	CDMACRO = 	[CD "] + ALLTRIM(lpPATH) + ["]
	&CDMACRO
ON ERROR DO errhand WITH ;
	ERROR( ), MESSAGE( ), MESSAGE(1), PROGRAM( ), LINENO( )

LOCAL nFCount, nDCount, aFiles[1], aDirs[1], IX, IY, lcEXT, lcSHORTNAME
nDCount = ADIR(aDirs, [*], [D])
nFCount = ADIR(aFiles, lpFilter, lpAttr)

WAIT WINDOW [Check:		"&lpFilter" with Attribute "&lpAttr"] + CHR(13) + ;
	[Folder:		&lpPATH] + CHR(13) + ;
	[Match #:		] + ALLTRIM(STR(nFCount)) + CHR(13) + ;
	[SubFolder #:	] + ALLTRIM(STR(nDCount)) + CHR(13) + ;
	[Record #:	] + ALLTRIM(STR(RECCOUNT())) NOWAIT NOCLEAR AT 0,0

FOR IY = 1 TO ALEN(AFiles) / 5		&& N x 5 ARRAY
	SELECT FILEDIR
	IF [.] $ AFiles(IY, 1)
		lcEXT = SUBSTR(AFiles(IY, 1), RAT([.], AFiles(IY, 1))+1)
	ENDIF
	lcFullName = STRTRAN(lpPATH + [\] + AFiles(IY, 1), [\\], [\] )
	lcSHORTNAME = GetShortName( lcFullName )

	INSERT INTO FILEDIR (FPATH, FILENAME, FILESIZE, FILEDATE, FILETIME, ATTR, EXT, FSHORTNAM) ;
		VALUES (lpPATH, AFiles(IY, 1), AFiles(IY, 2), AFiles(IY, 3), AFiles(IY, 4), AFiles(IY, 5), lcEXT, lcSHORTNAME )

ENDFOR

FOR IX = 1 TO ALEN(ADIRS) / 5		&& N x 5 ARRAY
DO CASE
CASE ALLTRIM(ADIRS(IX, 1)) = [.] .OR. ALLTRIM(ADIRS(IX, 1)) = [..]
	* SKIP

CASE [D] $ ADIRS(IX, 5)			&& THIS IS A DIRECTORY
	IF [D] $ lpATTR		&& User want Directory show
		SELECT FILEDIR
		IF [.] $ AFiles(IY, 1)
			lcEXT = SUBSTR(AFiles(IY, 1), RAT([.], AFiles(IY, 1))+1)
		ENDIF
		lcFullName = STRTRAN(lpPATH + [\] + AFiles(IY, 1), [\\], [\] )
		lcSHORTNAME = GetShortName( lcFullName )

		INSERT INTO FILEDIR (FPATH, FILENAME, FILESIZE, FILEDATE, FILETIME, ATTR, EXT, FSHORTNAM) ;
			VALUES (lpPATH, AFiles(IY, 1), AFiles(IY, 2), AFiles(IY, 3), AFiles(IY, 4), AFiles(IY, 5), lcEXT, lcSHORTNAME )
	ENDIF

	IF pRECUR = .T.
		SUBPATH = pPATH + [\] + ALLTRIM(ADIRS(IX, 1))
		SUBPATH = STRTRAN(SUBPATH, [\\], [\])
		FDIR(SUBPATH, lpFILTER, lpRECUR, lpATTR)
	ENDIF
ENDCASE
ENDFOR

*nFCount = ADIR(aFiles)

ON ERROR CANCEL
	CDMACRO = 	[CD "] + ALLTRIM(lCURPATH) + ["]
	&CDMACRO
ON ERROR DO errhand WITH ;
	ERROR( ), MESSAGE( ), MESSAGE(1), PROGRAM( ), LINENO( )

WAIT CLEAR
RETURN
ENDPROC

* LONG NAME -> SHORT NAME
FUNCTION GetShortName
LPARAMETERS cPathToConvert
LOCAL cBuf, nBufSize, nShortSize

IF TYPE([cPathToConvert]) # [C] .OR. LEN(cPathToConvert) = 0
	* Nothing to convert
	RETURN []
ENDIF

DECLARE INTEGER GetShortPathName IN Win32API ;
	STRING @cLongPath, ;
	STRING @cShortPathBuff, ;
	INTEGER nBuffSize

cBuf = SPACE(511)
nBufSize = 511
nShortSize = GetShortPathName(cPathToConvert, @cBuf, @nBufSize)
IF nShortSize > 0
	RETURN LEFT(cBuf, nShortSize)
ELSE
	RETURN []
ENDIF

ENDFUNC
The weak wait for chance, The strong bid for chance,
The clever notch up chance, but The merciful give you chance.
Previous
Reply
Map
View

Click here to load this message in the networking platform