Introduction
The Starsearcher develops from time to time batch scripts. In the
German part
of his website he describes batch scripts step by step. In English
this is not
possible for him, because his English is poor. He decided to
translate the
code a little and to describe the functions. Most of the people, who
have experience with batch scripts will understand. The code of the
Starsearcher is easy, but effective and in Germany his website is well
known - The statistic says that this website is under the first 120.000
in Germany.
All the following batch scripts are not destructive and there should be no
danger to try the batch scripts. There could be problems, because I had to
translate the text and there could be some mistakes. I use a German
user interface, so it was really a hard job.
So I hope you enjoy the result of my work! I`m working with windows 7 32.
The batch scripts should work with vista, but some commands definitely not
work with XP...
You need only the editor of windows. Open an empty text document, copy
the blue-green text and change the filename in *.bat . Then
you close the batch script and start it with a normal double-click.
For the most batch scripts you don`t need the rights of an
administrator...
Summary
double finder
table batch script
Self learning batch script
switchbatch script
batch scripts for searching files beyond a certain size
executable file list
HTA - how to show other html-documents without frames
double finder
Well, I made two versions of the batch script. The first version is for
finding double files in two folders without subfolders. The second version is created
for one directory (folder and subfolders).
I think that my way is world wide seldom...
However, the name of the batch script is not important.
doublefinder.bat
SET /p original=Enter the path to the directoy with
files you want compare
SET /p comparison=Enter the path
to the directory with the duplicates
set /p extension=Enter the file extension without a
dot!
chcp 28591 > NUL
for %%i in
("%original%\*.%extension%") do @echo %%~ni ^:%%~zi ^:%%i >>org.log
chcp 28591 > NUL
for %%i in
("%comparison%\*.%extension%") do @echo %%~ni ^:%%~zi ^:%%i >>comp.log
chcp 28591 > NUL
FOR /F "tokens=1,2,3* delims=:"
%%i IN (org.log) DO echo
%%i %%j %%k^:%%l >>result_%%j.log
chcp 28591 > NUL
FOR /F "tokens=1,2,3* delims=:"
%%i IN (comp.log) DO echo
%%i %%j %%k^:%%l >>result_%%j.log
for /f "delims=" %%a in ('dir /b
/a-d result_*.log') do more +1 "%%a">new_%%a
copy new_*.log double.txt
del *.log
In the document double.txt
are all doubles. There is the name of the file, the size of the files
in bytes and the path to the double. You are right! The size and the
file-extension are the criteria for the comparison. The result is
pretty good.
Another version for one complete directory and all subfolders:
SET /p directory=enter the path
to the directory
set /p extension=Enter the file extension without a
dot!
chcp 28591 > NUL
for /f "delims=" %%i in ('dir
%directory%\*.%extension% /s /b /a-d') do @echo %%~ni ^:%%~zi ^:%%i
>>org.log
chcp 28591 > NUL
FOR /F "tokens=1,2,3* delims=:"
%%i IN (org.log) DO echo
%%i %%j %%k^:%%l >>result_%%j.log
chcp 28591 > NUL
for /f "delims=" %%a in ('dir /b
/a-d result_*.log') do
more +1 "%%a">new_%%a
copy new_*.log double.txt
del *.log
----
Table batch
You can two rows or tables in two different docs put side by side in a
new document - this is normally a difficult action with a batch script!
I wrote this version in English - so it will work - try it!
You have to enter the name of the documents in the two red colored
lines. tableone.txt and tabletwo.txt are only examples. You can use
the
file extensions *txt, *csv...
The result is in the result.txt
- documents.
table.bat
FOR /F "tokens=*" %%A IN
('findstr /N .* "tableone.txt"') DO
echo %%A^: >> tableone.log
FOR /F "tokens=*" %%A IN
('findstr /N .* "tabletwo.txt"') DO
echo %%A^: >> tabletwo.log
FOR /F "tokens=1,* delims=:" %%i
IN (tableone.log) DO echo
%%j >tableone_%%i.log
FOR /F "tokens=1,* delims=:" %%i
IN (tabletwo.log) DO echo
%%j >tabletwo_%%i.log
set /a x=1
:further
for /f "delims=" %%a in (tableone_%x%.log) do for /f
"delims=" %%i in (tabletwo_%x%.log)
do echo %%i%%a >tablenew_%x%.log
set /a x=%x%+1
if exist *_%x%.log (goto further) else
goto final
:final
set /a y=1
:last
for /f "TOKENS=*" %%a in ('dir tablenew_%y%.log /b') do type
"%%a" >> result.txt
set /a y=%y%+1
if exist tablenew_%y%.log (goto last)
else goto nowend
:nowend
FOR /F "tokens=1,2 delims=:" %%i
IN (result.txt) DO echo
%%i%%j >>resulttwo.txt
del *.log
In result.txt you have
one colon as separator between the two tables in
the document. In resulttwo.txt
you have three blanks between the two
old documents. It does not matter. you can correct this...
-----
Self learning batch script
This batch script is learning, how to start a program with a keyword and
creates an own memory. The next time you start the batch script, you can enter
the keyword. The Starsearcher created some batch scripts to explore artificial
intelligence...There is another version to learn faster, but one here
is enough?!
Put the batch script in an empty folder and start the batch script
learn.bat
set /p progname= Hello, which
program want you open today?
if exist %progname%.bat
goto start
set /p path= do not know the program, enter the path to the exe!
chcp 28591 > NUL
create> %progname%.bat
Echo chcp 28591 ^> NUL >>%progname%.bat
Echo start "" "%path%" >>%progname%.bat
Echo exit >>%progname%.bat
:start
chcp 28591 > NUL
start "" "%progname%.bat"
exit taskkill /IM cmd.exe
One example: you start the first time the batch script. The memory is empty.
Now the program ask you, which program should be started by the
batch script. Now enter for example internetexplorer.
The batch script will answer : do not
know the program, enter the path to the exe!
You have to enter the full path with the *.exe , for example C:\Program Files\Internet Explorer\iexplore.exe,
the program will start and the batch script ends. The next time you
start the batch script and enter internetexplorer.
The internet explorer will
start now. Why? The batch script made a notice in a new created batch script and know
now the path of the
internet explorer. If exist a new created batch script with the name internetexplorer,
this batch script will be startet. On this way the batch skript learns step by step
the paths
and the names of the programs and will remember...By the way there are a
lot of batch scripts in the folder, when you use the learn-batch script. Try it!
Look in the folder with the learn batch script after using it and you will
understand...
An interesting game or more - its your decision.
----
switchbatch script
This batch script switches between two states. There is a system for
batch scripts
to make decisions - the batch script makes an action and creates a document:
this is the hint that there is another state. After a second start the
batch script realizes that there is a document. So now a different action
starts
and the document will be
destroyed by the batch script. So the batch script know after the next start that the
state changed again....
This batch script starts the internet explorer and creates a document, which is
called Time.log.
In this document there is the date and time, when you start the
batch script, the batch script opens the internet explorer. Now you can use the
internet explorer. When you are ready
to close the internet explorer, start the batch script again. The batch script knows
now that there is a open internet explorer, make a notice with the
endtime and close the internet explorer.
Put the batch script in a folder or on the desktop!
if not exist time.log echo
%date%>time.log
if exist change.txt goto
change
start "" "C:\Program Files\Internet Explorer\iexplore.exe"
ECHO %date% %Time% >>time.log
echo Dummytext >change.txt
goto end
:change
ECHO %date% %Time% >>time.log
del change.txt
taskkill /IM iexplore.exe
:end
How is it possible?
At the first time the batch script started there was created a document named change.txt. At the second
start there exist the document change.txt
and the second routine runs.
After closing the internet explorer change.txt will be destroyed.
So at
the next start the first routine runs again.
This is nothing more as the indirectly way to determine the state of
the internet explorer - Is it open or not?
Now you can use this way to change the registry for example: The
decision between two values: If exist not a document the batch script
changes a value and creates a document. When you start
the batch script a second time, there is this document and the batch script starts a
second routine and enter the old value in the registry and destroys after
this action the document. After the next start the document not exist...
Maybe one example in form of a small batch script. The batch script changes the
registry. There are two states: The first state shows all
file-extensions on the desktop or in folders. The second state is the
normal view in the
explorer. All file-extensions like *.jpg, *.docx are hidden. Try the
batch script. There
is no risk. After changing the value in the registry the process
explorer.exe will be
closed and then in the next moment the explorer starts again. So You
see the result immediately and you don`t have to restart the system.
if exist change.txt goto statetwo
reg add
hkcu\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced /v
HideFileExt /t REG_DWORD /d 0 /f
taskkill /f /IM explorer.exe
start explorer.exe
Dummytext>change.txt
goto ende
:statetwo
reg add
hkcu\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced /v
HideFileExt /t REG_DWORD /d 1 /f
del change.txt
taskkill /f /IM explorer.exe
start explorer.exe
:ende
Well, the batch script uses the
change.txt
to remember, if the value 1 or 2 exist in the registry. The
action depends on the existing of the change.log. Easy to understand.
It is just another form of the switchbatch script. The textdocument is only a
criteria for the following action...
You see - the batch script is not important, only the way...
---
batch script for searching files beyond a certain size
In this case we need two batch scripts. The first name is not important, but the second must be help.bat
size.bat (name ist not important)
SET /p path=enter the path to the highest folder in the directory!
set /p extension=enter the extension of the file without a dot
for /f "delims=" %%i in ('dir %path%\*.%extension% /s /b /a-d') do @echo %%~zi^:%%~ni^:%%i >>gro.log
FOR /F "tokens=1,2,3* delims=:" %%i IN (gro.log) DO echo %%i %%j %%k^:%%l >>%%i.log
FOR /F "tokens=1,2,3* delims=:" %%i IN (gro.log) DO call help.bat %%i %%j %%k:%%l
del *.log
help.bat enter this name or change the name after the call - command in the first batch script...
set /a x=%1
if %x% lss 50000 del %x%.log
if %x% GEQ 50000 echo %1 %2 %3 >> result.txt
end
You only have to start the size.bat. At the moment the batch script searches files over 50000 Bytes! You can change the values, but you have
to change the values two times in the help.bat. The files will be listed in the result.txt
The following command-line could be interesting for you!
for /f "delims=" %%i in ('dir %pfad%\*.%extension% /s /b /a-d') do @echo %%~zi^:%%~ni^:%%i >>gro.log
The folder and the subfolders will be proofed.
However, this batch script is simular to the double-finder batch script...
----
executable file list
It is easy to create a normal file list with the dir - command, but it is only with a special command possible to create a executable file list. However, I used the command-line:
You have to put the batch script in the highest folder of a directory or path. The subfolders are also included.
Then you start the batch: Enter the file
extension without a dot. The batch will create the file list relative
to the batch script.
The result.htm must be opened by the internet explorer.
By the way it is possible to make hyperlinks to files or documents on
your PC. It does not work online! A little more professional is to use
a *.hta...
set /p extension= enter the extension without a dot!
set destination=%~dp0%
chcp 28591 > NUL
for /f "delims=" %%i in ('dir "%destination%*.%extension%" /s /b /a-d') do @echo %%~zi^:%%~ni^:%%i >>result.log
>"%destination%new.htm" ECHO ^<html^>
>>"%destination%new.htm" ECHO ^<head^>
>>"%destination%new.htm" ECHO ^<style type="text/css"^>
>>"%destination%new.htm" ECHO a {color:#FFFF33; font-size:10pt;
font-family:verdana,sans-serif,tahoma; text-decoration:none}
>>"%destination%new.htm" ECHO a:hover {color:#FF0000;
font-size:10pt; font-family:verdana,sans-serif,tahoma;
text-decoration:none}
>>"%destination%new.htm" ECHO a.menu1 {color:#FFFFFF;
font-family:verdana,sans-serif,tahoma; font-size:8pt;
text-decoration:none}
>>"%destination%new.htm" ECHO a.menu1:hover {color:#FF0000;
font-family:verdana,sans-serif,tahoma; font-size:8pt;
text-decoration:none}
>>"%destination%new.htm" ECHO a.menu2 {color:#FFFFFF;
font-family:verdana,sans-serif,tahoma; font-size:9pt;
text-decoration:none}
>>"%destination%new.htm" ECHO a.menu2:hover {color:#FF0000;
font-family:verdana,sans-serif,tahoma; font-size:9pt;
text-decoration:none}
>>"%destination%new.htm" ECHO ^</style^>
>>"%destination%new.htm" ECHO ^</head^>
>>"%destination%new.htm" ECHO ^<body style="color: white; background-color: black;" alink="red"
>>"%destination%new.htm" ECHO link="yellow" vlink="#3333ff"^>
chcp 28591 > NUL
for /F "delims=: tokens=1,2,3*" %%i in (result.log) do nothing
>>new_%%i.log & >>"new_%%i.log" Echo ^<p
class=MsoNormal^>^<span lang=EN
style='font-weight:normal'^>^<a href="%%k:%%l"^>filename %%j
size %%i^</a^>^</span^>^</p^>
copy new_*.log result.log
copy new.htm + result.log result.htm
del *.log
del new.htm
>>"%destination%result.htm" ECHO ^</body^>
>>"%destination%result.htm" ECHO ^</html^>
----
HTA - how to show other html-documents without frames
Sometimes the starsearcher develops a little bit the hta-world. This
small hta demonstrates, how to show other html-sides without frames in
a DIV-Container of a hta:
<html>
<head>
< title>TEST</title>
< hta:application scroll="no" windowState="normal">
<style type="text/css">
.auto {
background: #00BFFF;
height: 300px;
overflow: auto;
width: 400px;
border: 1px solid #000;
padding: 10px;
}
</style>
</head>
<script language="VBScript">
sub Rundoku
set oFSO=CreateObject("Scripting.FileSystemObject")
set oFile=oFSO.OpenTextFile("some.htm",1)
text=oFile.ReadAll
document.all.DataArea.InnerHTML = text
oFile.Close
end sub
</script>
<body>
< div id=DataArea
class="auto"><center><input id=runbutton class="button"
type="button" value="result" name="run_button"
onClick="Rundoku"></center></div>
</body>
</html>
Well, you have to to change the green some.htm to the name of your html, htm or txt-document. After using the result-button, you will see your document in the div-container.
The size of the container is defined in the css-document (red).
However, you should use a container to determine the design in the hta.
The container includes a scrollbar (overflow: auto;). All the text will be shown. Hyperlinks work of course also.
It is possible with *.txt, too
The big advantage is, that you can determine the color of the container with css.
For example: It is not possible with frames and the command about blank to change the white color. If you go the way of the starsearcher, you can do it simply better!
Another variation is to get all the text from clipboard. Copy a text to the clipboard and start the hta:
<html>
<head>
<title>TEST</title>
<hta:application scroll="no" windowState="normal">
<style type="text/css">
.auto {
background: #00BFFF;
height: 300px;
overflow: auto;
width: 400px;
border: 1px solid #000;
padding: 10px;
}
</style>
</head>
<script language="VBScript">
sub Rundoku
DataArea.InnerHTML = document.parentwindow.clipboardData.GetData("text")
End Sub
</script>
<body>
<div id=DataArea
class="auto"><center><input id=runbutton class="button"
type="button" value="result" name="run_button"
onClick="Rundoku"></center></div>
</body>
</html>
----