Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Where's the Filesystem object?

Status
Not open for further replies.

MikeLacey

MIS
Nov 9, 1998
13,212
GB
I'm using VB5 and the help file mentions this object but doesn't say where to find it. Anyone know?<br>
<br>
Probably a really stupid question....<br>
<br>
-ml<br>
<p>Mike Lacey<br><a href=mailto:Mike_Lacey@Cargill.Com>Mike_Lacey@Cargill.Com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
What is exactly do you want to do. Find the Operating System?
 
ML<br>
<br>
Make a reference to the microsoft scripting library, its part of that object model<br>
<br>
C
 
I should just have asked this question in the first place - since I can't work out how to use the filesystem or file object.<br>
<br>
I need to know the creation/last access/modification time of a file.<br>
<br>
I can see the properties in the File object but I'm not getting anywhere trying to use that - help appreciated.<br>
<br>
I should stick to databases.<br>
<br>
Mike<br>
<p>Mike Lacey<br><a href=mailto:Mike_Lacey@Cargill.Com>Mike_Lacey@Cargill.Com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
Option Explicit<br>
<br>
Dim dc As Integer<br>
<br>
Private Const BIF_RETURNONLYFSDIRS = 1<br>
Private Const BIF_DONTGOBELOWDOMAIN = 2<br>
Private Const MAX_PATH = 260<br>
<br>
Private Declare Function SHBrowseForFolder Lib &quot;shell32&quot; (lpbi As BrowseInfo) As Long<br>
Private Declare Function SHGetPathFromIDList Lib &quot;shell32&quot; (ByVal pidList As Long, ByVal lpBuffer As String) As Long<br>
Private Declare Function lstrcat Lib &quot;kernel32&quot; Alias &quot;lstrcatA&quot; (ByVal lpString1 As String, ByVal lpString2 As String) As Long<br>
<br>
Private Type BrowseInfo<br>
hWndOwner As Long<br>
pIDLRoot As Long<br>
pszDisplayName As Long<br>
lpszTitle As Long<br>
ulFlags As Long<br>
lpfnCallback As Long<br>
lParam As Long<br>
iImage As Long<br>
End Type<br>
<br>
Sub fillist1()<br>
<br>
Dim li As ListItem<br>
Dim i As Integer<br>
Dim j As Integer<br>
Dim fs As New FileSystemObject<br>
Dim fl As File<br>
Dim fl2 As File<br>
Dim nieuw As Boolean<br>
<br>
Me.MousePointer = vbHourglass<br>
File1.Path = Text1<br>
For i = ListView1.ListItems.Count To 1 Step -1<br>
ListView1.ListItems.Remove i<br>
Next i<br>
For i = 0 To File1.ListCount - 1<br>
Set fl = fs.GetFile(Text1 & File1.List(i))<br>
nieuw = True<br>
If Check1 = vbChecked Then<br>
For j = 0 To File2.ListCount - 1<br>
If UCase$(File1.List(i)) = UCase$(File2.List(j)) Then<br>
Set fl2 = fs.GetFile(Text2 & File2.List(j))<br>
If fl2.DateLastModified &gt;= fl.DateLastModified Then nieuw = False<br>
End If<br>
Next j<br>
End If<br>
If nieuw Then<br>
Set li = ListView1.ListItems.Add(, LCase$(File1.List(i)), LCase$(File1.List(i)))<br>
li.SubItems(1) = fl.Size<br>
li.SubItems(2) = Format$(fl.DateLastModified, &quot;dd-mm-yy hh:Nn:ss&quot;)<br>
End If<br>
Next i<br>
Label1 = CStr(ListView1.ListItems.Count) & &quot; van &quot; & CStr(File1.ListCount)<br>
Me.MousePointer = vbNormal<br>
<br>
End Sub<br>
<br>
Sub fillist2()<br>
<br>
Dim li As ListItem<br>
Dim i As Integer<br>
Dim j As Integer<br>
Dim fs As New FileSystemObject<br>
Dim fl As File<br>
Dim fl2 As File<br>
Dim nieuw As Boolean<br>
<br>
Me.MousePointer = vbHourglass<br>
File2.Path = Text2<br>
For i = ListView2.ListItems.Count To 1 Step -1<br>
ListView2.ListItems.Remove i<br>
Next i<br>
For i = 0 To File2.ListCount - 1<br>
Set fl = fs.GetFile(Text2 & File2.List(i))<br>
nieuw = True<br>
If Check2 = vbChecked Then<br>
For j = 0 To File1.ListCount - 1<br>
If UCase$(File2.List(i)) = UCase$(File1.List(j)) Then<br>
Set fl2 = fs.GetFile(Text1 & File1.List(j))<br>
If fl2.DateLastModified &gt;= fl.DateLastModified Then nieuw = False<br>
End If<br>
Next j<br>
End If<br>
If nieuw Then<br>
Set li = ListView2.ListItems.Add(, LCase$(File2.List(i)), LCase$(File2.List(i)))<br>
li.SubItems(1) = fl.Size<br>
li.SubItems(2) = Format$(fl.DateLastModified, &quot;dd-mm-yy hh:Nn:ss&quot;)<br>
End If<br>
Next i<br>
Label2 = CStr(ListView2.ListItems.Count) & &quot; van &quot; & CStr(File2.ListCount)<br>
Me.MousePointer = vbNormal<br>
<br>
End Sub<br>
<br>
Sub fillist2()<br>
<br>
Dim li As ListItem<br>
Dim i As Integer<br>
Dim j As Integer<br>
Dim fs As New FileSystemObject<br>
Dim fl As File<br>
Dim fl2 As File<br>
Dim nieuw As Boolean<br>
<br>
Me.MousePointer = vbHourglass<br>
File2.Path = Text2<br>
For i = ListView2.ListItems.Count To 1 Step -1<br>
ListView2.ListItems.Remove i<br>
Next i<br>
For i = 0 To File2.ListCount - 1<br>
Set fl = fs.GetFile(Text2 & File2.List(i))<br>
nieuw = True<br>
If Check2 = vbChecked Then<br>
For j = 0 To File1.ListCount - 1<br>
If UCase$(File2.List(i)) = UCase$(File1.List(j)) Then<br>
Set fl2 = fs.GetFile(Text1 & File1.List(j))<br>
If fl2.DateLastModified &gt;= fl.DateLastModified Then nieuw = False<br>
End If<br>
Next j<br>
End If<br>
If nieuw Then<br>
Set li = ListView2.ListItems.Add(, LCase$(File2.List(i)), LCase$(File2.List(i)))<br>
li.SubItems(1) = fl.Size<br>
li.SubItems(2) = Format$(fl.DateLastModified, &quot;dd-mm-yy hh:Nn:ss&quot;)<br>
End If<br>
Next i<br>
Label2 = CStr(ListView2.ListItems.Count) & &quot; van &quot; & CStr(File2.ListCount)<br>
Me.MousePointer = vbNormal<br>
<br>
End Sub<br>
<br>
Private Sub Form_Load()<br>
<br>
<br>
Me.Top = GetSetting(&quot;Compare&quot;, &quot;Form&quot;, &quot;Top&quot;, CStr(Me.Top))<br>
Me.Left = GetSetting(&quot;Compare&quot;, &quot;Form&quot;, &quot;Left&quot;, CStr(Me.Left))<br>
Me.Width = GetSetting(&quot;Compare&quot;, &quot;Form&quot;, &quot;Width&quot;, CStr(Me.Width))<br>
Me.Height = GetSetting(&quot;Compare&quot;, &quot;Form&quot;, &quot;Height&quot;, CStr(Me.Height))<br>
With ListView1<br>
.ColumnHeaders.Add , , &quot;Bestand&quot;, 1693<br>
.ColumnHeaders.Add , , &quot;Grote&quot;, 804, lvwColumnRight<br>
.ColumnHeaders.Add , , &quot;Datum&quot;, 1464<br>
.View = lvwReport<br>
.ColumnHeaders(1).Width = GetSetting(&quot;Compare&quot;, &quot;List1&quot;, &quot;Width1&quot;, CStr(.ColumnHeaders(1).Width))<br>
.ColumnHeaders(2).Width = GetSetting(&quot;Compare&quot;, &quot;List1&quot;, &quot;Width2&quot;, CStr(.ColumnHeaders(2).Width))<br>
.ColumnHeaders(3).Width = GetSetting(&quot;Compare&quot;, &quot;List1&quot;, &quot;Width3&quot;, CStr(.ColumnHeaders(3).Width))<br>
End With<br>
With ListView2<br>
.ColumnHeaders.Add , , &quot;Bestand&quot;, 1693<br>
.ColumnHeaders.Add , , &quot;Grote&quot;, 804, lvwColumnRight<br>
.ColumnHeaders.Add , , &quot;Datum&quot;, 1464<br>
.View = lvwReport<br>
.ColumnHeaders(1).Width = GetSetting(&quot;Compare&quot;, &quot;List2&quot;, &quot;Width1&quot;, CStr(.ColumnHeaders(1).Width))<br>
.ColumnHeaders(2).Width = GetSetting(&quot;Compare&quot;, &quot;List2&quot;, &quot;Width2&quot;, CStr(.ColumnHeaders(2).Width))<br>
.ColumnHeaders(3).Width = GetSetting(&quot;Compare&quot;, &quot;List2&quot;, &quot;Width3&quot;, CStr(.ColumnHeaders(3).Width))<br>
End With<br>
Text1 = GetSetting(&quot;Compare&quot;, &quot;Paths&quot;, &quot;Path1&quot;, App.Path & &quot;\&quot;)<br>
If Right$(Text1, 1) &lt;&gt; &quot;\&quot; Then Text1 = Text1 & &quot;\&quot;<br>
fillist1<br>
Text2 = GetSetting(&quot;Compare&quot;, &quot;Paths&quot;, &quot;Path2&quot;, App.Path & &quot;\&quot;)<br>
If Right$(Text2, 1) &lt;&gt; &quot;\&quot; Then Text2 = Text2 & &quot;\&quot;<br>
fillist2<br>
<br>
End Sub<br>
<br>
Private Sub Form_Unload(Cancel As Integer)<br>
<br>
SaveSetting &quot;Compare&quot;, &quot;Paths&quot;, &quot;Path1&quot;, Text1<br>
SaveSetting &quot;Compare&quot;, &quot;Paths&quot;, &quot;Path2&quot;, Text2<br>
With ListView1<br>
SaveSetting &quot;Compare&quot;, &quot;List1&quot;, &quot;Width1&quot;, CStr(CLng(.ColumnHeaders(1).Width))<br>
SaveSetting &quot;Compare&quot;, &quot;List1&quot;, &quot;Width2&quot;, CStr(CLng(.ColumnHeaders(2).Width))<br>
SaveSetting &quot;Compare&quot;, &quot;List1&quot;, &quot;Width3&quot;, CStr(CLng(.ColumnHeaders(3).Width))<br>
End With<br>
With ListView2<br>
SaveSetting &quot;Compare&quot;, &quot;List2&quot;, &quot;Width1&quot;, CStr(CLng(.ColumnHeaders(1).Width))<br>
SaveSetting &quot;Compare&quot;, &quot;List2&quot;, &quot;Width2&quot;, CStr(CLng(.ColumnHeaders(2).Width))<br>
SaveSetting &quot;Compare&quot;, &quot;List2&quot;, &quot;Width3&quot;, CStr(CLng(.ColumnHeaders(3).Width))<br>
End With<br>
If Not Me.WindowState = vbMinimized Then<br>
SaveSetting &quot;Compare&quot;, &quot;Form&quot;, &quot;Top&quot;, CStr(CLng(Me.Top))<br>
SaveSetting &quot;Compare&quot;, &quot;Form&quot;, &quot;Left&quot;, CStr(CLng(Me.Left))<br>
SaveSetting &quot;Compare&quot;, &quot;Form&quot;, &quot;Width&quot;, CStr(CLng(Me.Width))<br>
SaveSetting &quot;Compare&quot;, &quot;Form&quot;, &quot;Height&quot;, CStr(CLng(Me.Height))<br>
End If<br>
<br>
End Sub<br>
<br>
Private Sub Form_Resize()<br>
<br>
Dim l2 As Single<br>
<br>
If Me.WindowState &lt;&gt; vbMinimized Then<br>
l2 = (Me.ScaleWidth - 3 * 84) / 2<br>
Text1.Width = l2 - 384<br>
Command1.Left = Text1.Left + Text1.Width<br>
Text2.Left = Command1.Left + 384 + 84<br>
Text2.Width = l2 - 384<br>
Command2.Left = Text2.Left + Text2.Width<br>
ListView1.Width = l2<br>
ListView2.Width = l2<br>
ListView2.Left = ListView1.Left + ListView1.Width + 84<br>
ListView1.Height = Me.ScaleHeight - Text1.Height - Label1.Height - Check1.Height - 5 * 84<br>
ListView2.Height = ListView1.Height<br>
Label1.Top = ListView1.Top + ListView1.Height + 84<br>
Label1.Width = l2<br>
Label2.Top = Label1.Top<br>
Label2.Left = Label1.Left + Label1.Width + 84<br>
Label2.Width = l2<br>
Check1.Top = Label1.Top + Label1.Height + 84<br>
Check1.Width = l2<br>
Check2.Top = Check1.Top<br>
Check2.Left = Check1.Left + Check1.Width + 84<br>
Check2.Width = l2<br>
End If<br>
<br>
End Sub<br>
<br>
take : 2 TextBoxs,2 ListView,4 buttons<br>
<br>
Private Sub Command1_Click()<br>
<br>
Dim lpIDList As Long<br>
Dim sBuffer As String<br>
Dim szTitle As String<br>
Dim tBrowseInfo As BrowseInfo<br>
<br>
szTitle = &quot;&quot;<br>
With tBrowseInfo<br>
.hWndOwner = Me.hWnd<br>
.lpszTitle = lstrcat(szTitle, &quot;&quot;)<br>
.ulFlags = BIF_RETURNONLYFSDIRS + BIF_DONTGOBELOWDOMAIN<br>
End With<br>
<br>
lpIDList = SHBrowseForFolder(tBrowseInfo)<br>
<br>
If (lpIDList) Then<br>
sBuffer = Space(MAX_PATH)<br>
SHGetPathFromIDList lpIDList, sBuffer<br>
sBuffer = Left(sBuffer, InStr(sBuffer, vbNullChar) - 1)<br>
Text1 = sBuffer & &quot;\&quot;<br>
fillist1<br>
If Check2 = vbChecked Then fillist2<br>
End If<br>
<br>
End Sub<br>
<br>
Private Sub Command2_Click()<br>
Dim lpIDList As Long<br>
Dim sBuffer As String<br>
Dim szTitle As String<br>
Dim tBrowseInfo As BrowseInfo<br>
<br>
szTitle = &quot;&quot;<br>
With tBrowseInfo<br>
.hWndOwner = Me.hWnd<br>
.lpszTitle = lstrcat(szTitle, &quot;&quot;)<br>
.ulFlags = BIF_RETURNONLYFSDIRS + BIF_DONTGOBELOWDOMAIN<br>
End With<br>
<br>
lpIDList = SHBrowseForFolder(tBrowseInfo)<br>
<br>
If (lpIDList) Then<br>
sBuffer = Space(MAX_PATH)<br>
SHGetPathFromIDList lpIDList, sBuffer<br>
sBuffer = Left(sBuffer, InStr(sBuffer, vbNullChar) - 1)<br>
Text2 = sBuffer & &quot;\&quot;<br>
fillist2<br>
If Check1 = vbChecked Then fillist1<br>
End If<br>
<br>
End Sub<br>
<br>
Private Sub Check1_Click()<br>
<br>
fillist1<br>
<br>
End Sub<br>
Private Sub Check2_Click()<br>
<br>
fillist2<br>
<br>
End Sub<br>
<br>
Eric De Decker
 
Thanks to Eric for his very complete answer.<br>
<br>
Also - from <br>
<br>
<A HREF=" TARGET="_new"><br>
--snip--<br>
The following code illustrates how to obtain a File object and how to view one of its properties. <br>
<br>
Function ShowDateCreated(filespec)<br>
<br>
Dim fso, f<br>
&nbsp;&nbsp;&nbsp;&nbsp;Set fso = CreateObject(&quot;Scripting.FileSystemObject&quot;)<br>
&nbsp;&nbsp;&nbsp;&nbsp;Set f = fso.GetFile(filespec)<br>
&nbsp;&nbsp;&nbsp;&nbsp;ShowDateCreated = f.DateCreated<br>
End Function<br>
--snip--<br>
<br>
This appeals to my (very) lazy style of programming.<br>
<br>
Mike<br>
<p>Mike Lacey<br><a href=mailto:Mike_Lacey@Cargill.Com>Mike_Lacey@Cargill.Com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top