Toon posts:

[VB] Zoekopdracht (filecheck)

Pagina: 1
Acties:
  • 93 views sinds 30-01-2008

Verwijderd

Topicstarter
Ik wil in Visual Basic 6.0 Learning Edition
een proggie maken dat kijkt naar de aanwezigheid
van een bepaald bestand van de harde schijf.

vb. Autoexec.bat op C:

Welke source-code is hiervoor, ik kon niks
vinden in de search

BVD

Verwijderd

code:
1
2
3
if dir("C:\autoexec.bat") <> "" then
   Doe iets
end if

Verwijderd

Topicstarter
Ben wel een beetje een newbie en dat script
schijnt niet echt te werken hoor, tenminste
ik heb de Doe iets ingesteld op Beep
maar hij beeped als de file wel bestaat en
als hij niet bestaat, wat doe ik fout?

Verwijderd

Geen idee, maar hoort gewoon te werken, typfout gemaakt?

Verwijderd

Topicstarter
Op maandag 25 juni 2001 21:18 schreef Yarvieh het volgende:
Geen idee, maar hoort gewoon te werken, typfout gemaakt?
Ik heb het copy/paste gedaan, zou je
misschien het hele script willen plaatsen, want
moet er niets iets tussen "" na <>???

Verwijderd

ehh dit is "het hele script" *D

  • brammetje
  • Registratie: Oktober 2000
  • Laatst online: 12-01 11:31
zullen we het maar op die learning edition gooien, of heeft dat gewoon alle mogelijkheden?

  • TheMrH
  • Registratie: April 2000
  • Laatst online: 16-11 09:14
Je kan het ook moeilijker doen met het FileSystemObject:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Dim i as integer
Dim fso as FileSystemObject
set fso = new FileSystemObject
' Je kan ook late binden met 
' Dim fso as object
' Set fs = CreateObject("Scripting.FileSystemObject")
' Anders moet je een reference plaatsen via Project->References
if fso.FileExists("c:\autoexec.bat") then
    Beep
    MsgBox "Hij bestaat dus WEL"
else
    for i=0 to 100
      Beep
    next i
    MsgBox "Hij bestaat dus NIET"
end if
set fso = Nothing

Maar de code van Yarvieh moet ook gewoon werken hoor

The box said 'requires Windows 95 or better', so I installed Linux...


Verwijderd

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
Dir Function Example
This example uses the Dir function to check 
if certain files and directories exist. 

Dim MyFile, MyPath, MyName
' Returns "WIN.INI"  if it exists.
MyFile = Dir("C:\WINDOWS\WIN.INI")   

' Returns filename with specified extension. If more than one *.ini
' file exists, the first file found is returned.
MyFile = Dir("C:\WINDOWS\*.INI")

' Call Dir again without arguments to return the next *.INI 
'file in the same directory.
MyFile = Dir

' Return first *.TXT file with a set hidden attribute.
MyFile = Dir("*.TXT", vbHidden)

' Display the names in C:\ that represent directories.
MyPath = "c:\"   ' Set the path.
MyName = Dir(MyPath, vbDirectory)   ' Retrieve the first entry.
Do While MyName <> ""   ' Start the loop.
   ' Ignore the current directory and the encompassing directory.
   If MyName <> "." And MyName <> ".." Then
    ' Use bitwise comparison to make sure MyName is a directory.
    If (GetAttr(MyPath & MyName) And vbDirectory) = vbDirectory Then
       Debug.Print MyName   ' Display entry only if it
    End If   ' it represents a directory.
   End If
   MyName = Dir   ' Get next entry.
Loop

Uit msdn (die cd's die je zelf als het goed is ook hebt, wellicht es in kijken voor de grap?)

  • SqnLdr
  • Registratie: Maart 2003
  • Niet online
Ik zit met het zelfde probleem maar gebruik VB 2005 Express. De simpele methode doet het niet, de moeilijke geeft de error Type 'FileSystemObject' is not defined. Wat doe ik fout?
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim i As Integer
        Dim fso As FileSystemObject
        fso = New FileSystemObject
        If fso.FileExists("c:\autoexec.bat") Then
            Beep()
            MsgBox("Hij bestaat dus WEL")
        Else
            For i = 0 To 100
                Beep()
            Next i
            MsgBox("Hij bestaat dus NIET")
        End If
        fso = Nothing
        'MsgBox("Action failed due to file overwriting protection." + Chr(13) + "Target file already exists. Press OK to change parameters.", MsgBoxStyle.Critical, "Error!")
    End Sub

  • RobIII
  • Registratie: December 2001
  • Niet online

RobIII

Admin Devschuur®

^ Romeinse Ⅲ ja!

(overleden)
whizchris schreef op zondag 04 februari 2007 @ 16:29:
Ik zit met het zelfde probleem maar gebruik VB 2005 Express. De simpele methode doet het niet, de moeilijke geeft de error Type 'FileSystemObject' is not defined. Wat doe ik fout?
code:
1
VB2005 is dan ook compleet andere koek dan VB6 ;)

Visual Basic .NET:
1
2
3
4
5
6
7
8
9
10
11
12
Imports System.IO

Public Class Form1

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If File.Exists("C:\autoexec.bat") Then
            MsgBox("Bestaat")
        Else
            MsgBox("Bestaat niet!")
        End If
    End Sub
End Class


Wel jammer dat je daar een topic uit 2001 voor uit de sloot rukt...

[ Voor 84% gewijzigd door RobIII op 04-02-2007 16:47 ]

There are only two hard problems in distributed systems: 2. Exactly-once delivery 1. Guaranteed order of messages 2. Exactly-once delivery.

Je eigen tweaker.me redirect

Over mij

Pagina: 1

Dit topic is gesloten.