[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 380
  • Last Modified:

Deamon in VB

I am currently writing an Unix like Deamon using VB. The program continously checks for the presence of files in a particular folder
in my C drive. How do I write the code that would specify the particular folder in my C drive and if a file exists, I want to make a copy of the file.
Thanks,
Zack
0
tzachari
Asked:
tzachari
  • 2
1 Solution
 
hatem72Commented:
' this is the first part
'btw: it will only find the first one!
'just change the code to find all
'use as:

'MsgBox FindFile("c:\", vFile$) & vFile$

Public Function FileExist(Path$) As Integer
    Dim x

    x = FreeFile

    On Error Resume Next
    Open Path$ For Input As x
    If Err = 0 Then
        FileExist = True
    Else
        FileExist = False
    End If
    Close x

End Function

Public Function FindFile(ByVal Path As String, ByVal File As String) As String
  Dim DirName As String, LastDir As String
 
  If File = "" Then Exit Function
  If Right(Path, 1) <> "\" Then Path = Path & "\"
 
  DirName = Dir(Path & "*.*", vbDirectory)
  Do While Not FileExist(Path & File)
 
    If DirName = "" Then Exit Do
    DoEvents
    If DirName <> "." And DirName <> ".." Then
      If (GetAttr(Path & DirName) And vbDirectory) = vbDirectory Then
        LastDir = DirName
        DirName = FindFile(Path & DirName & "\", File)
        If DirName <> "" Then
          Path = DirName
          Exit Do
        End If
        DirName = Dir(Path, vbDirectory)
        Do Until DirName = LastDir Or DirName = ""
          DirName = Dir
        Loop
        If DirName = "" Then Exit Do
      End If
    End If
    DirName = Dir
  Loop
 
  If FileExist(Path & File) Then FindFile = Path

End Function

0
 
hessCommented:
how about this... seems way easier.

Dir(path) retures the first file name that matches the querry. so dir("c:\*.exe") would return the first exe file in c:\, say , "c:\jon.exe"

now just use a timer and say

private sub Timer1_timer()
if dir("c:\the Dir Your Checking\*")<>"" then
your code here
your code here
your code here
your code here
your code here
end if
end sub
0
 
hessCommented:
if there are no files in dir("c:\the Dir Your Checking\*") then dir returns ""
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now