Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Permission Denied Code 800A0046

Status
Not open for further replies.

rnpIII

Technical User
May 2, 2001
61
US
Hello All,

I am just beginning in vbScript so please excuse the mess you may find in my code.
I am receiving a permission denied error code 800A0046 when I run FleCmpr.vbs.
If I run CopFle.vbs, I don't get this error copying\moving from and to the same directories.
I DO have permissions, twice over, once as domain admin and once directly on the directory in question, MatchDir.
This is in evidence because CopFle.vbs DOES work.

The only difference I can see here is the use of variables for the file names and I can't get around that, at least not with the limited knowledge I have.

I have read all six threads on this error and again, it is NOT a permissions issue.

This code does a perfect file comparison between two file or 200 files, I just need to copy the offending files to a special directory for my billing staff to repair.

Any assistance, suggestions, criticism will be appreciated.

rnpIII

-----------------------------------Code Below-----------------------------------
' FleCmpr.vbs

Const HomeDir = "\\FILES01\Home\Billing\Day_Proc\AdminiSource\CISI"
Const WorkDir = "\\FILES01\Home\Billing\Day_Proc\AdminiSource\CISI\Work"
Const BinDir = "\\FILES01\Home\It\Batches\Bin\"
Const TmpDir = "\\FILES01\Home\Billing\Day_Proc\AdminiSource\CISI\Temp"
Const LogDir = "\\FILES01\Home\Billing\Day_Proc\AdminiSource\CISI\Work\Logs"
Const MatchDir = "\\FILES01\Home\Billing\Day_Proc\AdminiSource\CISI\Work\Match\"

Dim file, fileII, FnmI, FnmII
Dim Verifso, VeriFle, FIfso, FIIfso, FI, FII, strFI, strFII
Dim fldr, PauseBtn, SizeVar
Dim Tmpfso, TmpFle

Set Tmpfso = CreateObject("Scripting.FileSystemObject")
Set TmpFle = Tmpfso.CreateTextFile(LogDir & "\Verified Files.txt", True)

Set Verifso = CreateObject("Scripting.FileSystemObject")
Set VeriFle = Verifso.CreateTextFile(LogDir & "\Match.txt", True)

Set FVarfso = CreateObject("Scripting.FileSystemObject")
Set FIfso = CreateObject("Scripting.FileSystemObject")
Set FIIfso = CreateObject("Scripting.FileSystemObject")

Set WshShell = WScript.CreateObject("WScript.Shell")

Set fldr = FVarfso.GetFolder(WorkDir)

' Get the file names from the Work directory
' Then get the second file name to compare with
For Each File in fldr.Files 'first file name to retrieve
For Each FileII In fldr.Files 'second file name to retrieve


FnmI = FVarfso.GetFilename (File)
FnmII = FVarfso.GetFilename (FileII)
TmpFle.WriteLine "Checking " & FnmI & " and " & FnmII ' Write to Verified Files.txt
If File <> FileII then ' If the names of the files do not match
Set FI = FIfso_OpenTextFile(File)
Set FII = FIIfso_OpenTextFile(FileII)
strFI = FI.ReadLine
strFII = FII.ReadLine
If strFI = strFII then ' Compare the first line of each file to see if they
' are identical
VeriFle.WriteLine FnmI & " and " & FnmII & " are identical" ' Write to
' names of duplicate files to Match.txt
'wscript.echo "Moving " & FnmI & " and " & FnmII
'FIfso.CopyFile WorkDir & "\Test.txt", MatchDir
'FIIfso.CopyFile FileII, MatchDir
MvFle 'FnmI, FnmII
End If
End If
Next


'Call PauseFunc ' Pause for error checking
Next

Set Verifso = CreateObject("Scripting.FileSystemObject")
Set VeriFle = Verifso.GetFile(LogDir & "\Match.txt")

Set WshShell = Wscript.CreateObject("Wscript.Shell")
Set WshEnv = WshShell.Environment("Volatile")

SizeVar = VeriFle.Size
If SizeVar <= 0 Then
Verifso.DeleteFile(VeriFle)

End If


Function PauseFunc ' Function to allow the script to pause and be cancelled

PauseBtn = WshShell.Popup("Click CANCEL to cancel script", 5, "Checking!", 1 + 32)

Select Case PauseBtn
case 2 WScript.Quit
case -1
End Select

End Function

'Moved it to a function so I could watch it better
Function MvFle '(FnmI, FnmII)

FIfso.MoveFile WorkDir &"\"& FnmI, MatchDir &"\"
'FIIfso.MoveFile FileII, MatchDir & FnmII

End Function

-----------A piece of code that works fine-------------
'CopFle.vbs
Const WorkDir = "\\FILES01\Home\Billing\Day_Proc\AdminiSource\CISI\Work"
Const MatchDir = "\\FILES01\Home\Billing\Day_Proc\AdminiSource\CISI\Work\Match"

Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.MoveFile WorkDir &"\testi.txt", MatchDir &"\"
 
I made some changes to your code. Specifically, it is not necessary to create several instances of the FilesSystemObject. Try the code and tell me the error that you get and what line it gives you the error on.

Code:
' FleCmpr.vbs

Const HomeDir = "\\FILES01\Home\Billing\Day_Proc\AdminiSource\CISI"
Const WorkDir = "\\FILES01\Home\Billing\Day_Proc\AdminiSource\CISI\Work"
Const BinDir =  "\\FILES01\Home\It\Batches\Bin\"
Const TmpDir =  "\\FILES01\Home\Billing\Day_Proc\AdminiSource\CISI\Temp"
Const LogDir =  "\\FILES01\Home\Billing\Day_Proc\AdminiSource\CISI\Work\Logs"
Const MatchDir = "\\FILES01\Home\Billing\Day_Proc\AdminiSource\CISI\Work\Match\"

 Dim file, fileII, FnmI, FnmII
