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

File search

Status
Not open for further replies.

rkapp2

MIS
Aug 7, 2007
12
US
I am tring to find a file named "username.id" locally on a PC. Can anyone help me with the syntax?

Thanks
 
What have you tried? Look in the FAQ section for an example of recursing through folders. Essentially you will need to look at every file in the path you specify for a file matching your search criteria.

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Here is what I tried.

Dim oFSO, FSO, NotesID, objNetwork, strUserName

set oFSO = WScript.Createobject ("Scripting.FileSystemObject")
set FSO = CreateObject ("Scripting.FileSystemObject")
set objNetwork = CreateObject ("WScript.Network")

strUserName = objNetwork.UserName
NotesID = "C:\Lotus\Notes\Data", .id"

set oFile = FSO.GetFile (NotesID)
ldFile = oFile.DataLastModified
oFSO.CopyFile "NotesID", "C:\NotesBackup"

I get a message stating the file cannot be found. Any help would be much appreciated.

Thanks
 
>oFSO.CopyFile "NotesID", "C:\NotesBackup"
[tt]oFSO.CopyFile [highlight]N[/highlight]otesI[highlight]D[/highlight], "C:\NotesBackup"[/tt]

Add overwrite flag to true, else repeated execution will be a runtime error.
[tt]oFSO.CopyFile NotesID, "C:\NotesBackup"[red],true[/red][/tt]

Also proof-read the script: some unexplainable bits are there.
>NotesID = "C:\Lotus\Notes\Data[highlight]", .[/highlight]id"

Further oFSO and FSO are the same thing. Either one is enough...
 
I omitted an object from the statement below.

NotesID = "C:\Lotus\Notes\Data" & strUserName & " .id
 
You omitted that all right, but did it work after?! That is what people would say what a followup is.
 
Ok, sorry for the improper follow up.

The information you gave did work. I msgbox NotesID, just to see what the output would be, which I set to "C:\Lotus\Notes\Data" & strUserName & " .id". It displayed the entire statement. I would like to just display the result of & strUserName & " .id". That is the file that I'm trying to backup.

Thanks
 
[1] Correction
>[self]Add overwrite flag to true, else repeated execution will be a runtime error.
This is incorrect, my fault. After checking the documentation again, the default of overwrite flag is true, so omitting that flag is okay and will not result in runtime by repeated execution. So with or without true flag is fine as long as it is not false.

[2] There is another typo.
>ldFile = oFile.DataLastModified
[tt]ldFile = oFile.Dat[red]e[/red]LastModified[/tt]

[3] I must confess I still cannot figure out whether eventual working or not for you. In any case, this is one possible cleanup version where some info not fully used is left untouched.
[tt]
Dim FSO, NotesID, objNetwork, strUserName, ldFile

set FSO = WScript.Createobject ("Scripting.FileSystemObject")
set objNetwork = CreateObject ("WScript.Network")

strUserName = objNetwork.UserName
NotesID = "C:\Lotus\Notes\Data" & strUserName & ".id"

if FSO.fileexists(NotesID) then
set oFile = FSO.GetFile (NotesID)
ldFile = oFile.DateLastModified
FSO.CopyFile NotesID, "C:\NotesBackup"
set oFile=nothing
else
wscript.echo "file: " & NotesID & " cannot be found."
end if

set objNetwork=nothing
set FSO=nothing
[/tt]
The destined file is name "NotesBackup" (not a foldername). But if there exists a folder named c:\NotesBackup, it is a runtime error. This will be the only main source of error untreated in the script. You can check the existence of it before issuing copyfile instruction. Like this.
[tt]
if FSO.folderexists("C:\NotesBackup") then
wscript.echo "Warning: backup filename collides with an existing folder. Operation aborted."
else
FSO.CopyFile NotesID, "C:\NotesBackup"
end if
[/tt]
I feel over-elaborated on simple thing!
 
Ok, I get it, you know what your talking about. Everything you have given me has worked.

Thanks over elaborated one.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top