WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Files and Directories

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Getting true filenames and directories UDF

Keywords:    Getting true filenames and directories UDF udfDirGetTrue

;------------------------------------------------------------------------------------------------------------------------------------------
; udfDirGetTrue ()                                                        
; udfDirGetEx ()                                                          
; udfDirGetLong ()                                                        
;------------------------------------------------------------------------------------------------------------------------------------------

If ItemLocate("udfdirgettrue",IntControl(77,103,0,0,0),@TAB) Then Goto skip_udfdirgettrue

#DefineFunction udfDirGetTrue ()
sTrueName = ""
sDirGet = DirGet()
iCount = ItemCount(sDirGet,"\")-1
For i=iCount To 2 By -1
   sTrueName = ItemInsert(DirItemize(StrCat("..\",ItemExtract(i,sDirGet,"\"))),0,sTrueName,"\")
   DirChange("..")
Next
sTrueName = StrCat(ItemInsert(ItemExtract(1,sDirGet,"\"),0,sTrueName,"\"),"\")
DirChange(sDirGet)
Return (sTrueName)
#EndFunction

:skip_udfdirgettrue
;------------------------------------------------------------------------------------------------------------------------------------------


;--- test ---
sDirPath = "d:\tEmP\tRuEnAmEtEsT\"  ; just a common name
iResult = DirMake(sDirPath)

sDirPath = StrLower(sDirPath)       ; lowercase works
iResult = DirChange(sDirPath)

sDirPath1 = DirGet()                ; appears as in last use of DirChange
sDirPath2 = udfDirGetTrue()         ; the actually really true name

MsgText  = StrCat("DirGet",@TAB,@TAB,sDirPath1,@CRLF,"udfDirGetTrue",@TAB,sDirPath2)
MsgTitle = "udfDirGetTrue ()    Get true path of a folder"
Message(MsgTitle,MsgText)

DirChange("..")
iResult = DirRemove(StrUpper(sDirPath)) ; uppercase works too

;------------------------------------------------------------------------------------------------------------------------------------------



;------------------------------------------------------------------------------------------------------------------------------------------
If ItemLocate("udfdirgetex",IntControl(77,103,0,0,0),@TAB) Then Goto skip_udfdirgetex

#DefineFunction udfDirGetEx ()
sDirGet = DirGet() ; use WIL's ready made function
iMAX_PATH = 262
hBB = BinaryAlloc(iMAX_PATH)
iLength = DllCall(StrCat(DirWindows(1),"kernel32.dll"),long:"GetLongPathNameA",lpstr:sDirGet,lpbinary:hBB,long:iMAX_PATH)
BinaryEodSet(hBB,iLength)
sLongPathName = BinaryPeekStr(hBB,0,iLength)
BinaryFree(hBB)
Return (sLongPathName)
#EndFunction

:skip_udfdirgetex
;------------------------------------------------------------------------------------------------------------------------------------------

;--- test ---
sDirPath = "d:\tEmP\tRuEnAmEtEsT\"  ; just a common name
iResult = DirMake(sDirPath)

sDirPath = StrLower(sDirPath)       ; lowercase works
iResult = DirChange(sDirPath)

sDirPath1 = DirGet()                ; appears as in last use of DirChange
sDirPath2 = udfDirGetEx()           ; the actually really true name

MsgText  = StrCat("DirGet",@TAB,@TAB,sDirPath1,@CRLF,"udfDirGetEx",@TAB,sDirPath2)
MsgTitle = "udfDirGetEx ()    Get true path of a folder"
Message(MsgTitle,MsgText)

DirChange("..")
iResult = DirRemove(StrUpper(sDirPath)) ; uppercase works too

;------------------------------------------------------------------------------------------------------------------------------------------



;------------------------------------------------------------------------------------------------------------------------------------------
If ItemLocate("udfdirgetlong",IntControl(77,103,0,0,0),@TAB) Then Goto skip_udfdirgetlong

#DefineFunction udfDirGetLong ()
Return (StrCat(FileNameLong(StrCat(DirGet(),".")),"\"))
#EndFunction

:skip_udfdirgetlong
;------------------------------------------------------------------------------------------------------------------------------------------

;--- test ---
sDirPath = "d:\tEmP\tRuEnAmEtEsT\"  ; just a common name
iResult = DirMake(sDirPath)

sDirPath = StrLower(sDirPath)       ; lowercase works
iResult = DirChange(sDirPath)

sDirPath1 = DirGet()                ; appears as in last use of DirChange
sDirPath2 = udfDirGetLong()         ; the actually really true name

MsgText  = StrCat("DirGet",@TAB,@TAB,sDirPath1,@CRLF,"udfDirGetLong",@TAB,sDirPath2)
MsgTitle = "udfDirGetLong ()    Get true path of a folder"
Message(MsgTitle,MsgText)

DirChange("..")
iResult = DirRemove(StrUpper(sDirPath)) ; uppercase works too

;------------------------------------------------------------------------------------------------------------------------------------------



;------------------------------------------------------------------------------------------------------------------------------------------
:performancetest
MsgTitle  = "Demo udfDirGetTrue udfDirGetEx udfDirGetLong   Performance Test"
TestLoop  = 100

Maxtests = 3
For t=1 To 1
   Display(1,MsgTitle,"Running Test %t%, please wait ...")
   Exclusive(@ON)
   start = GetTickCount()
   For i=1 To TestLoop
      str = udfDirGetTrue ()
   Next
   stop = GetTickCount()
   Exclusive(@OFF)
   Ticks%t% = stop-start
Next
For t=2 To 2
   Display(1,MsgTitle,"Running Test %t%, please wait ...")
   Exclusive(@ON)
   start = GetTickCount()
   For i=1 To TestLoop
      str = udfDirGetEx ()
   Next
   stop = GetTickCount()
   Exclusive(@OFF)
   Ticks%t% = stop-start
Next
For t=3 To 3
   Display(1,MsgTitle,"Running Test %t%, please wait ...")
   Exclusive(@ON)
   start = GetTickCount()
   For i=1 To TestLoop
      str = udfDirGetLong ()
   Next
   stop = GetTickCount()
   Exclusive(@OFF)
   Ticks%t% = stop-start
Next

MaxTicks = 0
For t=1 To MaxTests
   MaxTicks = Max(MaxTicks,Ticks%t%)
Next
For t=1 To MaxTests
   Pct%t% = 100*Ticks%t%/MaxTicks
Next
MsgText = ""
For t=1 To MaxTests
   MsgText = StrCat(MsgText,"Test ",t,@TAB,"Ticks = ",@TAB,Ticks%t%,@TAB,Pct%t%," %%",@CRLF)
Next
Message(MsgTitle,MsgText)

Exit
;------------------------------------------------------------------------------------------------------------------------------------------




Article ID:   W15314
File Created: 2002:11:07:15:21:22
Last Updated: 2002:11:07:15:21:22