Dear,First we reformat your script.
code:
BREAK ON
$filename = "*.exe"
$startdir = "d:\users\"
$tmpfile = "d:\log\files.txt"
CD "$startdir"
SHELL "%comspec% /c dir /s /b $filename > $tmpfile"
; sleep 20
$nul = open(1,$tmpfile,2)
$filename = readline(1)
WHILE @error = 0 ? $filename
$companyname = GETFILEVERSION ($filename,"CompanyName")
$fileversion = GETFILEVERSION ($filename,"FileVersion")
$filedescription = GETFILEVERSION ($filename,"FileDescription")
$productname = GETFILEVERSION ($filename,"ProductName")
IF $companyname <> ""
$result=setconsole('show')
$logfile="e:\filelogw.TXT"
$logdata = $filename + Chr(9) + $filedescription + Chr(9) + $fileversion + Chr(9) + $companyname+ Chr(9) + $productname + Chr(13) + Chr(10)
$result=0
$n=0
$result=Open(1, $logfile, 5)
IF $result<>0
$result=WriteLine(1, $logdata)
$result=Close(1)
ENDIF
$n=$n+1
ENDIF
;$FileName = Dir("")
$filename = readline(1)
? $filename
LOOP
CLS
We find your problem with the WHILE/LOOP structure. You read the information
from unit 1 and when you find a record you want to write to same unit 1. This is
of course not possible, but only the Close(1) will be executed correctly and
the next ReadLine(1) call will return an error.
We have also reformat your script a little bit.
Some remarks:
- put your variables at the big of your script. so we move the variable $logfile
to the big of your script.
- you don't need the cd command first. You can specify your $startdir
during the shell command.
- we quot your DIR specification. By the usage of longfilename it will not create
an error.
- We are only entry the WHILE/LOOP structure, when the file has been
opened without errors.
- the $result=0 isn't necessary.
- we have remove the $n statements. They are unused.
- we change $result to $nul when you don't really use it.
It may give you an idea to improve your script.Our version:
code:
CLS
BREAK ON
$filename = "*.exe"
$startdir = "d:\users\"
$tmpfile = "d:\log\files.txt"
$logfile = "e:\filelogw.txt" $startdir = "c:\windows\" ; - our specification -
$tmpfile = "c:\temp\files.txt" ; - our specification -
$logfile = "c:\temp\filelogw.txt" ; - our specification -
;
? "Check "+$startdir+$filename
? "Logfile "+$logfile
;
SHELL '%comspec% /c dir "$startdir$filename" /s /b >$tmpfile '
;
IF Open(1,$tmpfile,2)
$filename = ReadLine(1)
WHILE (@error = 0)
? $filename
$companyname=GetFileVersion($filename,"CompanyName")
$fileversion=GetFileVersion($filename,"FileVersion")
$filedescription=GetFileVersion($filename,"FileDescription")
$productname=GetFileVersion($filename,"ProductName")
IF ($companyname <> "")
$logdata=$filename+Chr(9)+$filedescription+Chr(9)+$fileversion+Chr(9)+$companyname+Chr(9)+$productname+Chr(13)+Chr(10)
IF Open(2, $logfile, 5)
$nul=WriteLine(2, $logdata)
$nul=Close(2)
ENDIF
ENDIF
$filename=ReadLine(1)
LOOP
$nul=Close(1)
ENDIF
? "completed"
A piece of output "c:\temp\files.txt":
code:
c:\windows\accstat.exe
c:\windows\arp.exe
c:\windows\bcuninstall.exe
c:\windows\calc.exe
c:\windows\cd32.exe
....
c:\windows\system\dcom95\oldole\dllhost.exe
c:\windows\system\dcom95\oldole\rpcss.exe
c:\windows\system\dcom95\oldole\uninstal.exe
The result file can be "c:\temp\filelogw.txt":
code:
c:\windows\arp.exe TCP/IP Arp Command 3.51 Microsoft Corporation Microsoft® Windows NT(TM) Operating System
c:\windows\cdplayer.exe CD Player accessory 4.00.950 Microsoft Corporation Microsoft® Windows® Operating System
c:\windows\clspack.exe Class Package Export Tool 5.00.3167 Microsoft Corporation Microsoft(R) Windows (R) Operating System
c:\windows\defrag.exe Microsoft Disk Defragmenter 4.00.1111 Microsoft Corporation Microsoft® Windows® Operating System
c:\windows\directcc.exe Direct Cable Connection application 4.00.1111 Microsoft Corporation Microsoft® Windows® Operating System
....
c:\windows\system\dcom95\oldole\uninstal.exe Install DCOM for Windows 95 4.71.3116 Microsoft Corporation Microsoft(R) Windows NT(TM) Operating System
greetings.