|
|
|
DD381800.HTM DD-Software.Disk Add this page to your favorites Save this document |
|
|
||||
|
|
||||
udfAddBackslash (sString) |
||||
;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfAddBackslash_1 (sString)
If (StrSub(sString,StrLen(sString),1)<>"\") Then sString = StrCat(sString,"\")
; Seems to be the fastest, if a trailing backslash already exists.
Return (sString)
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfAddBackslash_2 (sString)
If (StrIndex(sString,"\",0,@BACKSCAN)<>StrLen(sString)) Then sString = StrCat(sString,"\")
Return (sString)
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfAddBackslash_3 (sString)
Return (StrCat(sString,StrSub("\",1,(StrSub(sString,StrLen(sString),1)<>"\"))))
; Seems to be the fastest, if no trailing backslash exists.
; Detlev Dalitz.20010731
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------
;--- test ---
a = "D:\TEMP"
b = "D:\TEMP\"
c = "test.txt"
d = StrCat(a,StrSub("\",1,(StrSub(a,StrLen(a),1)<>"\")),c)
e = StrCat(b,StrSub("\",1,(StrSub(b,StrLen(b),1)<>"\")),c)
f = udfAddBackslash_3(a)
g = udfAddBackslash_3(b)
:performancetest
msgtitle = "Demo udfAddBackslash (sString) Performance Test"
TestStr = "D:\TEMP"
;TestStr = "D:\TEMP\"
TestLoop = 200
MaxTests = 3
For t=1 To MaxTests
Display(1,msgtitle,"Running Test %t%, please wait ...")
Exclusive(@ON)
start = GetTickCount()
For i=1 To TestLoop
sString = udfAddBackslash_%t% (TestStr)
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
;------------------------------------------------------------------------------------------------------------------------------------------
|
||||
| If you have questions about WinBatch, you are encouraged to use online WebBoard BBS at http://webboard.windowware.com | ||||
|
|
|
|
||||
|
|
||||
udfDelBackslash (str)
|
||||
;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfDelBackslash_1 (str)
len=StrLen(str)
If(StrSub(str,len,1)=="\")Then Return(StrSub(str,1,len-1))
Return(str)
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfDelBackslash_2 (str)
len=StrLen(str)
If(StrIndex(str,"\",0,@BACKSCAN)==len)Then Return(StrSub(str,1,len-1))
Return(str)
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfDelBackslash_3 (str)
Return(StrSub(str,1,StrLen(str)-(StrSub(str,StrLen(str),1)=="\")))
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfDelBackslash_4 (str, mode)
len=StrLen(str)
Select 1
Case(mode==0)
Case(mode==2)
While(StrSub(str,len,1)=="\")
len=len-1
str=StrSub(str,1,len)
EndWhile
If(mode==2)Then str=StrCat(str,"\")
Break
Case(mode==1)
If(StrSub(str,len,1)=="\")
len=len-1
str=StrSub(str,1,len)
EndIf
Break
EndSelect
Return (str)
; mode=0 delete all trailing backslashes
; mode=1 delete one trailing backslash
; mode=2 keep only one backslash
; DD.20010801.20020209
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------
;--- test ---
str10 = "D:\TEMP\"
str11 = udfDelBackslash_1(str10)
str12 = udfDelBackslash_2(str10)
str13 = udfDelBackslash_3(str10)
str20 = "D:\TEMP\\"
str21 = udfDelBackslash_1(str20)
str22 = udfDelBackslash_2(str20)
str23 = udfDelBackslash_3(str20)
str30 = "D:\TEMP\\\\\\\\\\\\\\"
While (StrSub(str30,StrLen(str30),1)=="\")
str30 = udfDelBackslash_3(str30)
EndWhile
str40 = "D:\TEMP\\\\\\\\\\\\\\"
done = @FALSE
While !done
lenpre = StrLen(str40)
str40 = udfDelBackslash_3(str40)
lenpost = StrLen(str40)
done = (lenpre==lenpost)
EndWhile
str41 = "D:\TEMP\\\\\\\\\\\\\\"
lenpre = 0
lenpost = !lenpre
While (lenpre <> lenpost)
lenpre = StrLen(str41)
str41 = udfDelBackslash_3(str41)
lenpost = StrLen(str41)
EndWhile
str50 = "D:\TEMP\\\\\\\\\\\\\\"
str51 = udfDelBackslash_4(str50,0)
str52 = udfDelBackslash_4(str50,1)
str53 = udfDelBackslash_4(str50,2)
:performancetest
msgtitle = "Demo udfDelBackslash (str) Performance Test"
;TestStr = "D:\TEMP"
TestStr = "D:\TEMP\"
;TestStr = "D:\TEMP\\\\\\\\\\\\\\"
TestLoop = 400
For t=1 To 3
Display(1,msgtitle,"Running Test %t%, please wait ...")
Exclusive(@ON)
start = GetTickCount()
For i=1 To TestLoop
str = udfDelBackslash_%t% (TestStr)
Next
stop = GetTickCount()
Exclusive(@OFF)
Ticks%t% = stop-start
Next
t=4
For m=0 To 2
Display(1,msgtitle,"Running Test %t% mode %m%, please wait ...")
Exclusive(@ON)
start = GetTickCount()
For i=1 To TestLoop
str = udfDelBackslash_%t% (TestStr,%m%)
Next
stop = GetTickCount()
Exclusive(@OFF)
ti=t+m
Ticks%ti% = stop-start
Next
MaxTests = 6
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
;------------------------------------------------------------------------------------------------------------------------------------------
|
||||
| If you have questions about WinBatch, you are encouraged to use online WebBoard BBS at http://webboard.windowware.com | ||||
|
|
|
|
||||
|
|
||||
udfDelEmptyTree (dir)
|
||||
;----------------------------------------------------------------------------------------------------------------------
; udfDelEmptyTree (dir)
; udfDelTree (dir)
; udfDelTree_2 (dir, mode)
; udfGetTempPath ()
;----------------------------------------------------------------------------------------------------------------------
If ItemLocate("udfdelemptytree",IntControl(77,103,0,0,0),@tab) Then Goto skip_udfdelemptytree
#DefineFunction udfDelEmptyTree (dir)
origdir = DirGet()
DirChange(dir)
dirlist = DirItemize("*.*")
dircount = ItemCount(dirlist,@tab)
For d=1 To dircount
thisdir = ItemExtract(d,dirlist,@tab)
udfDelEmptyTree(thisdir) ; recursive
Next
filelist = FileItemize("*.*")
empty = (filelist=="") && (dirlist=="")
DirChange("..")
If empty ; maybe not really empty anyway
oldmode = ErrorMode(@off) ; suppress error message
DirRemove(dir)
ErrorMode(oldmode)
EndIf
DirChange(origdir)
Return
; dir = the root dir of the foldertree to be deleted
; note: only empty folders will be deleted
;
; modified by Detlev Dalitz.20020530
#EndFunction
:skip_udfdelemptytree
;----------------------------------------------------------------------------------------------------------------------
If ItemLocate("udfdeltree",IntControl(77,103,0,0,0),@tab) Then Goto skip_udfdeltree
#DefineFunction udfDelTree (dir)
IntControl(5,1,0,0,0) ; System & Hidden files or directories are seen and used
origdir = DirGet()
DirChange(dir)
dirlist = DirItemize("*.*")
DirAttrset(dirlist,"rash")
dircount = ItemCount(dirlist,@tab)
For d=1 To dircount
thisdir = ItemExtract(d,dirlist,@tab)
udfDelTree(thisdir) ; recursive
Next
FileAttrSet("*.*","rash")
FileDelete("*.*")
DirChange("..")
DirRemove(dir)
DirChange(origdir)
IntControl(5,0,0,0,0) ; protect System & Hidden files and directories
Return
; dir = the root dir of the foldertree to be deleted.
; Note: This udf can see hidden & system directory attribute by IntControl(5,1,0,0,0).
; The deletion of all files and almost all directories is a hazardous act.
; Have caution on doing this! Folders and their files will be deleted without permission!
;
; based on Article in WinBatch TechBase
; Article ID: W14748
; Filename: DelTree and Xcopy.txt
; File Created: 2001:03:19:15:12:22
;
; modified by Detlev Dalitz.20020530
#EndFunction
:skip_udfdeltree
;----------------------------------------------------------------------------------------------------------------------
If ItemLocate("udfdeltree_2",IntControl(77,103,0,0,0),@tab) Then Goto skip_udfdeltree_2
#DefineFunction udfDelTree_2 (dir, mode)
mode = Min(2,Max(0,mode))
If (mode==2) Then IntControl(5,1,0,0,0) ; System & Hidden files or directories are seen and used
origdir = DirGet()
DirChange(dir)
dirlist = DirItemize("*.*")
dircount = ItemCount(dirlist,@tab)
For d=1 To dircount
thisdir = ItemExtract(d,dirlist,@tab)
udfDelTree_2(thisdir, mode) ; recursive
Next
Select mode
Case 0
filelist = FileItemize("*.*")
empty = (filelist=="") && (dirlist=="")
DirChange("..")
If empty ; maybe not really empty anyway
oldmode = ErrorMode(@off) ; suppress error message
DirRemove(dir)
ErrorMode(oldmode)
EndIf
Break
Case 1
FileAttrSet("*.*","rash")
oldmode = ErrorMode(@off) ; suppress error message
FileDelete("*.*")
ErrorMode(oldmode)
DirChange("..")
DirAttrset(dir,"rash")
oldmode = ErrorMode(@off) ; suppress error message
DirRemove(dir)
ErrorMode(oldmode)
Break
Case 2
FileAttrSet("*.*","rash")
FileDelete("*.*")
DirChange("..")
DirAttrset(dir,"rash")
DirRemove(dir)
Break
EndSelect
DirChange(origdir)
IntControl(5,0,0,0,0) ; protect System & Hidden files and directories
Return
; dir = the root dir of the foldertree to be deleted
; mode = 0 = Delete empty folders only.
; mode = 1 = Delete all folders, if empty or not, but respect hidden & system attributes.
; mode = 2 = Force deleting all files and folders by IntControl(5,1,0,0,0).
; Note: Hidden folders are not visible for DirItemize.
;
; based on WinBatch TechBase
; Article ID: W14748
; Filename: DelTree and Xcopy.txt
; modified by Detlev Dalitz.20020530
#EndFunction
:skip_udfdeltree_2
;----------------------------------------------------------------------------------------------------------------------
If ItemLocate("udfgettemppath",IntControl(77,103,0,0,0),@tab) Then Goto skip_udfgettemppath
#DefineFunction udfGetTempPath ()
ftemp = FileCreateTemp("TMP")
FileDelete(ftemp)
TempPath = FilePath(ftemp)
Terminate(!DirMake(TempPath),"udfGetTempPath",StrCat("Cannot access temporary folder:",@crlf,TempPath))
Return (TempPath)
#EndFunction
:skip_udfgettemppath
;----------------------------------------------------------------------------------------------------------------------
; ---- test ----
pausetitle = "Demo 'Delete Foldertree' routines"
; create foldertree
pausetext = StrCat(@crlf,"Press OK to continue ...")
pausetext = StrCat("Create test foldertree",@crlf,pausetext)
Pause(pausetitle,pausetext)
tempfolder = udfGetTempPath()
testroot = StrCat(tempfolder,"xxxx\")
maxtop = 5
maxsub = 2
maxfiles = 4
For top=1 To maxtop
For sub=1 To maxsub
folder = StrCat(testroot,"top",top,"\","sub",sub,"\")
DirMake(folder)
DirChange(folder)
If (sub mod 2) ; fill odd folders with files
For i=1 To maxfiles
file = StrCat("file",i)
If !FileExist(file) Then FileClose(FileOpen(file,"WRITE")) ; create zero length file
If (i mod 2) Then FileAttrSet(file,"RASH") ; set attributes to odd files
Next
EndIf
If !(top mod 2) Then DirAttrset(folder,"RASH") ; set attributes to folder
DirChange(testroot)
Next
Next
; start explorer to view foldertree
pausetext = StrCat(@crlf,"Press OK to continue ...")
pausetext = StrCat("Start Explorer to view original foldertree",@crlf,pausetext)
Pause(pausetitle,pausetext)
Run("explorer.exe",StrCat("/e, /root, ",testroot))
WinWaitExist("~Explorer",-1)
explorer = WinGetactive()
SendKeysTo(explorer,"{NUMPAD*}")
SendKeysTo(explorer,"{DOWN 2}")
TimeDelay(2)
; test 1
pausetext = StrCat(@crlf,"Press OK to continue ...")
pausetext = StrCat("Test 1: udfDelEmptyTree (dir) and view result",@crlf,pausetext)
Pause(pausetitle,pausetext)
foldertree = StrCat(testroot,"top1\")
udfDelEmptyTree (foldertree)
WinActivate(explorer)
TimeDelay(1)
SendKeysTo(explorer,"{F5}") ; refresh
TimeDelay(1)
; test 2
pausetext = StrCat(@crlf,"Press OK to continue ...")
pausetext = StrCat("Test 2: udfDelTree (dir) and view result",@crlf,pausetext)
Pause(pausetitle,pausetext)
foldertree = StrCat(testroot,"top2\")
udfDelTree (foldertree)
WinActivate(explorer)
TimeDelay(1)
SendKeysTo(explorer,"{F5}") ; refresh
TimeDelay(1)
; test 3
pausetext = StrCat(@crlf,"Press OK to continue ...")
pausetext = StrCat("Test 3: udfDelTree_2 (dir, 0) and view result",@crlf,pausetext)
Pause(pausetitle,pausetext)
foldertree = StrCat(testroot,"top3\")
udfDelTree_2 (foldertree, 0)
WinActivate(explorer)
TimeDelay(1)
SendKeysTo(explorer,"{F5}") ; refresh
TimeDelay(1)
; test 4
pausetext = StrCat(@crlf,"Press OK to continue ...")
pausetext = StrCat("Test 4: udfDelTree_2 (dir, 1) and view result",@crlf,pausetext)
Pause(pausetitle,pausetext)
foldertree = StrCat(testroot,"top4\")
udfDelTree_2 (foldertree, 1)
WinActivate(explorer)
TimeDelay(1)
SendKeysTo(explorer,"{F5}") ; refresh
TimeDelay(1)
; test 5
pausetext = StrCat(@crlf,"Press OK to continue ...")
pausetext = StrCat("Test 5: udfDelTree_2 (dir, 2) and view result",@crlf,pausetext)
Pause(pausetitle,pausetext)
foldertree = StrCat(testroot,"top5\")
udfDelTree_2 (foldertree, 2)
WinActivate(explorer)
TimeDelay(1)
SendKeysTo(explorer,"{F5}") ; refresh
TimeDelay(1)
; cleaning
pausetext = StrCat(@crlf,"Press OK to continue ...")
Pause(pausetitle,pausetext)
:cancel
If IsDefined(explorer) Then If WinExist(explorer) Then WinClose(explorer)
If IsDefined(tempfolder) Then DirChange(tempfolder)
If IsDefined(testroot) Then udfDelTree (testroot)
Message(pausetitle,"Done.")
Exit
;----------------------------------------------------------------------------------------------------------------------
|
||||
| If you have questions about WinBatch, you are encouraged to use online WebBoard BBS at http://webboard.windowware.com | ||||
|
|
|
|
||||
|
|
||||
udfGetDiskUsagePct (drivelist) |
||||
If itemlocate("udfgetdiskusagepct", IntControl(77,103,0,0,0), @tab) then goto skip_udfgetdiskusagepct
#DefineFunction udfGetDiskUsagePct (drivelist)
ds = 0.0 + DiskSize(drivelist)
df = DiskFree(drivelist)
Return (100*(ds-df)/max(1,ds))
; returns disk usage in percent, e.g. 92.34567890
; drivelist is a string, composed of one or more drive letters,
; separated by "|", or the current file delimiter (usually a tab).
; From: Marty marty@winbatch.com
; Date: Friday, October 26, 2001 03:40 PM
#EndFunction
:skip_udfgetdiskusagepct
;--- test ---
message("Demo udfGetDiskUsagePct",StrCat("Drive C:",@crlf,"Percent used: ",udfGetDiskUsagePct("c")))
AllLocalDrives = DiskScan(2)
message("Demo udfGetDiskUsagePct",StrCat("All local drives ",@crlf,AllLocalDrives,@crlf,"%% used = ",udfGetDiskUsagePct(AllLocalDrives)))
AllRemoteDrives = DiskScan(4)
message("Demo udfGetDiskUsagePct",StrCat("All remote drives ",@crlf,AllRemoteDrives,@crlf,"%% used = ",udfGetDiskUsagePct(AllRemoteDrives)))
Exit
|
||||
| If you have questions about WinBatch, you are encouraged to use online WebBoard BBS at http://webboard.windowware.com | ||||
|
|
|
|
||||
|
|
||||
udfGetNextUnusedDiskID () |
||||
If itemlocate("udfgetnextunuseddiskid", IntControl(77,103,0,0,0), @tab) then goto skip_udfgetnextunuseddiskid
#DefineFunction udfGetNextUnusedDiskId ()
Return (ItemExtract(1,DiskScan(0),@tab))
; DD.20020130
#EndFunction
:skip_udfgetnextunuseddiskid
;--- test ---
DiskId = udfGetNextUnusedDiskId()
If (DiskID=="") then DiskID = "not available."
Message("Demo udfGetUnusedDiskId ()",StrCat("Next unused DiskID is ",DiskID))
Exit
|
||||
| If you have questions about WinBatch, you are encouraged to use online WebBoard BBS at http://webboard.windowware.com | ||||
|
|
|
|
||||
|
|
||||
udfGetUNCFromDrive (localdrive) |
||||
#DefineFunction udfGetUNCFromDrive(localdrive)
localdrive = StrSub(localdrive,1,2)
dword = BinaryAlloc(4)
bbuff = BinaryAlloc(256)
BinaryPoke4(dword, 0,255)
BinaryPoke(bbuff, 255,0)
dllcall(strcat(dirwindows(1),"MPR.DLL") ,long:"WNetGetConnectionA", lpstr:LocalDrive, lpbinary:bbuff, lpbinary:dword)
unc = BinaryPeekStr(bbuff,0,256)
BinaryFree(dword)
BinaryFree(bbuff)
Return (unc)
; returns the name of the network resource currently connected to a 'local name'.
; If the resource is not mapped a null string will be returned.
; same function like WIL'S extender functions: n3DrivePath, n4DrivePath, w95GetCon, wntGetCon, netGetCon
; Topic: UNC Path from a maped drive
; Conf: WinBatch
; From: akreutzer kreutzer@ost.state.or.us
; Date: Tuesday, July 31, 2001 07:44 AM
#EndFunction
;--- test ---
netrsrc = udfGetUNCFromDrive("W:")
If netrsrc=="" then Message("Drive W: is","not mapped")
else Message("Drive W: is mapped to",netrsrc)
exit
|
||||
| If you have questions about WinBatch, you are encouraged to use online WebBoard BBS at http://webboard.windowware.com | ||||
|
|
|
|
||||
|
|
||||
udfGetZeroDirs (rootdir, mode) |
||||
If (ItemLocate("udfgetzerodirs",IntControl(77,103,0,0,0),@tab)>0) Then Goto skip_udfgetzerodirs
#DefineFunction udfGetZeroDirs (dir, mode)
mode = Min(1,Max(0,mode))
If (mode==1) Then IntControl(5,1,0,0,0) ; System & Hidden files or directories are seen and used
origdir = DirGet()
DirChange(dir)
list = ""
dirlist = DirItemize("*.*")
dircount = ItemCount(dirlist,@tab)
For i=1 To dircount
thisdir = ItemExtract(i,dirlist,@tab)
ds = DirSize(thisdir,0)
If (ds==0)
name = StrCat(DirGet(),thisdir)
list = ItemInsert(name,-1,list,@tab)
EndIf
str = udfGetZeroDirs(thisdir,mode)
If (str <> "") Then list = ItemInsert(str,-1,list,@tab)
Next
DirChange(origdir)
IntControl(5,0,0,0,0) ; protect System & Hidden files and directories
Return (list)
; Returns a tab delimited itemlist of directorynames.
; mode = 0 = Normal operation, no use of hidden & system attributed folders.
; mode = 1 = Inspect hidden & system attributed folders too.
;
; Detlev Dalitz.20020616
#EndFunction
:skip_udfgetzerodirs
; --- test ---
msgtitle = "Demo udfGetZeroDirs (dir, filehandle)"
BoxOpen (msgtitle,"... running ...")
root = AskDirectory(StrCat(msgtitle,@crlf,"Select root for search"),"","","Are you sure?",1|2)
dirlist = udfGetZeroDirs(root,1)
tempfile = FileCreateTemp("TMP")
fw = FileOpen(tempfile,"write")
FileWrite(fw,StrReplace(dirlist,@tab,@crlf))
FileClose(fw)
If FileExist(tempfile)
RunWait("notepad",tempfile)
FileDelete(tempfile)
EndIf
BoxButtondraw(1,1,"&Ok","20,780,980,950")
BoxText("Done.")
BoxButtonwait()
BoxShut()
Exit
|
||||
| If you have questions about WinBatch, you are encouraged to use online WebBoard BBS at http://webboard.windowware.com | ||||
|
|
|
|
||||
|
|
||||
udfIsUnusedDrive (DriveLetter) |
||||
;---------------------------------------------------------------------------------------------------- ; udfIsUnusedDrive (DriveLetter) ; DD.2002:07:05:09:57:26 ; udfIsRemovableDrive (DriveLetter) ; DD.2002:07:05:09:57:26 ; udfIsLocalDrive (DriveLetter) ; DD.2002:07:05:09:57:27 ; udfIsNetDrive (DriveLetter) ; DD.2002:07:05:09:57:27 ; udfIsCDROMDrive (DriveLetter) ; DD.2002:07:05:09:57:27 ; udfIsRAMDrive (DriveLetter) ; DD.2002:07:05:09:57:27 ; udfIsLocalDrive (DriveLetter) ; DD.2002:07:05:09:57:27 ; udfIsUnknownDrive (DriveLetter) ; DD.2002:07:05:09:57:27 ;---------------------------------------------------------------------------------------------------- #DefineFunction udfIsUnusedDrive (DriveLetter) Return (StrScan(DiskScan(0),StrUpper(StrSub(DriveLetter,1,1)),1,@fwdscan)>0) #EndFunction #DefineFunction udfIsRemovableDrive (DriveLetter) Return (StrScan(DiskScan(1),StrUpper(StrSub(DriveLetter,1,1)),1,@fwdscan)>0) #EndFunction #DefineFunction udfIsLocalDrive (DriveLetter) Return (StrScan(DiskScan(2),StrUpper(StrSub(DriveLetter,1,1)),1,@fwdscan)>0) #EndFunction #DefineFunction udfIsNetDrive (DriveLetter) Return (StrScan(DiskScan(4),StrUpper(StrSub(DriveLetter,1,1)),1,@fwdscan)>0) #EndFunction #DefineFunction udfIsCDROMDrive (DriveLetter) Return (StrScan(DiskScan(8),StrUpper(StrSub(DriveLetter,1,1)),1,@fwdscan)>0) #EndFunction #DefineFunction udfIsRAMDrive (DriveLetter) Return (StrScan(DiskScan(16),StrUpper(StrSub(DriveLetter,1,1)),1,@fwdscan)>0) #EndFunction #DefineFunction udfIsUnknownDrive (DriveLetter) DriveLetter = StrUpper(StrSub(DriveLetter,1,1)) If (StrScan(DiskScan( 0),DriveLetter,1,@fwdscan)>0) Then Return (@false) If (StrScan(DiskScan( 1),DriveLetter,1,@fwdscan)>0) Then Return (@false) If (StrScan(DiskScan( 2),DriveLetter,1,@fwdscan)>0) Then Return (@false) If (StrScan(DiskScan( 4),DriveLetter,1,@fwdscan)>0) Then Return (@false) If (StrScan(DiskScan( 8),DriveLetter,1,@fwdscan)>0) Then Return (@false) If (StrScan(DiskScan(16),DriveLetter,1,@fwdscan)>0) Then Return (@false) Return (@true) #EndFunction ;#DefineFunction udfIsLocalDrive (DriveLetter) ;DriveLetter = StrCat(StrUpper(StrSub(DriveLetter,1,1)),":") ;Drives = DiskScan (2) ;Return (ItemLocate(DriveLetter,Drives,@tab)>0) ;#EndFunction Info = "n:\notes\data" IsUnusedDrive = udfIsUnusedDrive (Info) IsRemovableDrive = udfIsRemovableDrive (Info) IsLocalDrive = udfIsLocalDrive (Info) IsNetDrive = udfIsNetDrive (Info) IsCDROMDrive = udfIsCDROMDrive (Info) IsRAMDrive = udfIsRAMDrive (Info) IsUnknownDrive = udfIsUnknownDrive (Info) Exit |
||||
| If you have questions about WinBatch, you are encouraged to use online WebBoard BBS at http://webboard.windowware.com | ||||
|
|
|
|
||||
|
|
||||
udfIsValidFilename (sFilename, iMode) |
||||
;------------------------------------------------------------------------------------------------------------------------------------------
If ItemLocate("udfisvalidfilename",IntControl(77,103,0,0,0),@TAB) Then Goto skip_udfisvalidfilename
#DefineFunction udfIsValidFilename (sFilename, iMode)
Select iMode
Case 0 ; DOS SFN
sRoot=FileRoot(sFilename)
iRootLen=StrLen(sRoot)
If (iRootLen>8) Then Return @FALSE
If (iRootLen==0) Then Return @FALSE
sExt=FileExtension(sFilename)
iExtLen=StrLen(sExt)
If (iExtLen>3) Then Return @FALSE
sDOSReservedNamesList="con|nul|prn|lpt1|lpt2|lpt3|com1|com2|com3|com4|aux|clock$"
If (ItemLocate(sRoot,sDOSReservedNamesList,"|")>0) Then Return @FALSE
sDosValidCharsList="abcdefghijklmnopqrstuvwxyz0123456789_^$~!%%&#-{}()@'`"
If (StrClean(sRoot,sDosValidCharsList,"",@FALSE,1)!="") Then Return @FALSE
If (iExtLen>0)
If (StrClean(sExt,sDosValidCharsList,"",@FALSE,1)!="") Then Return @FALSE
EndIf
Return @TRUE
Break
Case 1 ; Windows LFN
sRoot=FileRoot(sFilename)
iRootLen=StrLen(sRoot)
iExtLen=StrLen(FileExtension(sFilename))
If ((iRootLen+iExtLen)==0) Then Return @FALSE
If ((iRootLen+iExtLen)>=215) Then Return @FALSE
sDOSReservedNamesList="con|nul|prn|lpt1|lpt2|lpt3|com1|com2|com3|com4|aux|clock$"
If (ItemLocate(sRoot,sDOSReservedNamesList,"|")>0) Then Return @FALSE
sWinInvalidCharsList='\/:*?"<>|'
sWinValidCharsList=""
For i=1 To 255
sWinValidCharsList=StrCat(sWinValidCharsList,Num2Char(i))
Next
sWinValidCharsList=StrClean(sWinValidCharsList,sWinInvalidCharsList,"",@FALSE,1)
sFilename=StrClean(sFilename,sWinValidCharsList,"",@FALSE,1)
sFilename=StrClean(sFilename,".","",@FALSE,1)
If (sFilename!="") Then Return @FALSE
Return @TRUE
Break
EndSelect
Return @FALSE
;..........................................................................................................................................
; This udf validates if given filename is suitable filename for DOS or Windows.
; iMode=0 ... DOS-SFN ShortFileName
; File name check using abcdefghijklmnopqrstuvwxyz0123456789_^$~!%%&#-{}()@'` as per MS-DOS reference manual.
; iMode=1 ... Win95-LFN LongFileName, File name check for a maximum length of 215 characters.
;
; Based on example by Steffen Fraas 20010417 sfraas@zoo.co.uk.
; Published In WinBatch TechDataBase
; Article ID: W15015
; File Created: 2001:04:18:14:32:25
; Modified by Detlev Dalitz.20010701.20020209
;..........................................................................................................................................
#EndFunction
:skip_udfisvalidfilename
;------------------------------------------------------------------------------------------------------------------------------------------
;--- test ---
sTestList = "validdos.fil|validdoss.fil|validdos.file|valid.|aux|prn.|com1:|.|"
For i=1 To ItemCount(sTestlist,"|")
sFilename = ItemExtract(i,sTestList,"|")
Message(sFilename,StrCat(ItemExtract(1+udfIsValidFilename(sFilename,0),"invalid,valid",",")," DOS name."))
Next
sTestList = "valid.win.fil|valid,win.fil|valid?|v.a.l.i.d.w.i.n.f.i.l.e.!|valid.aux.file|aux.tmp|aux|prn.|com1:|.|.test|"
For i=1 To ItemCount(sTestlist,"|")
sFilename = ItemExtract(i,sTestList,"|")
Message(sFilename,StrCat(ItemExtract(1+udfIsValidFilename(sFilename,1),"invalid,valid",",")," Windows name."))
Next
Exit
;------------------------------------------------------------------------------------------------------------------------------------------
|
||||
| If you have questions about WinBatch, you are encouraged to use online WebBoard BBS at http://webboard.windowware.com | ||||
|
|
|
|
||||
|
|
||||
udfSearchTreeForFile (root, filename) |
||||
If ItemLocate("udfsearchtreeforfile", IntControl(77, |