Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

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

mdProgrammer (Programmer) (OP)
5 May 09 9:18
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
PHV (MIS)
5 May 09 10:42
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: How Do I Get Great Answers To my Tek-Tips Questions?
FAQ181-2886: How can I maximize my chances of getting an answer?

mdProgrammer (Programmer) (OP)
5 May 09 10:57
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)
PHV (MIS)
5 May 09 11:38
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: How Do I Get Great Answers To my Tek-Tips Questions?
FAQ181-2886: How can I maximize my chances of getting an answer?

mdProgrammer (Programmer) (OP)
5 May 09 13:27
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).
ITPangaeaArchitect (MIS)
11 May 09 3:26
Maybe I missed it, but what is the EXAC error you are getting back?

- Brandon Wilson
  MCSE:Security00/03; MCSA:Security03
  MCSA:Messaging00; MCP; A+
  IT Pangaea (http://it-pangaea.com)

ITPangaeaArchitect (MIS)
11 May 09 3:26
*EXACT

- Brandon Wilson
  MCSE:Security00/03; MCSA:Security03
  MCSA:Messaging00; MCP; A+
  IT Pangaea (http://it-pangaea.com)

mdProgrammer (Programmer) (OP)
12 May 09 9:45
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).

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close