Posted: Mon Nov 17, 2008 3:39 am Post subject: FindFirstFile, FindNextFile API function question
*I heard somewhere that each directory in windows contains two folders/files : "." and ".." Can anyone confirm and explain that for us .
*Also, i made some code in VB6 to add the file names in a directory to a combo box. I made it with reference to sample source codes, and to ensure that the "." and ".." file names are not added to the combo box, the code first removes any nulls in the file name, and then checks if its the "." or ".." -> the last part is a little trivial.
As you'll see in he code below (which works well the way it is), an if_statement checks if the filename is BOTH "." and ".." at the same time, and if so, then the file name is not added to the combobox.
>>so how is it that we need to check if a filename is not both "." and ".." at the same time; so that these file names are not added to the combo box???
the code: - you should declare the FindFirstFiles and FindNxtFile APi functions first......if you cant, PM me....
Code:
Private Sub FillCombo()
'On Error GoTo err
Dim path As String, fileName As String, hSearch As Long, _
wfd As WIN32_FIND_DATA, cont As Integer
path = App.path & "\ccc\*.*"
hSearch = FindFirstFile(path, wfd)
cont = 1
Do While cont <> 0
fileName = StripNulls(wfd.cFileName)
If fileName <> "." And fileName <> ".." Then cmb.AddItem Left(fileName, Len(fileName) - 4)
cont = FindNextFile(hSearch, wfd)
Loop
lblCount.Caption = cmb.ListCount & " *.au3 files."
FindClose hSearch
Exit Sub
err:
MsgBox "some error"
End Sub
Function StripNulls(OriginalStr As String) As String
If (InStr(OriginalStr, Chr(0)) > 0) Then
OriginalStr = Left(OriginalStr, InStr(OriginalStr, Chr(0)) - 1)
End If
StripNulls = OriginalStr
End Function
____________ whats worse than getting owned
-> not knowing it....
oh, you'll need
1> a combo box named "cmb"
2> a label named> "lblCount"
3> a brain and some intellect
4> if u have no. 3, then u should have a comp with VS [am writing this just in case].
The directory your code is chacking is stored in the variable "path".
My code sets it to "app.path & "\ccc""
and that's coz i had that particular directory in my HDD
So u should set it to a directory u have> get nifty and use a few text boxes, file-list boxes....and such here and there.
It'll be fun, and u'll learn a lot. Make this code more useful ____________ whats worse than getting owned
-> not knowing it....
I don't play with VB so I can't comment on the code but I can tell you that windows does have 2 directories named . and .. in each folder. The "." directory is a reference to the current directory you are in and the ".." directory is a reference to the next highest folder in the hierarchy. So for example, if you were to have a folder setup like this:
C:\Users\Binary and you were in Binary then "." would point to C:\Users\Binary\ and ".." would point to C:\Users\
This is helpful for directory transversal if you are attacking a site vulnerable to LFI you and the files included were in C:\includes\ and you wanted to get a file from C:\passwordFiles\ then you could inject ..\passwordFiles\passwordFileYouWant. ____________ A.K.A DigitalOutcast
Rawr!