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!

Find file and Copy to Specific Directory 1

Status
Not open for further replies.

thelionking

IS-IT--Management
Mar 21, 2008
4
CZ
Hello all,

I have a problem.
We have the server on the network with no display (LCD,CRT). I can use the admin rights on loggin to the server. I need to find some file placed on the server (for exam.: staticIP.cmd). I'd like to copy the located file to the specific folder. I have to use some batch file(s) (such as VBScript, DOS commands)

I know how the find file on the remote computer (DIR command), but I am not able to copy this found file via script
Can you help me please? [sadeyes]
 
I am using the following batch file for find the <name> file

:: ----------------------------------------------------
:: locate.bat
:: Locates Specified File Name
:: Syntax: locate <Drive (All)> <file name>
:: ----------------------------------------------------
@ECHO on

SET XSET=/UPPER
CALL XSET32 PARAMETER=%1
IF "%PARAMETER%" == "ALL" GOTO ALL-DRIVE

:ALL-DRIVE
ECHO.
ECHO Searching all Drives for " %2 "
ECHO.
FOR %%D IN (C: D: E:) DO DIR %%D\%2 /B /P /S > C:\locate.txt
GOTO END

:END
ECHO.
SET XSET=
 
Since we are in vbs forum (and that I don't use long time bat to copy file feeding the list from a source file), you can run this vbs after setting up c:\locate.txt. Also, one copy suffices, you just need to read the top line. This is how it is done - typed up off-hand, non-tested.
[tt]
'your input hard scripted
[blue]starget="d:\abc\" 'destination folder, with trailing backslash
slocationfile="c:\locate.txt"
[/blue]
set fso=createobject("scripting.filesystemobject")
set ofile=fso.opentextfile(slocationfile,1,true,-2)
if not ofile.atendofstream then
s=ofile.readline
end if
ofile.close
set ofile=nothing

if trim(s)<>"" then
a=split(s,"\")
t=a(ubound(a))
if fso.folderexists(starget) then
fso.copyfile s, starget & t, true
wscript.echo "File (copied) : " & s & vbcrlf & "Target : " & starget & t
else
wscript.echo "Destination folder does not exist. Nothing will be copied."
end if
else
wscript.echo "Location file does not contain useful data."
end if
set fso=nothing
[/tt]
 
Thank you very much for help. It works fine... I know that I`m in VBS forum. DOS commands have bounded function. And I am a beginner in VBs. I have read that VBs it could help me.. ehm ehm.. no vbs... you :)
 
Another question
If you can copy the file to the specific location via VBS.. is the vbs script able to find the <filename> from disk? I would like to inactive the DOS batch file..
Thank you
 
I have no problem on bat/cmd, they are very respectable device and get specific jobs done effectively.

As to the question, sure, you can run a shell commad exactly as the bat and direct output to the file. Again I have no problem with the communciation via a temp or persistent file: some do, I don't. This is how.
[tt]
'the givens to the functionality here
[blue]adir=array("c:","d:","e:") 'searched (mapped) drives
sfilename="abc.xyz" 'searched file name
ssource="c:\locate.txt"[/blue]

set fso=createobject("scripting.filesystemobject")
if fso.fileexists(ssource) then
fso.deletefile ssource,true 'prepare file anew
end if
set fso=nothing

set wshshell=createobject("wscript.shell")
for each sdir in adir
scmd="%comspec% /c " & sdir & " && cd\ && dir " & sfilename & " /b /s>>" & ssource 'no /p switch
wshshell.run scmd,0,true
next
set wshshell=nothing
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top