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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vbscript File Not Found error (but the file IS there)

Status
Not open for further replies.

mdProgrammer

Programmer
Oct 2, 2004
71
US
I have a script which has been running fine for 3 years. It runs monthly, and on the 1st of each month, it copies the previous month's data to an archive folder and inserts the month and year into the filename. It works if I do it on my local computer, so I'm guessing it some sort of directory permissions issue, but I tried adding "everyone" as a user and giving all permissions and it still gives the error. I noted where the error occurs in the comments.

Here's my code -


Dim basePath ' The path where the databases are
Dim filePath ' The path where the databases are to be deleted and copied
' Never set the filePath to the root directory!
Dim fileExt ' The file name and extension of the file(s) to be copied
' Do not remove the "\"!

' Set the variables - actual folder names and database names changed for this example.
basePath = "\\dataServer\data"
filePath = "\\dataServer\data\Database Folder"
fileExt = "\SomeDatabaseString*.mdb"

' Copy current database into database folder with month/year date stamp inserted into the filename.

dim filesys
set filesys=CreateObject("Scripting.FileSystemObject")
filesys.CopyFile basePath & fileExt, filePath ' Copy files to new directory

Dim fso,f

Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(basePath)

For Each file In f.Files

if UCase(Right(file.Name, 3)) = "MDB" Then

'msgbox filePath & "\" & file.Name
'msgbox filePath & "\" & Left(file.Name,(len(file.Name)-4)) & " " & MonthName(Month(Date())) & " " & Year(Date()) & ".mdb"

' ###### The error occurs here -


fso.MoveFile filePath & "\" & file.Name, filePath &_
"\" & Left(file.Name,(len(file.Name)-4)) &_
" " & MonthName(Month(Date())) & " " & Year(Date()) & ".mdb"
end if
Next

Set fso = Nothing
 
You may try this:
Code:
For Each file In f.Files
  If UCase(Right(file.Name, 3)) = "MDB" Then
    file.Name = Left(file.Name,Len(file.Name)-4) & " " _
     & MonthName(Month(Date)) & " " & Year(Date) & ".mdb"
  End If
Next

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
That code snippet would only change the filename in the current directory, which is what I don't want. (There is a SQL Server DTS package that populates the databases in the main directory)
 
And this ?
Code:
basePath = "\\dataServer\data" 
filePath = "\\dataServer\data\Database Folder"
Dim fso,f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(basePath)
For Each file In f.Files
     if UCase(Right(file.Name, 3)) = "MDB" Then
          fso.MoveFile basePath & "\" & file.Name, filePath &_
      "\" & Left(file.Name,(len(file.Name)-4)) &_
          " " & MonthName(Month(Date())) & " " & Year(Date()) & ".mdb"
     end if
Next
Set fso = Nothing

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
The code itself works on my computer, but not on the network. (It's been working perfectly on the first of each month for the past 3 years until this month) Is there any security setting that would cause this error? I know someone was working on the server where this script is, but I don't know what they did. (Our networking people can be a bit secretive - I'm the programmer, and I don't have access to half the networking stuff).
 
The error says this -

Script: \\(database server)\data\filename.vbs
Line: 79
Char: 11
Error: File Not Found
Code: 800A0035
Source: Microsoft VBScript runtime error

The file has been copied to the folder, so it's there. It seems the actual problem is that it can't rename the file (which is has been doing fine for the past 3 years).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top