|
-
Jul 19th, 2000, 01:33 PM
#1
Thread Starter
Lively Member
VB Code:
Public Function FileFinder(WatchDir As String) As String
'this function will find the file, if it does not find the file
'that means that it is correct, they have never sent us this file
'before
Dim FileFinding As String
Dim count As Integer
Dim counts As String
Dim result As Long
Dim string2 As String
Dim CaptionValue As Integer
Dim Preferences As String
Dim FileToDelete As String
Dim DeleteMe As Boolean
count = 0
FileFinding = Dir(WatchDir) 'Where to look for.
Do Until FileFinding = ""
count = count + 1
FileName = FileFinding
If PreferencesDelimitor <> "" Then
string2 = PreferencesDelimitor
result = AmtInStr(FileName, string2)
Preferences = PreferencesFileFormat - 1
If result <> Preferences Then
CaptionValue = 2
StatusCaptionCase (CaptionValue)
MoveFileTemp (FileName)
End If
Else
MsgBox ("You MUST choose a Delimitor and File Format")
Combo1.SetFocus
End If
FileFinding = Dir 'this is where error occurs
If result = Preferences Then
MoveFiles (FileName)
FileToDelete = FileName
DeleteMe = True
End If
If DeleteMe = True Then
DeleteFileName (FileToDelete)
DeleteMe = False
End If
Loop
counts = CStr(count)
FileFinder = counts
End Function
I have the above function. It works, almost, when the file it is searching for is found it does what it is supposed to do until it reaches the end of the directory list and then it comes back with this error: Run-Time error '5': Invalid procedure call or argument. If it does not find the file then everything works fine. It stops working on FileFinding = Dir.
Any suggestions??
Last edited by Hack; Apr 5th, 2006 at 06:20 AM.
Reason: Added [vbcode][/vbcode] tags for more clarity.
Using VB6 Still Pluging away
-
Jul 19th, 2000, 02:18 PM
#2
Fanatic Member
Maybe this is it!
If you just call the Dir function without specifying a search mask -- for instance "*.*" -- the first time, then you get an error.
Try this:
Code:
Private Sub Form_Load()
Dim a As String
a = Dir
End Sub
What happens?
Yes... you get that same error: Run-time Error 5. This suggests to me that your program somehow resets the Dir function. Maybe one of those other functions you call in the loop are using calls to Dir. If that is the case, maybe that is your problem.
-
Jul 19th, 2000, 02:21 PM
#3
Thread Starter
Lively Member
I don't think so, but let me check.
Using VB6 Still Pluging away
-
Jul 19th, 2000, 02:23 PM
#4
Thread Starter
Lively Member
Thanks that is the problem.
Using VB6 Still Pluging away
-
Jul 19th, 2000, 02:34 PM
#5
Thread Starter
Lively Member
Nope that was not it, still getting the same error
Using VB6 Still Pluging away
-
Jul 19th, 2000, 02:37 PM
#6
Fanatic Member
hmm, Are you using any API calls or anything funny like that?
-
Jul 19th, 2000, 02:54 PM
#7
Thread Starter
Lively Member
no. It was working fine this morning and then I added the delete calls and ever since then it has not worked.
Using VB6 Still Pluging away
-
Jul 19th, 2000, 04:04 PM
#8
Fanatic Member
Hmm, that sounds really weird. I have not had that problem ever. But listen, can you post the code in the DeleteFileName function? I think there is something in there that messes up your code.
-
Jul 20th, 2000, 06:10 AM
#9
Thread Starter
Lively Member
Sure, here it is.
VB Code:
Private Sub DeleteFileName(DeletedFile As String)
Dim FilePath As String
FilePath = GetFiles & DeletedFile
Kill FilePath
End Sub
Here is the AmountInStr Function:
VB Code:
Public Function AmtInStr(String1 As String, string2 As String) As Long
', string3 As String, string4 As String
'this function counts the number of "." or "_" or "-" in the file name
'this is to know which company the file belongs to
Dim Loop1 As Long, Amount As Integer
Amount% = 0
For Loop1& = 1 To Len(String1$)
If InStr(Loop1&, String1$, string2$) <> 0 Then
Loop1& = InStr(Loop1&, String1$, string2$)
Amount% = Amount% + 1
End If
DoEvents
Next Loop1&
AmtInStr& = Amount%
End Function
I have also included MoveFile and MoveFileTemp:
VB Code:
Public Function MoveFiles(MoveFileName As String)
'this is the function that is going to do all of the work
'this function will take the filename that has come in and
'find it's directory using the explore function, if a directory
'is not found then one will be created
'it will then try to find the filename of the file that it is
'looking for, if one is found then this will generate and error
'if no file is found the the filename will be moved and success has
'been made
Dim result As String
Dim count As Integer
Dim answer As Integer
Dim FilePath As String
Dim NewFilePath As String
Dim AlreadyThere As String
Dim ActionValue As Integer
Dim CaptionValue As Integer
FilePath = GetFiles & MoveFileName
NewFilePath = MoveLocation & MoveFileName
CaptionValue = 2
StatusCaptionCase (CaptionValue)
If MoveFileName = "" Then
result = FileFinder(GetFiles)
count = CInt(result)
count = count - 1
FileCopy FilePath, NewFilePath
answer = 1
Else
'FileCopy FilePath, NewFilePath
'if there is this file in the directory already then
'raise and error and do not move the file
'need to create the new folder name, which is the opp number
'which is the first set of numbers before the first deliminitor
SaveFile (MoveFileName)
answer = 1
ActionValue = answer
If ActionValue = 3 Or ActionValue = 4 Then
CaptionValue = 3
StatusCaptionCase (CaptionValue)
Else
CaptionValue = 0
StatusCaptionCase (CaptionValue)
End If
'write to the lstReport what was done
'example "Moved file from here to there
ActionCase (ActionValue)
lstFile.AddItem FileName
End If
End Function
Public Function MoveFileTemp(MoveToTempFileName As String)
Dim result As String
Dim count As Integer
Dim answer As Integer
Dim FilePath As String
Dim NewFilePath As String
Dim AlreadyThere As String
Dim ActionValue As Integer
Dim CaptionValue As Integer
FilePath = GetFiles & MoveToTempFileName
NewFilePath = MoveTempLocation & MoveToTempFileName
CaptionValue = 2
StatusCaptionCase (CaptionValue)
If MoveToTempFileName = "" Then
result = FileFinder(GetFiles)
count = CInt(result)
count = count - 1
FileCopy FilePath, NewFilePath
answer = 1
Else
FileCopy FilePath, NewFilePath
'if there is this file in the directory already then
'raise and error and do not move the file
answer = 5
ActionValue = answer
If ActionValue = 3 Or ActionValue = 4 Then
CaptionValue = 3
StatusCaptionCase (CaptionValue)
Else
CaptionValue = 0
StatusCaptionCase (CaptionValue)
End If
'write to the lstReport what was done
'example "Moved file from here to there
ActionCase (ActionValue)
lstError.AddItem FileName
End If
End Function
Last edited by Hack; Apr 5th, 2006 at 06:23 AM.
Reason: Added [vbcode] [/vbcode] tags or more clarity.
Using VB6 Still Pluging away
-
Apr 4th, 2006, 07:09 PM
#10
Lively Member
Re: Need help with Directories
Hi,
It happen to me the same think while my program in the loop for wating to any file come to the directory to do some process with it, which i work around it by puting another if statment
if oldfilename <> "" then
do wait time
end if
i think some time the cpu is fast which it do 2 process in the same time..looking at the file even no file and doing other function. which indecate the file in use or lock or even not there.
bye
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|