' Dim Verifso, VeriFle, FIfso, FIIfso, FI, FII, strFI, strFII
Dim oFSO, VeriFile, FI, FII, strFI, strFII
 Dim fldr, PauseBtn, SizeVar
 Dim TmpFle



Set oFSO = CreateObject("Scripting.FileSystemObject")
Set TmpFle = oFSO.CreateTextFile(LogDir & "\Verified Files.txt", True)
Set VeriFle = oFSO.CreateTextFile(LogDir & "\Match.txt", True)
Set WshShell = WScript.CreateObject("WScript.Shell")
Set fldr = oFSO.GetFolder(WorkDir)

' Get the file names from the Work directory
' Then get the second file name to compare With
For Each File in fldr.Files 'first file name to retrieve
    For Each FileII In fldr.Files 'second file name to retrieve
        TmpFle.WriteLine "Checking " & file.Name & " and " & fileII.Name ' Write to Verified Files.txt
        If file.Name <> fileII.Name then             ' If the names of the files do not match
            Set FI = oFSO.OpenTextFile(File)
            Set FII = oFSO.OpenTextFile(FileII)
            strFI = FI.ReadLine
            strFII = FII.ReadLine
            If FI.ReadLine = FII.ReadLine then  ' Compare the first line of each file to see if they
                                    ' are identical
                VeriFle.WriteLine file.Name & " and " & fileII.Name & " are identical" ' Write To
                                    ' names of duplicate files to Match.txt
                'wscript.echo "Moving " & FnmI & " and " & FnmII
                'FIfso.CopyFile WorkDir & "\Test.txt", MatchDir
                'FIIfso.CopyFile FileII, MatchDir
                oFSO.MoveFile WorkDir &"\"& file.Name, MatchDir &"\"
            End If
        End If
        Next

        
        'Call PauseFunc         ' Pause for error checking
Next

Set VeriFle = oFSO.GetFile(LogDir & "\Match.txt")
Set WshEnv = WshShell.Environment("Volatile")

SizeVar = VeriFle.Size
If SizeVar <= 0 Then
    Verifso.DeleteFile(VeriFle)    
    
End If


Function PauseFunc ' Function to allow the script to pause and be cancelled
    
    PauseBtn = WshShell.Popup("Click CANCEL to cancel script", 5, "Checking!", 1 + 32)
    
    Select Case PauseBtn
       case 2      WScript.Quit
       case -1     
    End Select

End Function

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Hello TomThumbKP,

I get the same error on the same line as before, well, the same piece of code (line 41), I had to change line 34 back to "If strFI = strFII then" from the FI.readline... because of another error that did not concern me at the time.

I noted in another test, if I take this statement:
If File <> FileII then
Set FI = FIfso_OpenTextFile(File)
Set FII = FIIfso_OpenTextFile(FileII)
strFI = FI.ReadLine
strFII = FII.ReadLine
If strFI = strFII then
FIfso.MoveFile WorkDir &"\"& FnmI, MatchDir
FIIfso.MoveFile WorkDir &"\"& FnmII, MatchDir
End If
End If
And move the nested IF outside of the original IF then it will move the file, but then it will move all the files.
Like so:
If File <> FileII then
Set FI = FIfso_OpenTextFile(File)
Set FII = FIIfso_OpenTextFile(FileII)
strFI = FI.ReadLine
strFII = FII.ReadLine
End If
If strFI = strFII then
FIfso.MoveFile WorkDir &"\"& FnmI, MatchDir
FIIfso.MoveFile WorkDir &"\"& FnmII, MatchDir
End If

So, it looks as though there is some kind of lock on it with the FOR loop?
Could I some how end the loop without restarting the whole process?

Thanks for your assistance and thank you for your suggestions, I will study your code some more to better understand what you are suggesting.
rnpIII
 
Try putting this line right above the line that is erroring then let me know what the line says.

TmpFle.WriteLine "The copy args are: " & WorkDir &"\"& file.Name & ", " & MatchDir &"\"

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Hello TomThumbKP,

I get:
The copy args are: \\FILES01\Home\Billing\Day_Proc\AdminiSource\CISI\Work\Cyccb320041118.txt, \\FILES01\Home\Billing\Day_Proc\AdminiSource\CISI\Work\Match\

The paths look correct, I can't see anything wrong.
It must be the readline having a lock on the files.
I have tried FI.Close and FII.close within the second IF, right before the move, with negative results.
Methinks I need to find a way to make that readline let go of that file.

Any ideas?
rnpIII
 
Does it work if you change the move to a copy?

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Hello TomThumbKP,

Changing from Move to Copy had no effect.
I think I found the issue.
First and formost, the "Close" statements (?). They do help. Without them the code does seem to fail.

Second, I noted in my processes, for some reason from somewhere I had another script running (evidently it was hung up on something).
I killed that wscript.exe process and this one started working.
While it kind of makes sense in one respect, it doesn't in another because the other script would still work.
Strange.

Anyway, Closing the file and making sure there are no hung scripts did the trick.

Now, I just need to find a way to make a good status bar for the processes, saw one on the forum but don't understand how to use it yet, maybe when I get a chance to read the code I might have a clue.

Thank you for your suggestions on cleaning up the code, making it a little more manageable and your assistance on the main issue.

rnpIII
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top