Home > Software engineering >  Multiple file deletion VB statements problems for help
Multiple file deletion VB statements problems for help

Time:10-22

Actually here is based on humanmagic teacher write the statement of change, the purpose to achieve multiple text files to delete, and then keep the result of every time, for example, the target file deleted after A, delete files to delete results B,,,, and so on, with the resulting file is deleted the ABCD, finally, as A result, after every step and delete files are retained, the diagram below:


The following statement to delete the first, two file is normal, but the third start although can generate CDE results file, but in fact still retains the first two steps of deleted as a result, the third start not to delete,
Teachers and see where the problem is?
Private Sub Command10_Click ()
Dim As Object, a temp As String
Set a=CreateObject (" scripting. The dictionary ")

Open Text2 For Input As # 1 "Text2 was the first to delete the file path of"
The Line Input # 1, temp
Do Until EOF (1)
The Line Input # 1, temp
A (Left (temp, 6))=""
Loop
Close # 1
The Open Text1 For Input As # 1 "Text1 original file path
"Open the Left (Text1, Len (Text1) - (4) + delete "_ A.t xt" For the Output As # 2 "to delete the file path For the first time"
The Line Input # 1, temp
Print # 2, temp
Do Until EOF (1)
The Line Input # 1, temp
If Not a.E xists (Left (temp, 6)) Then
Print # 2, temp
End the If
Loop
Close # 1, # 2

If Text3 & lt; & gt;" "Then" Text3 is second to delete the file path
"The Open Text3 For Input As # 1
The Line Input # 1, temp
Do Until EOF (1)
The Line Input # 1, temp
A (Left (temp, 6))=""
Loop
Close # 1
Open the Left (Text1, Len (Text1) - (4) + delete "_ A.t xt" For Input As # 1 "to delete the file path For the first time, As For the second time to delete the original file"
Open the Left (Text1, Len (Text1) - (4) + delete "_ B.t xt" For the Output As # 2 "the second delete the file path"
The Line Input # 1, temp
Print # 2, temp
Do Until EOF (1)
The Line Input # 1, temp
If Not a.E xists (Left (temp, 6)) Then
Print # 2, temp
End the If
Loop
Close # 1, # 2
End the if

If Text4 & lt; & gt;" "Then" Text4 is the third to delete the file path
"The Open Text4 For Input As # 1
The Line Input # 1, temp
Do Until EOF (1)
The Line Input # 1, temp
A (Left (temp, 6))=""
Loop
Close # 1
Open the Left (Text1, Len (Text1) - (4) + delete "_ B.t xt" For Input As # 1 "For the second time to delete the file path, As the third time to delete the original file"
Open the Left (Text1, Len (Text1) - (4) + delete "_ C.t xt" For the Output As # 2 "to delete the file path For the third time"
The Line Input # 1, temp
Print # 2, temp
Do Until EOF (1)
The Line Input # 1, temp
If Not a.E xists (Left (temp, 6)) Then
Print # 2, temp
End the If
Loop
Close # 1, # 2
End the if

If Text5 & lt; & gt;" "Then" Text5 is the fourth to delete the file path
"The Open Text5 For Input As # 1
The Line Input # 1, temp
Do Until EOF (1)
The Line Input # 1, temp
A (Left (temp, 6))=""
Loop
Close # 1
Open the Left (Text1, Len (Text1) - (4) + delete "_ C.t xt" For Input As # 1 "to delete the file path For the third time, As For the fourth time to delete the original file"
Open the Left (Text1, Len (Text1) - (4) + delete "_ which xt" For the Output As # 2 "to delete the file path For the fourth time"
The Line Input # 1, temp
Print # 2, temp
Do Until EOF (1)
The Line Input # 1, temp
If Not a.E xists (Left (temp, 6)) Then
Print # 2, temp
End the If
Loop
Close # 1, # 2
End the if

MsgBox "frequency out finish, please view the results in the original folder!" , 32, "tip"
End Sub

CodePudding user response:

Every time after the completion of the add empty dictionary, or a dictionary in the accumulation of all want to delete the file
A.R emoveAll
Add in the
Close # 1, # 2
The next line

CodePudding user response:

Plus a.R emoveAll result is same, only delete the first two files, don't know the reason

CodePudding user response:

Code logic there is no problem, you want to make sure Text4, Text5 exists, or file coding, or file structure


Private Sub Command10_Click ()
Dim As Object, a temp As String
Set a=CreateObject (" scripting. The dictionary ")

Open Text2 For Input As # 1 "Text2 was the first to delete the file path of"
The Line Input # 1, temp
Do Until EOF (1)
The Line Input # 1, temp
A (Left (temp, 6))=""
Loop
Close # 1
The Open Text1 For Input As # 1 "Text1 original file path
"Open the Left (Text1, Len (Text1) - (4) + delete "_ A.t xt" For the Output As # 2 "to delete the file path For the first time"
The Line Input # 1, temp
Print # 2, temp
Do Until EOF (1)
The Line Input # 1, temp
If Not a.E xists (Left (temp, 6)) Then
Print # 2, temp
End the If
Loop
Close # 1, # 2
a.R emoveAl

If Text3 & lt; & gt;" "Then" Text3 is second to delete the file path
"The Open Text3 For Input As # 1
The Line Input # 1, temp
Do Until EOF (1)
The Line Input # 1, temp
A (Left (temp, 6))=""
Loop
Close # 1
Open the Left (Text1, Len (Text1) - (4) + delete "_ A.t xt" For Input As # 1 "to delete the file path For the first time, As For the second time to delete the original file"
Open the Left (Text1, Len (Text1) - (4) + delete "_ B.t xt" For the Output As # 2 "the second delete the file path"
The Line Input # 1, temp
Print # 2, temp
Do Until EOF (1)
The Line Input # 1, temp
If Not a.E xists (Left (temp, 6)) Then
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  •  Tags:  
  • VBA
  • Related