Problem:
Need to find the keyword "ORDER, " in a large folder of txt files. Need to move all files that don't have this keyword to another folder.
How do I count the number string instances for all files in a directory?
Here is an example of looking for the string "ORDER, " in all txt files.
find /C "ORDER, " *.txt
How do I filter for items with a count of zero?
find /C "ORDER, " *.txt | findstr /c:": 0"
This is because each line in the output of find comes up:
---------- stats-2011-09-13.TXT: 0
---------- stats-2011-09-12.TXT: 12
What if I want to move all files from a list to some folder?
First output your results by doing redirection.
find /C "ORDER, " *.txt | findstr /c:": 0" > list.txt
You can open the file and strip out everything except the filename and extension. Once that's done, just use a for loop to move everything in list.txt.
for /f %a in ('type list.txt') do move %a no_orders
Showing posts with label windows. Show all posts
Showing posts with label windows. Show all posts
Tuesday, September 13, 2011
Wednesday, March 17, 2010
Set program output to environment variable in batch file
FOR /F "tokens=*" %A IN ('prog.exe') DO SET ENVVAR=%A
Sunday, January 17, 2010
start menu pin list location
> If I pin a shortcut to the startmenu, where does XP store this
> information?
With a shortcut in this folder...
C:\Documents and Settings\All Users\Start Menu
The above folder would be the easiest.
Also here...
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\
Explorer\MenuOrder\Start Menu2\Programs
Value Name: Order
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\
Explorer\StartPage
Value Name: Favorites
Value Name: FavoritesResolve
All of those are REG_BINARY values and hard to read them.
Thursday, September 3, 2009
Cut out unwanted pieces of a lastname with vbscript
lastname = "DE' CA-R LO III"
'separate lastname by spaces into an array
a = split(lastname," ")
new_lastname = a(0)
for i = 0 to ubound(a) -1 ' add each chunk of the last name to the final string
'the last piece of the last name is not added if it is less than 4 characters (such as III, II, I, etc)
if i + 1 = ubound(a) and len(a(i+1)) > 3 then
new_lastname = new_lastname + a(i+1)
elseif i + 1< ubound(a) then
new_lastname = new_lastname + a(i+1)
end if
next
new_lastname = Replace(new_lastname,"-","") 'take out hyphens
new_lastname = Replace(new_lastname,"'","") 'take out punctuations
wscript.echo new_lastname
Thursday, August 20, 2009
Installing a folder tree of fonts on XP
rem XP doesn't let you select a folder to install fonts from; it will not recurse to find fonts within a folder unless they are all under one folder
rem This command will go through all folders in the current directory and copy the files to all_fonts
rem The /y for copy will force an overwrite if a duplicate file shows up
for /F "tokens=1 delims=," %a in ('dir /s /b') do copy /y "%a" all_fonts
rem This command will go through all folders in the current directory and copy the files to all_fonts
rem The /y for copy will force an overwrite if a duplicate file shows up
for /F "tokens=1 delims=," %a in ('dir /s /b') do copy /y "%a" all_fonts
Friday, June 12, 2009
Monday, June 8, 2009
Tricks with the Echo command in XP
rem generate list with echo
for /l %a in (1,1,9) do echo "station-0%a"
rem Generate a file with echo to a room of computers
for /l %a in (1,1,50) do echo "station-%a" > \\station-%a\c$\myfile.txt
for /l %a in (1,1,9) do echo "station-0%a"
rem Generate a file with echo to a room of computers
for /l %a in (1,1,50) do echo "station-%a" > \\station-%a\c$\myfile.txt
Friday, June 5, 2009
Set remote desktop from command line
reg add "\\computer\hklm\system\currentcontrolset\control\terminal server" /v "fDenyTSConnections" /d 0 /t REG_DWORD /f
0 is off and 1 is on
0 is off and 1 is on
Wednesday, June 3, 2009
Generate a command window for each iteration of a loop
rem This is good for those commands that take a lot of time.
rem Each iteration generates a new cmd window
for /l %a in (1,1,10) do start cmd /k psexec \\computer-%a time-consuming.exe
rem Each iteration generates a new cmd window
for /l %a in (1,1,10) do start cmd /k psexec \\computer-%a time-consuming.exe
Force a live update from command line
This will perform a silent live update of Symantec Antivirus 10.2
"c:\Program Files\Symantec AntiVirus\VPDN_LU.exe" /fUpdate /s
"c:\Program Files\Symantec AntiVirus\VPDN_LU.exe" /fUpdate /s
Adding a printer with vbscript from a network share
rem Add the connection
cscript prnmngr.vbs -ac -p \\server\printer_share
rem Set it as a default
cscript prnmngr.vbs -t -p "\\server\printer name"
rem If you don't know the name
cscript prnmngr.vbs -l
cscript prnmngr.vbs -ac -p \\server\printer_share
rem Set it as a default
cscript prnmngr.vbs -t -p "\\server\printer name"
rem If you don't know the name
cscript prnmngr.vbs -l
Keeping track of station numbers with a text file
rem Usually I keep track of the configurations associated with a station by its mac
rem Without the macs, one can keep track of what configuration to use by using a counter
rem
rem This works well with a network or a flash drive
for /f %%a in ('type \\server\share\count.txt') do SET temp=%%a
rem echo %temp%
SET /A temp+=1
echo %temp% > \\server\share\count.txt
rem The counts of count.txt is simply a number and can be used in a script
rem Without the macs, one can keep track of what configuration to use by using a counter
rem
rem This works well with a network or a flash drive
for /f %%a in ('type \\server\share\count.txt') do SET temp=%%a
rem echo %temp%
SET /A temp+=1
echo %temp% > \\server\share\count.txt
rem The counts of count.txt is simply a number and can be used in a script
Tuesday, June 2, 2009
net time commands
net time (time from domain server)
net time /querysntp
net time /set \\another_pc
net time /setsntp:time.apple.com
net time /querysntp
net time /set \\another_pc
net time /setsntp:time.apple.com
Monday, June 1, 2009
Change a computer name with vbscript
Scripting the changing of computer names in windows is straight-forward with a vbscript.
You can change a computer via the registry, so this is the approach used here.
Set the computer name you want in the sNewName variable.
sNewName = "new_pc_name"
Set oShell = CreateObject ("WSCript.shell")
sCCS = "HKLM\SYSTEM\CurrentControlSet\"
sTcpipParamsRegPath = sCCS & "Services\Tcpip\Parameters\"
sCompNameRegPath = sCCS & "Control\ComputerName\"
With oShell
.RegDelete sTcpipParamsRegPath & "Hostname"
.RegDelete sTcpipParamsRegPath & "NV Hostname"
.RegWrite sCompNameRegPath & "ComputerName\ComputerName", sNewName
.RegWrite sCompNameRegPath & "ActiveComputerName\ComputerName", sNewName
.RegWrite sTcpipParamsRegPath & "Hostname", sNewName
.RegWrite sTcpipParamsRegPath & "NV Hostname", sNewName
End With ' oShell
You can change a computer via the registry, so this is the approach used here.
Set the computer name you want in the sNewName variable.
sNewName = "new_pc_name"
Set oShell = CreateObject ("WSCript.shell")
sCCS = "HKLM\SYSTEM\CurrentControlSet\"
sTcpipParamsRegPath = sCCS & "Services\Tcpip\Parameters\"
sCompNameRegPath = sCCS & "Control\ComputerName\"
With oShell
.RegDelete sTcpipParamsRegPath & "Hostname"
.RegDelete sTcpipParamsRegPath & "NV Hostname"
.RegWrite sCompNameRegPath & "ComputerName\ComputerName", sNewName
.RegWrite sCompNameRegPath & "ActiveComputerName\ComputerName", sNewName
.RegWrite sTcpipParamsRegPath & "Hostname", sNewName
.RegWrite sTcpipParamsRegPath & "NV Hostname", sNewName
End With ' oShell
VBScript tricks : no logo, filesystem, control blocks, argument
'When running from the console, here is how to hide the logo
cscript //Nologo myscript.vbs
'How to reference an argument
WScript.Arguments.Item(0)
'Here is how to read a file
set f = fso.opentextfile(source, 1,false)
if fso.fileexists(source) then
while not f.atendofstream
inputline = f.readline
msgbox inputline
wend
end if
Monday, April 20, 2009
Universal scripted uninstall (XP)
Given the displayname value, this vbscript will go and find it in the registry and uninstall the corresponding program.
This is where it searches:
hklm\software\microsoft\windows\currentversion\uninstall
This is where it searches:
hklm\software\microsoft\windows\currentversion\uninstall
' arg 1 - displayname
if (wscript.arguments.count > 0 ) then
set shell = wscript.createobject("wscript.shell")
strcmd = "reg query hklm\software\microsoft\windows\currentversion\uninstall /s"
set oexec = shell.exec(strcmd)
temp = 0
parent = ""
do while not oexec.stdout.atendofstream
strline = oexec.stdout.readline
if len(strline) > 0 then
a=split(strline,vbtab)
if mid(trim(a(0)),1,4) = "HKEY" then
b = split(trim(a(0)),"\")
parent = b(ubound(b))
temp = 1
end if
alen = ubound(a) + 1
if alen >= 3 then
if trim(a(0)) = "DisplayName" and trim(a(2)) = wscript.arguments(0) and temp = 1 then
wscript.echo "msiexec /x " & parent & " /qn"
temp = 0
shell.exec("msiexec /x " & parent & " /qn")
exit do
end if
end if
end if
loop
end if
Friday, December 19, 2008
Viruses are back again!
Just when you thought XP Antivirus 2008 died out, enter AntiSpyware 2009. This piece of crap gets on your machine by screwing up internet explorer and the startup environment. The damn thing protects itself even in safe mode. I'm not sure how it does this; usually this is done with winlogon.exe, but the winlogon registry key seemed to be clean. We've just been reghosting the machine. Watch where you click! When you see a dialog box about spyware (and it's definitely not your antivirus software) restart your machine (this dialog box is from internet explorer).
Blackberry desktop manager
Working with the BDM has not been a general pleasure for me and other technicians where I work. It doesn't sync all the time, most likely due to corrupt organizer data and/or buggy software. The weird thing is that it was working kind alright when we had an Exchange server, but it got crappy when we migrated to a MAPI connector with Sun. I got it syncing by installing the exchange redirector BDM (we're still using outlook) and disabling redirection?! In the process of stumbling on this, I became familiar with just about every troubleshooting BB trick. Fun!
Subscribe to:
Posts (Atom)