Afternoon,

I am working through getting a script to grab a file name and the date
it was last modified and am not having any luck with the UNC it would
appear. The script is below and it is erroring on the line below:

Set DatZipFile = fso.GetFile(DatFilePath + Text)

If I msgbox (DatFilePath + Text) the path is correct. I have tried
using the files collection method but I can't properly filter for the
file im looking for. Any help would be greatly appreciated

Cheers

Rob.

-----------------------------------------------------------------------------

set shell = createobject("wscript.shell")
Set WshNetwork = WScript.CreateObject("WScript.Network")
const DatFilePath="\\server\c$\Program
Files\McAfee\ePO\3.0.1\DB\Software\"

set TheArgs = WScript.Arguments
NetworkD = TheArgs.Item(0)

NetworkDrive = NetworkD + ":"

WshNetwork.MapNetworkDrive NetworkDrive,"\\server\c$"

cmd = "%comspec% /c dir dat-*.zip /b | sort"
shell.currentdirectory = NetworkDrive + "\Program
Files\McAfee\ePO\3.0.1\DB\Software\"
set dir = shell.exec(cmd)
text = ""
do while true
if not dir.stdout.atendofstream then
text = text & dir.stdout.readall
end if
if dir.status = 1 then exit do
wscript.sleep 100
loop

WshNetwork.RemoveNetworkDrive (NetworkDrive),true

set shell = Nothing
set WshNetwork = Nothing

Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
Set DatZipFile = fso.GetFile(DatFilePath + Text)
Modified = DatZipFile.DateLastModified

------------------------------------------------------------------------------

Re: File Not Found Error - UNC? by Tim

Tim
Mon Oct 10 05:01:50 CDT 2005

Hi Rob,

One odd thing about your script is that you are using '+' to
concatenate strings. You should be using '&'. I'm surprised that you
aren't getting type missmatch errors all over the place.... If you
simply need to capture the file name and date modified for all files in
a folder (and it's sub folders), a simpler approach (well, I think it's
simpler :-)), rather than using shell.exec would be:

Option Explicit

Dim fso,ofolder

Set fso = CreateObject("Scripting.FileSystemObject")
Set ofolder = fso.GetFolder("c:\documents and settings")

ShowFileDetails ofolder

Public Sub ShowFileDetails(ThisFolder)
Dim ThisFile,sMsg,ThisSubFolder

For Each ThisFile in ThisFolder.Files
sMsg = "Folder: " & ThisFolder.Path & vbCrLf
sMsg = sMsg & "File: " & ThisFile.name & vbCrLf & "Modified: "
sMsg = sMsg & ThisFile.DateLastModified
MsgBox sMsg
Next

For Each ThisSubFolder In ThisFolder.SubFolders
ShowFileDetails ThisSubFolder
Next
End Sub

Best of luck
Regards,
Tim


Re: File Not Found Error - UNC? by purpleisafruit

purpleisafruit
Mon Oct 10 20:57:59 CDT 2005

I needed to use the Dir command to filter for the filename
dat-xxxx.zip. The dir command appended some extra characters to the end
of the filename returned. The code below works a treat:

___________________________________________________________________-
' Start
set shell = createobject("wscript.shell")
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set fso = CreateObject("Scripting.FileSystemObject")
Const ForReading = 1, ForWriting = 2, ForAppending = 8

' Get Arguemnts
' Argument 0 = network drive to map
set TheArgs = WScript.Arguments
NetworkD = TheArgs.Item(0)

' Map The Network Drive
NetworkDrive = UCase(NetworkD + ":")
WshNetwork.MapNetworkDrive NetworkDrive,"\\server\c$"

' Find the dat zip filename
cmd = "%comspec% /c dir dat-*.zip /b | sort"
shell.currentdirectory = NetworkDrive + "\Program
files\McAfee\ePO\3.0.1\DB\Software\"
set dir = shell.exec(cmd)
text = ""
do while true
if not dir.stdout.atendofstream then
text = text & dir.stdout.readall
end if
if dir.status = 1 then exit do
wscript.sleep 100
loop

' Triming the CRLF from the text variable
trimmedtext = left(text, len(text)-2)

DatZipFile = fso.buildpath(shell.currentdirectory, trimedtext)

' Get the date modified details of the file
set File = fso.GetFile(datzipfile)
Modified = file.DateLastModified
_______________________________________________________________


Re: File Not Found Error - UNC? by Dr

Dr
Wed Oct 12 10:49:20 CDT 2005

JRS: In article <1128995879.229386.168170@g47g2000cwa.googlegroups.com>
, dated Mon, 10 Oct 2005 18:57:59, seen in news:microsoft.public.scripti
ng.vbscript, purpleisafruit@gmail.com posted :
>I needed to use the Dir command to filter for the filename
>dat-xxxx.zip. The dir command appended some extra characters to the end
>of the filename returned.

dir /b dat-????.zip ?

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk DOS 3.3, 6.20; Win98. ©
Web <URL:http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms & links.
PAS EXE TXT ZIP via <URL:http://www.merlyn.demon.co.uk/programs/00index.htm>
My DOS <URL:http://www.merlyn.demon.co.uk/batfiles.htm> - also batprogs.htm.