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

File Not Found Error?

Status
Not open for further replies.

marshyrob

Technical User
Jan 20, 2004
137
GB
Hello

I have a script that i want to use to search a remote PC (StrComputer) for any .mp3 files in a specified location (StrDir).

When the script runs i get a "path not found" at line 20 char 5.

Anyone have any ideas as to why?

Here is the script:

Input = InputBox("Enter the Machine IP To Search")
StrComputer = Input
StrDriveMap = "\\" & StrComputer & "\c$\Documents and Settings\"
strDir = StrDriveMap
Set FSO = Wscript.CreateObject("Scripting.FileSystemObject")
getInfo(strDir)
'wscript.Echo "Search Complete"


Sub SearchFiles(aItem)
Select Case LCase(Right(Cstr(aItem.Name), 3))
Case "mp3"
wscript.Echo "FILE FOUND: " & aItem.Name
End Select
End Sub



Sub getInfo(strDir)
Set objDir = FSO.GetFolder(strDir) **This is the line**
For Each FileItem In objDir.Files
SearchFiles(FileItem)
Next

For Each NextFileItem In objDir.SubFolders
' wscript.Echo "Parsing Folder: " & NextFileItem.Name
getInfo(NextFileItem)
Next
End Sub

Any help would be appreciated.
 
Do you make sure that the ip address you input is online first. When I run your script here it fails when I put in a dummy ip address but it works when I put in an address that is online.

Try using this function to make sure the ip address is online. It could also be a case that you don't have rights to the C$ share or the share has been removed.

Code:
Input = InputBox("Enter the Machine IP To Search")
StrComputer = Input
StrDriveMap = "\\" & StrComputer & "\c$\Documents and Settings\"
strDir = StrDriveMap
Set FSO = WScript.CreateObject("Scripting.FileSystemObject")
'** needed to ping ip
Set ws = WScript.CreateObject ("wscript.shell")

If reachable(strcomputer) Then 
	getInfo(strDir)
Else
	WScript.Echo "IP not active"
End If
'wscript.Echo "Search Complete"

Sub SearchFiles(aItem)    
    Select Case LCase(Right(CStr(aItem.Name), 3))
        Case "mp3"
                    WScript.Echo "FILE FOUND: " & aItem.Name
    End Select
End Sub

Sub getInfo(strDir)
    Set objDir = FSO.GetFolder(strDir) '**This Is the line**
    For Each FileItem In objDir.Files
        SearchFiles(FileItem)
    Next
    
    For Each NextFileItem In objDir.SubFolders
        ' wscript.Echo "Parsing Folder: " & NextFileItem.Name 
        getInfo(NextFileItem)
    Next
End Sub
'** function to see if ip is online
 Function Reachable(Hostname)
            intReturn = Ws.run("ping -n 2 -w 500 " & hostname, 0, True)
	If intReturn = 0 Then
		reachable = True
	Else
		reachable = False
	End If
End Function

Hope that works
 
Hi ddnwolff

When i run it against a machine that i know the IP of and that is live (its sitting next to me!!) it jut does not return with anything now!?

Just runs in task manager (wscript.exe) but i get nothing back at all?

Any ideas?
 
It is not impossible "Documents and Settings" be renamed. Are you sure it is not? You said it is sitting next to you. Why don't you try some other folder for testing?
 
Try raplacing

Code:
StrDriveMap = "\\" & StrComputer & "\c$\Documents and Settings\"
with
Code:
StrDriveMap = chr(34)  & "\\" & StrComputer & "\c$\Documents and Settings\" & chr(34)

This will put quotes around the string so you can use long file names.


bn2hunt

"Born to hunt forced to work
 
>This will put quotes around the string so you can use long file names
I don't think we need that for fso's getfile/getfolder methods, do you think?
 
Your probably correct on that, but for some reason I was thinking I had a simaler problem once when using an ip address to access a share rather than pc name, and that is what fixed it. But I can't find the script that I used that in so I am probably remembering wrong.

marshyrob
Have you tried accessing the share using the same format from your run command in windows to see if it is a problem with the script or if it is a problem with access or if windows can't find the share. ie.. start --> run ipaddress\c$\documents and settings\

bn2hunt

"Born to hunt forced to work
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top