Re: Script: Network share problems




The error description is "File not found" which usually means there are no files
to copy from "source". If the folder didn't exist or you did not have security
access then the error should be different. The MSDN documentation says "An
error also occurs if a source using wildcard characters doesn't match any files"
(http://msdn.microsoft.com/library/en-us/script56/html/94e39f9a-c7bf-42be-ae71-5768f034e070.asp)

So maybe there are no files to copy in the root folder? As a test, just create
a temporary file named R:\Test.txt and then run the script. If that's the case
you will need to add more error checking to your script.

OPTION 1. You could check for files first, before calling CopyFile(), something
like this:
''''''''''''''''''''''''''''''''''''''''''''''
objStream.Writeline "File Copy Job Start - " & Time & Date
SourceParent = objFSO.GetParentFolderName(source)
If objFSO.GetFolder(SourceParent).Files.Count > 1 Then
objStream.Writeline "Copying root files from " & source
objFSO.CopyFile source, dest, OVERWRITE_EXISTING
Else
objStream.Writeline "No files found to copy from " & source
End If

''''''''''''''''''''''''''''''''''''''''''''''


OPTION 2: Enable automatic error handling with "On Error Resume Next":
''''''''''''''''''''''''''''''''''''''''''''''
On Error Resume Next
objFSO.CopyFile source, dest, OVERWRITE_EXISTING
If Err.Number <> 0 Then
If Err.Description <> "File not found" Then
objStream.Writeline "Failed to copy " & source & ", " & Err.Description
End If
End If
On Error GoTo 0
''''''''''''''''''''''''''''''''''''''''''''''

Your script has no error checking whatsoever, you should read up on error
handling:
http://msdn.microsoft.com/library/en-us/script56/html/0675d0b2-5c1a-4f20-94f3-6749c74984a9.asp
http://www.microsoft.com/technet/scriptcenter/guide/sas_vbs_efuo.mspx



"Akwolf" <Akwolf@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:C7A23C0E-8F90-4B85-AD8A-C03A83F9A6AB@xxxxxxxxxxxxxxxx
Ok. Thanks for the tip. I'm not too familiar with shell scripting. Here's
the error message I keep getting.


Script: F;\Wutemp\filecopy.vbs
Line: 49
Char: 1
Error: File not found
Code: 800A0035
Source: Microsoft VBScript runtime error

I hope this helps you better to understand my problem. The line number is
different now because I rearranged the code but the code that is talking
about is still the same one: "objFSO.CopyFile source, dest,
OVERWRITE_EXISTING"

I will try to seach the interenet for the code error but I just maybe
someone has troubleshot this before and knows just what to do. I'm pretty
much out of ideas.



"Marty List" wrote:


And what is the error message???

Since you don't have any error handling enabled in your script, you should be
seeing an error description from the default error handler of the script host
(cscript.exe or wscript.exe). If for some reason you're not getting an error
message, then add a check for Err.Number and Err.Description after the line
that's failing.


"Akwolf" <Akwolf@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:37F44904-B362-4CF3-B5D2-C73EA41946CD@xxxxxxxxxxxxxxxx
Sorry, the error I'm getting is on line 49 " objFSO.CopyFile source, dest,
OVERWRITE_EXISTING"

"Marty List" wrote:


Which line is causing it to break? When you say "throws me errors" that's
not very descriptive, please post the error description.


"Akwolf" <Akwolf@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:F226497A-EBCF-4FCB-9C99-C4694320E4BA@xxxxxxxxxxxxxxxx
Hi,

I have spent a day writing a script to map a network drive to a share
folder and then copy files over from a remote server. At the end it
deletes
all the files.

When I run it with local folders it works fine, but when I use the
mapped
network drive it breaks and throws me errors. I really don't know what
is
going on. The mapped network drive has all the permissions it needs to
read,
write, and delete. Can someone shed some light on this issue. I have
included my script below.

Const ForReading = 1

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objNetwork = CreateObject("Wscript.Network")

Set objFile = objFSO.OpenTextFile("f:\wutemp\test.txt", ForReading)

Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
arrItems = Split(strLine, " ")
If arrItems(0) = "Site1" Then
objNetwork.MapNetworkDrive arrItems(1), arrItems(2), "false",
"domain\administrator", "Password"

End If
Loop

objFile.Close

Const OVERWRITE_EXISTING = True

' Global variables
source = "r:\*.*" ' Source Drive
dest = "f:\wutemp\test2\" ' Destination Folder
delSource = "f:\wutemp\test2" ' Source Folder to delete files
logSource = "f:\wutemp\" ' Destination Folder to create log file

fileName = logSource & "filecopy.log"

' Create filesystem objects
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objStream = objFSO.CreateTextFile(fileName, true)

' Write header to log file
objStream.Writeline "File Copy Job Start - " & Time & Date
objStream.Writeline " "

' Copy all root files
objFSO.CopyFile source, dest, OVERWRITE_EXISTING

' Copy all subfolders and files
objFSO.CopyFolder source, dest, OVERWRITE_EXISTING

' write status to log file
If Err = 0 Then
objStream.Writeline "Files Copied Successfully"
objStream.Writeline " "
objStream.Writeline "Deleting source files"
objStream.Writeline " "

' Delete all files in root folder
DeleteAllFiles(delSource)

' Delete all files in subfolders
FindSubFolders objFSO.GetFolder(delsource)

Else
objStream.Writeline "Error: No Files Copied"
End If

' Write footer to log file
objStream.Writeline " "
objStream.Writeline "File Copy Job End - " & Time

objNetwork.RemoveNetworkDrive arrItems(1)

Set objFso = Nothing
Set objStream = Nothing
Set oFs = Nothing
Set ObjNetwork = Nothing

' method to traverse subfolders recursively
Sub FindSubFolders(Folder)
For Each Subfolder in Folder.SubFolders

objStream.Writeline " "
DeleteAllFiles Subfolder.Path

FindSubFolders Subfolder
Next
End Sub

' method to delete all files within subfolder
Sub DeleteAllFiles(fName)
objStream.Writeline " + " & fName

Set oFs = CreateObject("Scripting.FileSystemObject")

If oFs.FolderExists(fName) then

Set oFolder = oFs.GetFolder(fName)

For Each oFile In oFolder.Files
objStream.Writeline " - " & oFile.name & " Deleted"
oFile.Delete
Next

End If

End Sub








.



Relevant Pages

  • Re: creating folder tree structures
    ... When I have a working script I will post ... Set fso = CreateObject ... So that ONLY "Folder 1" name is ... the rest of the subfolders are set already. ...
    (microsoft.public.scripting.vbscript)
  • Re: script to find all files in folder/subfolders
    ... what I would like the script to eventually do, is scan all files in a certain ... folder (including subfolders) and if the file has not been modified in 1 ... folder, including sub-folders but I can't get the subfolder part to work. ... Set colFiles = objWMIService.ExecQuery _ ...
    (microsoft.public.windows.server.scripting)
  • Subfolder views
    ... I am trying to make all subfolders in My Pictures the same as the main ... MVP Keith had a script to do the job, ... You can select a folder & configure its view settings, ... non-grouped view to be the default inheritance for My Computer, ...
    (microsoft.public.windowsxp.basics)
  • Re: Customize File Views -HELP!
    ... I've written a script that will apply all the view customizations you can ... You can select a folder & configure its view settings, ... subfolders ...
    (microsoft.public.windowsxp.general)
  • RE: Disappearing Network Share Subfolders
    ... Thank you for posting to the SBS Newsgroup. ... I understand that some of your Windows XP SP2 clients cannot view the ... subfolders in share folders on SBS 2K Server. ... Does the problematic share folder locate at NTFS or FAT32 disk? ...
    (microsoft.public.windows.server.sbs)

Loading