Reply
Old October 22nd, 2002 Top | #1
anewhope
 
anewhope's Avatar
Unregistered
Posts: n/a

Default VB Stuff

What im looking to do in a VB program is search for a set given file that I would declare, then if found copy it to a directory.

How would I go about this?

Say if I wanted to back up winini.bat to a floppy drive or something like that?

Anyhelp greatly appreciated
  Reply With Quote
Old October 24th, 2002 Top | #2
 
Piett's Avatar
...will circle this city
Joined: April 2002
Location: Calgary, Alberta
Posts: 528
Reputation: 0
Power: 128

Default

are you saying search and entire HD for it? because that would take some coding, big time. or do you just mean supplying a directory (without sub-dirs) and checking if it is there?
Piett is offline   Reply With Quote
Old October 24th, 2002 Top | #3
anewhope
 
anewhope's Avatar
Unregistered
Posts: n/a

Default

Specifying the directory and then sub dir's off that...
  Reply With Quote
Old October 25th, 2002 Top | #4
 
Piett's Avatar
...will circle this city
Joined: April 2002
Location: Calgary, Alberta
Posts: 528
Reputation: 0
Power: 128

Default

hmm i think that i could get it to search in the dir, but not the sub dir. that's a maybe though. haven't done any major vb in like 2 yrs
Piett is offline   Reply With Quote
Old October 25th, 2002 Top | #5
a_scoundral
 
a_scoundral's Avatar
Unregistered
Posts: n/a

Default

The answer you seek is simple.
Click project -> referneces -> then add in Microsoft Scripting Runtime. File name scrrun.dll

Next add some code

dim fso as FileSystem Object

Set fso = New FileSystemObject
if fso.FileExists(QualifiedSrcFileAndPath) = true then
fso.CopyFile QualifiedSrcFileAndPath, QualifiedDestFileAndPath, True
end if
'The True is to force an overwrite if the file already exists in the destination directory.


Set fso = Nothing
  Reply With Quote
Old October 26th, 2002 Top | #6
 
dave holbon's Avatar
OSNN Veteran Addict
Joined: May 2002
Location: London England
Posts: 1,014
Reputation: 140
Power: 133

Default

There are so many ways to do this it might be best if you stated what the operating system/s you wanted to achieve this under was: as you could use: -

Scripting, API calls, VB functions and a host of other methods or add-ins including batch file processing.
dave holbon is offline   Reply With Quote
Old October 26th, 2002 Top | #7
JZolloXP
 
JZolloXP's Avatar
Unregistered
Posts: n/a

Default

Here's code that will recusively search a directory...


Code:
Sub RecursiveSearch(ByVal sPattern As String, ByVal CurrDir As String, sFound() As String)
Dim i As Integer
Dim sCurrPath As String
Dim sFile As String
Dim ii As Integer
Dim iFiles As Integer
Dim iLen As Integer

If Right$(CurrDir, 1) <> "\" Then
    Dir1.Path = CurrDir & "\"
Else
    Dir1.Path = CurrDir
End If
'keep on going into the directories until there are no more left
For i = 0 To Dir1.ListCount
    If Dir1.List(i) <> "" Then
        DoEvents 'make sure it doesn't crash
        Call RecursiveSearch(sPattern, Dir1.List(i), sFound)
    Else
        If Right$(Dir1.Path, 1) = "\" Then
            sCurrPath = Left(Dir1.Path, Len(Dir1.Path) - 1)
        Else
            sCurrPath = Dir1.Path
        End If
	'copy path to string
        File1.Path = sCurrPath
	'copy pattern data to string
        File1.Pattern = sPattern
        If File1.ListCount > 0 Then 'matching files found in the directory
            For ii = 0 To File1.ListCount - 1
		'resize array for a new file
                ReDim Preserve sFound(UBound(sFound) + 1)
                sFound(UBound(sFound) - 1) = File1.List(ii)
            Next ii
        End If
        iLen = Len(Dir1.Path)
        Do While Mid(Dir1.Path, iLen, 1) <> "\"
            iLen = iLen - 1
        Loop
        Dir1.Path = Mid(Dir1.Path, 1, iLen)
    End If
Next i
End Sub
You must have two controls, a directory control named Dir1 and a FileList control named File1. Call it in this format...

Call RecursiveSearch("file.ext", "C:/", fileArray())

That will search for file named "file.ext", in the Entire C:/ drive, and output all matches into an array called fileArray()
  Reply With Quote

Reply

Bookmarks

Thread Tools

Posting Rules

Similar Threads
Thread Thread Starter Forum Replies Last Post
HL2 Stuff Teddy PC Gaming 1 October 1st, 2004 2:28am
what does this stuff mean? canadian_divx Windows Desktop Systems 4 May 22nd, 2003 7:56am
New Stuff Electronic Punk Site Problems & Feedback 11 September 7th, 2002 7:40pm