Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

8001.

Solve : track a process running time?

Answer»

Any commands or code could track a process running time within a batch file?

When I RAN iteration of a process in Windows XP, a single process sometimes takes 100 HOURS (very rare, 1 of 50 iterations), and normally it shall take 1-2 minutes. It is a convergence problem in MCMC and I can not control it.

As an alternative, In my code, I can invoke OS batch file. If I could track a process running time, I can kill it with taskkill after a given time, such as 10 minutes.

I think it may work as:

1) sleep 0.5 seconds till a process start to run,

2) start to track the process running time,

3) if the process is done in 10 minutes, then END; else kill it.

Really appreciate your suggestions.

C:\batch>type kill10.bat

Code: [Select]rem C:\batch>sleep

rem Arguments are: Sleep <seconds>

rem www.tricerat.com

@echo off

sleep 600

Rem From tasklist:
rem notepad.exe 2192 Console 0 548 K

taskkill /pid 2192

OUTPUT:


C:\batch>kill10.bat


SUCCESS: Sent termination SIGNAL to the process with PID 2192.

C:\batch>Quote from: gnomegordon on January 18, 2010, 06:55:38 PM

Any commands or code could track a process running time within a batch file?

I can no longer modify (edit ) post #1. The modify key is not available.

The following batch finds the pid number and a COMMAND line argument allows the name of any process or application.


C:\batch>type kill10.bat

Code: [Select]@echo off

sleep 600


tasklist | findstr "%1" > notepid.txt


for /f "tokens=1,2 delims= " %%i in (notepid.txt) do (
echo pid=%%j

taskkill /pid %%j

)
Output:

C:\batch>kill10.bat notepad

pid=2284
SUCCESS: Sent termination signal to the process with PID 2284.
C:\batch>
8002.

Solve : ftp command ????

Answer» HELLO

(i don't KNOW english)

i will
if the computer connected to internet

start ftp and SEND my files

thank you.Don't worry about the English...
What ftp program are you using ? ?in cmd

ftp -s:ftp.txt

ftp.txt:

open my server
my username
my password
bin
put myfile.txt
bye
-----------------

but if computer not connected to internet don't send my file
Quote from: mss9668 on April 14, 2013, 01:47:48 AM
but if computer not connected to internet don't send my file

Is that the problem you are FACING?

Code: [Select]@echo off
ping www.google.com >nul || (
echo You are not connected to the internet
pause
)

no....

for example :

Code: [Select]@echo off
cls
:1
if connected to internet goto 2
if not connected to internet goto 3
:2
ftp -s:ftp.txt
:3
goto 1
EDITED

Code: [Select]@echo off
:loop
ping www.google.com >nul && (ftp -s:ftp.txt) || (goto :loop)
Quote from: mss9668 on April 14, 2013, 03:37:47 AM
no....

for example :

Code: [Select]@echo off
cls
:1
if connected to internet goto 2
if not connected to internet goto 3
:2
ftp -s:ftp.txt
:3
goto 1

You don't NEED to use three labels. One will do.

:1
if not connected to internet goto 1
ftp -s:ftp.txt


Practical implementation:

:1
ping -n 1 www.google.com >nul
if %errorlevel% gtr 0 goto 1
ftp -s:ftp.txt

or...

:1
ping -n 1 www.google.com >nul || goto 1
ftp -s:ftp.txt

8003.

Solve : Can please help on Telnet Batch file?

Answer»

Hi,

Can someone help me on my Telnet batch FILE? Basically what my current batch file do is telnet to a specific IP and save a screenshot of it automatically. Now what I want to do is create a text file then save all the IP and ports on it, then run a batch script to run telnet and get all the IP's and ports on the said text file. Would this be possible? Any help would be appreciate. Thanks a lot.

Regards,
MykelWhat is this for and how are you saving a screen capture? It would also help if you could post your code.Hi Lemonilla,

I USE this batch file for testing on every router I install on the client site. There are a lot of IP's and ports needed to be tested once router is up and running. For me to do it, I need to edit and PASTE each IP on each line of my batch script.


Telnet.bat

@echo off


Start "" "C:\telnet test\Captured screen"
TIMEOUT 3

start "" "C:\Windows\System32\Telnet.exe" x.x.x.x yyyy
start nircmd.exe cmdwait 5000 savescreenshotwin "C:\telnet test\Captured screen\scr~$currdate.MM_dd_yyyy$-~$currtime.HH_mm_ss$.png"
TIMEOUT 7
nircmd.exe closeprocess Telnet.exe

start "" "C:\Windows\System32\Telnet.exe" x.x.x.x yyyy
start nircmd.exe cmdwait 5000 savescreenshotwin "C:\telnet test\Captured screen\scr~$currdate.MM_dd_yyyy$-~$currtime.HH_mm_ss$.png"
TIMEOUT 7
nircmd.exe closeprocess Telnet.exe


x.x.x.x = server IP
yyyy = ports

As you can see on the script, I need to key-in the IP's and ports (x.x.x.x yyyy). You say you want the IP list in a text file, but you are saving PNG files. Do you intend to do an OCR of the PNG files?

I think I misunderstood where the ip:ports were coming from.I am assuming that your text file CALLED iplist.txt is a list of IP:port addresses like so: 111.222.333.444:1024
one IP:port PER line.

This batch file will then create the images:


Code: [Select]@echo off
Start "" "C:\telnet test\Captured screen"
TIMEOUT 3

for /f "delims=" %%a in (iplist.txt) do (
start "" "C:\Windows\System32\Telnet.exe" %%a
start nircmd.exe cmdwait 5000 savescreenshotwin "C:\telnet test\Captured screen\scr~$currdate.MM_dd_yyyy$-~$currtime.HH_mm_ss$.png"
TIMEOUT 7
nircmd.exe closeprocess Telnet.exe
)

8004.

Solve : Delete All Users Local Settings/Application Data?

Answer»

Our organization has sever applications that install cache and settings under the "C:\Documents and Settings\%Userprofile%\Local Settings\Application Data" directory. This is fine and dandy' until the application has an issue and need to be completely installed and REINSTALLED. At this point the cache and user file are sometimes left behind. I would like to find an easy efficient way of removing these directories.
In the past we have not had more than 1 user to deal with so it was a simple install then remove the cache files however, we recently implemented a few workstations in a facility that uses a domain and has over 20 users that rotate through, all the users have login's. Which is where I run into a problem...
I have yet to see an easy way around this that does not involve opening each individual user profile and navigating to the files in question and deleting them. What I would really like is a batch file I could run that would delete these directory's, but cant for the life of me figure out how to write it. SOMETHING like the following would be perfect but either my syntax is wrong or I just lack the experience with batch files:

del C:\Documents and Settings\%UserProfile%\Local Settings\Application Data\"files in question"
del C:\Documents and Settings\%UserProfile%\Application Data\"files in question"

I have EVEN toyed with the notion of running two separate programs, one to query the "Documents and Settings" directory for all of the users that would dump to a .txt, then a second program that would query that .txt and remove the directories based on what is in the .txt.

Anyone that can help please do. I can LIVE if there is no easy way, but it would probably save me a few hours over the next couple of months.,


C:\>type appdata.bat
Code: [Select]@echo off

cd %userprofile%/Application Data/

dir *.txt

rem del *.txt
Output:


C:\> appdata.bat
Volume in drive C has no label.
Volume Serial Number is F4A3-D6B3

Directory of C:\Documents and Settings\Bill Richardson\Application Data

01/23/2010 12:43 PM 8 user.txt
1 File(s) 8 bytes
0 Dir(s) 303,193,333,760 bytes free

C:\Documents and Settings\Bill Richardson\Application Data>All Users i believe would not be a workable approach as it becomes a protected system file.

Maybe using an APP before the fact (or install) would be beneficial such as Total Uninstall...
It takes a snapshot of all files and folders created/changed on installation including the registry and thus when an app is uninstalled it removes all remnants of that app including cached and temp files.

8005.

Solve : Can someone create a batch file for me??

Answer»

I am hoping someone can make me a batch file where it will automatically submit the answer at the end.



6



http://seriouswars.net/macro2.php?action=validate">


One

Two

Three

Four

Five

Six

Seven

Eight

Nine









the batch file i need or the program i need would be - where it automatically validates the code.

if you COPY all that info and call it whatever.html you will see it I apologize for the spam that took over your topic. It has been removed.

I do not have the answer to your question, but I hope you will receive help soon.All the html code does is display 9 radio buttons and a validate button. Where did this code come from? and what exactly do you want to validate?

Batch code does not have the functionality to validate web pages. What you can do is create an external script which can create an INSTANCE of a web browser (IE has a InternetExplorer.Application object; Firefox has one too but it's older than dirt and I'm not sure it will work with the newer releases).

Once you create the instance you can use the methods and properties of the browser object to set values and submit the form for validation.

Check out Internet Explorer Object for more help or post your questions here and we'll see what we can do.

Good luck. Try http://validator.w3.org/#validate_by_input. I think it will work. But next TIME, don't post this in the MicroSoft DOS section.
8006.

Solve : Help - script to rename file based on size?

Answer»

Dear Experts,

I'm new in DOS PROGRAMMING, so please HELP me to solve my issue.
I want to create script with these logic:
1. Check size file test.log,
2. if the size more than 500MB then close cmd.exe
3. rename the test.log became test.log.20130910 and move to archive folder
4. start the cmd.exe with execute program in the path C:\program\top.exe without close the window.
5 back to number 1. This process always repeated.

Really appreciate for any comment


Thanks
EdyQuote from: serpihankaca on September 10, 2013, 10:19:40 AM

This process always repeated.

Repeated FOREVER?

Do you want the repetition to be instant, or with a pause? If so, how long?Quote
if the size more than 500MB then close cmd.exe

You cannot execute dos commands without the window opened. You can have this part in VBS or something else, or you can have the window remain open.Quote from: Lemonilla on September 10, 2013, 01:36:04 PM
You cannot execute dos commands without the window opened.

I don't think that is what he means, but until he comes back we won't know.
8007.

Solve : start hide program?

Answer» HI...

what open program HIDE?

for example :

Code: [Select]start /hide myprogram.exe
Why?
The forum will help people with important questions.
It does not help people make a virus.
no....

i need to this command You cannot hide a program with Command PromptA bit dramatic Geek to say he's makin a virus.Quote from: patio on April 14, 2013, 12:19:44 PM
A bit dramatic Geek to say he's makin a virus.
OK. I was dramatic. But why WOULD he want to hide it?thank you.

for guide...


Code: [Select]@echo off
cls
(
set args = WScript.ARGUMENTS
num = args.Count

if num = 0 then
WScript.Echo "Usage: [CSCRIPT | WScript] invis.vbs aScript.bat <some script arguments>"
WScript.Quit 1
end if

sargs = ""
if num > 1 then
sargs = " "
for k = 1 to num - 1
anArg = args.Item(k)
sargs = sargs & anArg & " "
next
end if

Set WshShell = WScript.CreateObject("WScript.Shell")

WshShell.Run """" & WScript.Arguments(0) & """" & sargs, 0, False
)> invis.vbs
wscript.exe invis.vbs myprogram.exe %*
OK. An administration may run a task in the background as a schedule task. It have be minimized so that it only shows on the task bar.
But it ought to be Power Shell, not command prompt.
Here is a link that may offer some ideas.
http://stackoverflow.com/questions/1802127/how-to-run-a-powershell-script-without-displaying-a-window

8008.

Solve : How to automate Outlook E-mails to PDF?

Answer»

Is there a WAY to automate outlook e-mail conversions to PDF? I understand creating the rule in Outlook, but automation stops because the file has to be renamed. I was wondering if there is a script that I can write into the rule that will name the file by date & time. Any help WOULD be greatly appreciated.A) export all Outlook EMAILS to SEPARATE FILES in a folder
B) use a command line PDF creation tool to convert each one to a PDF, using a batch file.

8009.

Solve : Log file with "comments"?

Answer»

Hey guys.

I need some help with a batch file, i want to make a log file for "errors" with time, date AND comment.

so that when i open my batch file it ask me to write something and whatever i write it copys into my log file underneath my time and date. i tried this but it obviesly didnt work :/ help plz.

@ECHO OFF
if exist error.txt (
set /p skriv= Error to repport?:
@echo %time% %date% &GT;> error.txt
@echo %skriv% >> error.txt
) else (
set "." > error.txt
)
@echo succes
pause>nul Just a little TIDYING. If your error comment contains & < > | etc characters then use echo "%skriv%" with double quotes.


Code: [Select]@ECHO OFF
set "skriv="
if NOT exist error.txt (
set /p "skriv=Error to report?: "
>> error.txt echo %date% @ %time%
>> error.txt echo %skriv%
) else (
echo success
)
pause>nul

This will only run once, but you haven't really explained how you want it to function.It didnt work the text file only had time date and "echo off"

I want it to work like a log off errors, like i work maintainance on machines, when i´ve fixed a machine i want to be able to open the batch, write what error i had and when i press enter on the batch, it adds what i wrote into my log file together with time and date.

so that at any given time i can open my log.txt or (error.txt) and SEE all the errors and time + date of that error.

understand? If you want to append to a file then use this: The last version needed delayedexpansion to echo within the loop.

Code: [Select]@ECHO OFF
set "skriv="
set /p "skriv=Error to report?: "
>> error.txt echo %date% @ %time%
>> error.txt echo "%skriv%"
thank you so much, how come i have to set "skriv=" then set /p "skriv="?Quote from: Mekawy on April 17, 2013, 05:28:20 AM

how come i have to set "skriv=" then set /p "skriv="?

It's error checking. %skriv% can be set in the same command session and WOULD then give an incorrect comment if enter alone was pressed without typing a comment.

This way it is initialised as an empty string and will only echo what is typed.
8010.

Solve : Batch file using NET LOCALGROUP?

Answer»

I am trying to find out which users are assigned to a GROUP and from that move some files to a various folders.

Finding whether a user is part of a group is easy enough using

NET LOCALGROUP "GROUPNAME" | find /I /C "%username%"

It returns 1 if the user is part of the group and 0 if they are not. The problem is then further PROCESSING. I want to use the value 1 returned from above command. However setting a VARIABLE to the above line does not work and using %ERRORLEVEL% brings back 0 EVEN if the user is in the group which is not surprising as no error has occurred.

Any ideas to returning the value from NET LOCALGROUP "GROUPNAME" | find /I /C "%username%" and putting it into a variable. Which I then can use to process a few IF statements

sorry for posting this, usually I would struggle through but deadlines loom plus I am NEW to batch files.The standard way of running a command and parsing (processing) the output is provided by the FOR command with the /F switch. For documentation see many web sources or type FOR .? at the prompt. Example:

for /f %%A in ('net "GROUPNAME" ^| find /I /C "%username%"') do set value=%%A

Note: When executing a command in a FOR dataset, and parsing the output, if we wish to use a pipe, e.g. to FIND, a caret before the pipe symbol is necessary. It is an "escape character".

Or you can use the errorlevel.

NET LOCALGROUP "GROUPNAME" | find /I "%username%" >nul
If not errorlevel 1 (
echo found "%username%"
echo more commands here
)

A problem with that method is that a user called 'Juliet' will also match a user called "Julie"

8011.

Solve : ECHO File Problem?

Answer»

IT Person upgraded my PC, so he copy the data from my old hard disk (drive D) and install it in new hard.
But when he copied my locker file and i enter the password, i found that the file is empty and i don't have another copy from those data
The locker file was ECHO batch with the following command, so please help as unfortunately the IT formated the old hard disk also

cls
*ECHO OFF
title Folder Private
if EXIST "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" goto UNLOCK
if NOT EXIST Private goto MDLOCKER
:CONFIRM
echo Are you sure you want to lock the folder(Y/N)
set/p "cho=>"
if %cho%==Y goto LOCK
if %cho%==y goto LOCK
if %cho%==n goto END
if %cho%==N goto END
echo Invalid choice.
goto CONFIRM
:LOCK
ren Private "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
attrib +h +s "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
echo Folder locked
goto End
:UNLOCK
echo Enter password to unlock folder
set/p "pass=>"
if NOT %pass%== password here goto FAIL
attrib -h -s "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
ren "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" Private
echo Folder Unlocked successfully
goto End
:FAIL
echo Invalid password
goto end
:MDLOCKER
md Private
echo Private created successfully
goto End
:EndDo you mean to say that there was a hidden folder with data in it that didn't get copied across to the new hard drive?use this program on your old disk EaseUS Data Recovery Wizard 5.8.5 Thanks for feedback, but my old disk is formatted
So if i use EaseUS Data Recovery Wizard 5.8.5 will it back again my hidden locked data file?Generally when a hard drive has been formatted and a new os installed etc, trying to get data off of the old file system is like winning the lottery because new data overwrote the location on the hard drive where the old data resided. Data Recovery wizards are best when a file was just recently accidentally deleted and no new data was written to that space because the file is still there in that space, just with its first character of filename flipped to a ( E5h ) special character. http://www.diydatarecovery.nl/kb_undelete_article.htm

A data recovery service provider may be ABLE to retrieve fragments of what may be left by scanning the platters reading the magnetic signature to try to reassemble the prior data based on a technique that tests the strength of the 0's and 1's amplitude ( Magnetic Strength ).

Whereas:
If its a strong 0, then the prior bit was most likely 0 in the prior file system
If its a weak 0, then the bit may have been a 1 in the prior file system
If its a weak 1, then the bit may have been a 0 in the prior file system
If its a strong 1, then the bit was most likely a 1 in the prior file system

*This technique of reading the bit's signal strength is something that I haven't seen a piece of software perform, and you need a very expensive piece of data recovery equipment to perform.

*This is very similar to those who may remember buying blank cassette tapes and by example recording the radio to snag songs to add to mix tapes in the 1980s. When using a fresh blank 90 minute cassette your audio quality was as perfect as could be for whatever tape deck and quality of cassette you used. Upon the 2nd time recording overtop of the last recording of this music snag tape with new audio, if you have the volume up when LISTENING to this new recording and there is a dead area in the newest recording such as dead air or a pause before a commercial, you may hear the prior recording very faintly. The fact is that this is very faint across the entire tape and is the RESIDUAL magnetic signature of the prior recording. With the right hardware you could recover a good majority of the recording 2nd to last. Hard drives also share this characteristic due to magnetic recording and so with the right equipment to pick up on the signal strengths of each bit read, you can piece together within a pretty good amount of probability what the prior bit's value was 0 or 1. BUT this only works for magnetic media and will not work with SSD's and Flash Devices etc.Quote from: TY on April 17, 2013, 12:51:45 PM

Thanks for feedback, but my old disk is formatted
So if i use EaseUS Data Recovery Wizard 5.8.5 will it back again my hidden locked data file?

SHORT answer is: yes, if the drive hasn't been written to.
If the drive has had data written to it then you will have to try it and see if the file you need can be recovered, without corruption.
8012.

Solve : Batch delete file with one line?

Answer»

Hi Friends,
I have many FILES in directory. Each file have different line. (some file have 1 line some file have more lines)
I want to have batch file to delete file that have only 1 line.

Thank youThis should echo the del command with the files of only 1 line. Remove the echo if it WORKS ok.

Code: [Select]@echo off
for %%a in (*.*) do (
for /f %%b in ('find /C /v "" ^<"%%a" ') do if %%b EQU 1 echo del "%%a"
)
Thanks for your script foxidrive

You are a suppermanHe has BREAKFAST once in awhile as WELL...And I like soup, so I guess you could say that that makes me a souperman.

8013.

Solve : Changing a Bat script with a bat script??

Answer»

Hey all, i have a PRETTY basic batch file scripting question.

i have a bat file and i need to remove a part of it, preferebly automatically with another bat file. here is the before and after i would like (this is just the one line i need edited from a batch file, not the whole batch)

entry in file1.bat:

net use \\uncpathtoserver /user:[emailprotected] *

desired outcome after RUNNING batch file:

net use \\uncpathtoserver /user:example *

Basically i am trying to remove the @domain.com part. I have been USING an older version of samba that let me use full email address for my username, and the newer versions of samba dont like it, so i need to change that in a number of user's scripts. We are not on an active directory system, which is why i have the scripts in the first place.

thanks in advance for the help.Why not just copy all the scripts to another directory, then edit all of those.
Yes, you could automate the process, but why?
If a string has exactly one @ character, you could remove it by splitting the string into tokens using @ as the delimiter.

This is before.bat

@echo off
REM Comment 1
net use \\uncpathtoserver1 /user:[emailprotected] *
REM Comment 2
net use \\uncpathtoserver2 /user:[emailprotected] *
REM Comment 3
net use \\uncpathtoserver3 /user:[emailprotected] *
REM Comment 4
net use \\uncpathtoserver4 /user:[emailprotected] *

This script I call transform.bat. It assumes

(1) The script to be transformed has @echo off as the first line. That line will be skipped and a new one output at the start of processing.
(2) Only lines STARTING "net use" will have @ symbols

@echo off
echo @echo off
for /f "skip=1 usebackq tokens=1* [emailprotected]" %%A in ("%1") do echo %%A | find /i "net use">nul && (echo %%A *) || (echo %%A)

usage:

transform.bat "before.bat" > "after.bat"

after.bat

@echo off
REM Comment 1
net use \\uncpathtoserver1 /user:user1 *
REM Comment 2
net use \\uncpathtoserver2 /user:user2 *
REM Comment 3
net use \\uncpathtoserver3 /user:user3 *
REM Comment 4
net use \\uncpathtoserver4 /user:user4 *




Salmon, Worked Like a Charm!

Thanks a tonok, maybe not like a charm. I noticed a few issues with the output. maybe if i put the whole script it will be easier to see

orig script:

@echo off
color b0
title Map Network Drives Script
net use * /delete
rem Map network drives
cls
echo Please enter your E-MAIL password
net use \\uncpathtoserver /user:[emailprotected] *
net use T: \\uncpathtoserver\share1 /persistent:yes
net use U: \\uncpathtoserver\share2 /persistent:yes
net use n: \\uncpathtoserver\share3 /persistent:yes
rem Show drives
cls
net use
pause
Press any key to continue . . . .

When i run the script i get the FOLLOWING:

@echo off
color b0
title Map Network Drives Script
net use * /delete *
rem Map network drives
cls
echo Please enter your E-MAIL password
net use \\uncpathtoserver /user:username *
net use T: \\uncpathtoserver\share1 /persistent:yes *
net use U: \\uncpathtoserver\share2 /persistent:yes *
net use n: \\uncpathtoserver\share3 /persistent:yes *
rem Show drives
cls
net use *
pause
Press any key to continue . . . .


When what i need to be getting is:

@echo off
color b0
title Map Network Drives Script
net use * /delete
rem Map network drives
cls
echo Please enter your E-MAIL password
net use \\uncpathtoserver /user:username *
net use T: \\uncpathtoserver\share1 /persistent:yes
net use U: \\uncpathtoserver\share2 /persistent:yes
net use n: \\uncpathtoserver\share3 /persistent:yes
rem Show drives
cls
net use
pause
Press any key to continue . . . .

Notice the extra *,s and spaces?Try this

@echo off
echo @echo off
for /f "skip=1 usebackq tokens=1* [emailprotected]" %%A in ("%1") do echo %%A | find /i "net use \\">nul && (echo %%A *) || (echo %%A)

Result

@echo off
color b0
title Map Network Drives Script
net use * /delete
rem Map network drives
cls
echo Please enter your E-MAIL password
net use \\uncpathtoserver /user:username *
net use T: \\uncpathtoserver\share1 /persistent:yes
net use U: \\uncpathtoserver\share2 /persistent:yes
net use n: \\uncpathtoserver\share3 /persistent:yes
rem Show drives
cls
net use
pause
Press any key to continue . . . .



Success!

Thanks a ton

8014.

Solve : checking if window is minimized?

Answer»

batch newbie power yeahhhhhh

i was wondering if it was possible to check if a window is minimized and run commands accordingly.

for example:

Code: [Select]@echo off
if (CODE OR SOMETHING WOULD GO HERE) (
echo yeah this is minimized
exit
)
i am aware that was an awful batch file example

so anyway, is it possible to check such a thing? maybe through vbscript? because i know %errorlevel% cant solve everything CHECKING windows states requires access to the Windows API and this is not directly available from a batch script or the command line. It is possible using a programming language such as C or Visual Basic; the API function you want is called GetWindowPlacement.

It isn't clear which window you are talking about: do you mean the batch script window itself, or some other window?

Perhaps it might be helpful if you told US what you are trying to do.
If I need to find this sort of stuff out from the command line or in a batch I have used a FREE utility called CMDOW. Feed it the window handle and you get back a line of text like this:

C:\>cmdow 0x01084C /P
0x01084C 3 5636 Res Ina Ena VIS firefox Security news

If that window was minimized the 4th ITEM, "Res" would be "Min"

http://www.commandline.co.uk/cmdow/
Quote from: Salmon Trout on September 08, 2013, 07:00:01 AM

Perhaps it might be helpful if you told us what you are trying to do.

+1

Newbies should learn early on to include the reasons, so that experienced people can figure out the best way to solve a problem from the multitude of ways available.

Otherwise they get an answer that is about as useful as their question. Sorry for the rant - it just happens so often.oh, yeah, sorry. it is the batch window itself i am trying to hide. i may use visual basic for this, as i have basic knowledge of it.Using cmdow.exe, check if own window is not minimized and if not, minimize it

for /f "skip=1 tokens=1,2,3,4" %%A in ('cmdow @ /P') do if not "%%D"=="Min" cmdow @ /MINQuote from: tehjoffy on September 08, 2013, 11:25:57 AM
it is the batch window itself i am trying to hide.

Why?
8015.

Solve : MASSIVE SIZE CHANGE!?

Answer»

I hav Attached An Example Showing Wats My Problem

I Wanna understand After Running That Batch File In attachments

The WAV file after injecting SIZE changes from 32 kb into more than 100 mb

WHY DOES THIS HAPPEN

The File SchemaMetafile_DVD1.csc is just a renamed zip file!HERES The example

FORGOT 2 Post it wid problem


[Saving space, attachment deleted by admin]Quote from: the_mad_joker on January 22, 2010, 06:06:21 AM

WHY DOES THIS HAPPEN

You did something wrong.

Oh by the way

Quote
if sumbody helped me sorting this mess,, i wud b the best ripper

Quote
IM [PAiN] The Master RiPpEr...

Quote
this is most Important Query of ma lyf




8016.

Solve : Remove Text From File Name?

Answer»

I'm stumped on how to strip text from a file name and am hoping someone can help me here.

I need to be able to remove "_face01" (minus the quotation marks) from multiple files in a folder. The batch script can't kept in the DIRECTORY with the files, it will need to reference it. I've EXPERIMENTED with a few For loops and am not getting far.

This was my last effort:

@echo off
setlocal enabledelayedexpansion
set deletestring=_face01
for /f "delims==" %%F in (' "\\folder-path" " *.bmp ^| find "%deletestring%"' ) do (
set oldfilename=%%F
set newfilename=!oldfilename:%deletestring%=!
Ren "!oldfilename!" "!newfilename!"
)

I was honestly hoping for something simpler:

for /f "tokens=*" %%F in ( '"path-to-folder" *.bmp' ) do ren "%%F" "%%F:~0,-11%"

Neither of these seem to work.

Thanks!

MJ
I tried to do this a while back for some files and just bought Better File Rename INSTEAD which can CLIP to remove unwanted text from file names, or rename in whatever way you chose just about. http://www.publicspace.net/windows/BetterFileRename/This seems to work as long as the first letter of the file isn't '1'. Still working on this, so don't run it on your files quite yet.

Code: [Select]:: !a! = full file name
:: !b! = extension
:: %%G = Before _file01
@echo off
setlocal EnableDelayedExpansion


for /f "delims=" %%A in ('dir /b ^| findstr "_face"') do (
set a=
set b=
set a=%%A
for /f "tokens=2 delims=." %%B in ("%%A") do (
set b=%%B
)
for /f "tokens=1 delims=_file" %%G in ("%%A") do (
rename "!a!" %%G.!b!
echo %%A %%G.!b!
)
)
pause

commented out rename command so it will only list files, and what it would rename them.

(practiced on .txt files)

EDIT: FIXED the file, seems to work quite well.
Keep in mind that this clips everything after the "_face". Oh, and you can't have a period (.) anywhere in any of the filenames, or they will be messed up.
before:
Code: [Select]04/17/2013 07:39 PM 6 10_face01.txt
04/17/2013 07:39 PM 6 11_face01.txt
04/17/2013 07:39 PM 6 12_face01.txt
04/17/2013 07:39 PM 6 13_face01.txt
04/17/2013 07:39 PM 6 14_face01.txt
04/17/2013 07:39 PM 6 15_face01.txt
04/17/2013 07:39 PM 6 16_face01.txt
04/17/2013 07:39 PM 6 17_face01.txt
04/17/2013 07:39 PM 6 18_face01.txt
04/17/2013 07:39 PM 6 19_face01.txt
04/17/2013 07:39 PM 6 1_face01.txt
04/17/2013 07:39 PM 6 20_face01.txt
04/17/2013 07:39 PM 6 21_face01.txt
04/17/2013 07:39 PM 6 22_face01.txt
04/17/2013 07:39 PM 6 23_face01.txt
04/17/2013 07:39 PM 6 24_face01.txt
04/17/2013 07:39 PM 6 25_face01.txt
04/17/2013 07:39 PM 6 26_face01.txt
04/17/2013 07:39 PM 6 27_face01.txt
04/17/2013 07:39 PM 6 28_face01.txt
04/17/2013 07:39 PM 6 29_face01.txt
04/17/2013 07:39 PM 6 2_face01.txt
04/17/2013 07:39 PM 6 30_face01.txt
04/17/2013 07:39 PM 6 31_face01.txt
04/17/2013 07:39 PM 6 32_face01.txt
04/17/2013 07:39 PM 6 33_face01.txt
04/17/2013 07:39 PM 6 34_face01.txt
04/17/2013 07:39 PM 6 35_face01.txt
04/17/2013 07:39 PM 6 36_face01.txt
04/17/2013 07:39 PM 6 37_face01.txt
04/17/2013 07:39 PM 6 38_face01.txt
04/17/2013 07:39 PM 6 39_face01.txt
04/17/2013 07:39 PM 6 3_face01.txt
04/17/2013 07:39 PM 6 40_face01.txt
04/17/2013 07:39 PM 6 4_face01.txt
04/17/2013 07:39 PM 6 5_face01.txt
04/17/2013 07:39 PM 6 6_face01.txt
04/17/2013 07:39 PM 6 7_face01.txt
04/17/2013 07:39 PM 6 8_face01.txt
04/17/2013 07:39 PM 6 9_face01.txt
04/17/2013 07:37 PM 384 renam.bat
41 File(s) 624 bytes
2 Dir(s) 259,738,959,872 bytes free

after:
Code: [Select]04/17/2013 07:39 PM 6 1.txt
04/17/2013 07:39 PM 6 10.txt
04/17/2013 07:39 PM 6 11.txt
04/17/2013 07:39 PM 6 12.txt
04/17/2013 07:39 PM 6 13.txt
04/17/2013 07:39 PM 6 14.txt
04/17/2013 07:39 PM 6 15.txt
04/17/2013 07:39 PM 6 16.txt
04/17/2013 07:39 PM 6 17.txt
04/17/2013 07:39 PM 6 18.txt
04/17/2013 07:39 PM 6 19.txt
04/17/2013 07:39 PM 6 2.txt
04/17/2013 07:39 PM 6 20.txt
04/17/2013 07:39 PM 6 21.txt
04/17/2013 07:39 PM 6 22.txt
04/17/2013 07:39 PM 6 23.txt
04/17/2013 07:39 PM 6 24.txt
04/17/2013 07:39 PM 6 25.txt
04/17/2013 07:39 PM 6 26.txt
04/17/2013 07:39 PM 6 27.txt
04/17/2013 07:39 PM 6 28.txt
04/17/2013 07:39 PM 6 29.txt
04/17/2013 07:39 PM 6 3.txt
04/17/2013 07:39 PM 6 30.txt
04/17/2013 07:39 PM 6 31.txt
04/17/2013 07:39 PM 6 32.txt
04/17/2013 07:39 PM 6 33.txt
04/17/2013 07:39 PM 6 34.txt
04/17/2013 07:39 PM 6 35.txt
04/17/2013 07:39 PM 6 36.txt
04/17/2013 07:39 PM 6 37.txt
04/17/2013 07:39 PM 6 38.txt
04/17/2013 07:39 PM 6 39.txt
04/17/2013 07:39 PM 6 4.txt
04/17/2013 07:39 PM 6 40.txt
04/17/2013 07:39 PM 6 5.txt
04/17/2013 07:39 PM 6 6.txt
04/17/2013 07:39 PM 6 7.txt
04/17/2013 07:39 PM 6 8.txt
04/17/2013 07:39 PM 6 9.txt
04/17/2013 07:37 PM 384 renam.bat
41 File(s) 624 bytes
2 Dir(s) 259,738,959,872 bytes free

This should work. Replace c:\backup\ with your folder.

Code: [Select]@echo off
pushd "c:\backup\"
for /f "delims=" %%a in ('dir *.* /b /a-d') do call :next "%%a"
popd
goto :EOF
:next
set "name=%~1"
set "name=%name:_face01=%"
ren %1 "%name%"
Thanks guys! I used the code from Foxdrive and it worked like a charm. Much appreciated!

MJ

8017.

Solve : Batch File to access and operate on a remote machine?

Answer»

Hi,

I've made a batch file to access a remote UNIX machine. It works FINE but now I want to use this batch to execute some commands on the unix machine.

Code: [Select]
@ECHO OFF

"C:\Program Files\ZOC5\ZOC.exe" "/CALL:[#1361966675]"


In the above line of the batch file, "zoc.exe" is the program I use to connect to the machine and the "CALL:[#1361966675]" expression it's a ZOC session which I previously created with the information like the IP, user and password to access the machine.

Now I want to type some commands in this machine, how do I do this?

Help please.
I found a guide you can UTILIZE to help you, I believe it's from the developers.

http://www.emtec.com/zoc/zocenglish.pdf

8018.

Solve : Batch parameters containing spaces?

Answer»

I am tearing my HAIR out with this. I have LOOKED at various suggested solutions but I can't get them to work.
I have a simple batch file (D:\Download\BackupList.txt) that contains folder names:
Brain Exerciser
Captures
CpuGproj

I have a batch file that just displays each line of the file. I can't get it to display the first line that contains spaces, it just displays Brain. I have tried using quotation marks and delims but I can't get it to work. I'm sure there's a simple answer but it eludes me. The batch file is:
For /F "tokens=1*" %%g in (D:\Download\BackupList.txt) do call :echoit %%g
goto :exit
:echoit
echo %1
goto :eof
:exit
pause

I would be grateful for any help. tiatokens=%* or tokens=%~1 perhaps?Quote from: CHman on January 22, 2010, 09:15:22 AM

Brain Exerciser
Captures
CpuGproj

The batch file is:
For /F "tokens=1*" %%g in (D:\Download\BackupList.txt) do call :echoit %%g
goto :exit
:echoit
echo %1
goto :eof
:exit

echo "%1"

Thanks for the replies.

Quote from: Treval on January 22, 2010, 10:14:36 AM
tokens=%* or tokens=%~1 perhaps?
The FOR finishes immediately when these are used.

Quote from: BillRichardson on January 22, 2010, 10:30:59 AM
echo "%1"
This just PUTS quotes round the Brain

The full string Brain Exerciser is not being passed to the echoit routine.Quote from: CHman on January 22, 2010, 09:15:22 AM
I'm sure there's a simple answer but it eludes me.

I am confused. Why don't you just do this? (below) Is there some reason you want to a simple thing in a complex way?

for /f "delims=" %%g in (D:\Download\BackupList.txt) do echo %%g

1. Textlines.txt

Code: [Select]I am tearing my hair out with this. I have looked at various suggested solutions but I can't get them to work.
I have a simple batch file (D:\Download\BackupList.txt) that contains folder names:

2. Showlines.bat

Code: [Select]@echo off
for /f "delims=" %%A in (textlines.txt) do echo %%A
3. Output:
Code: [Select]D:\Test\Batch>showlines.bat
I am tearing my hair out with this. I have looked at various suggested solutions but I can't get them to work.
I have a simple batch file (D:\Download\BackupList.txt) that contains folder names:

Quote from: CHman on January 22, 2010, 11:32:55 AM

The full string Brain Exerciser is not being passed to the echoit routine.


C:\batch>type chman.bat
Code: [Select]rem Brain Exerciser
rem Captures
rem CpuGproj
@echo off
For /F "delims=" %%g in (E:\Download\BackupList.txt) do echo %%g

pause
For /F "delims=" %%g in (E:\Download\BackupList.txt) do call :echoit "%%g"
goto :exit
goto :exit
:echoit
echo %1
goto :eof
:exit

Output:

C:\batch> chman.bat

C:\batch>rem Brain Exerciser

C:\batch>rem Captures

C:\batch>rem CpuGproj
Brain Exerciser
Captures
CpuGproj
Press any key to continue . . .
"Brain Exerciser"
"Captures"
"CpuGproj"
C:\batch>Brilliant. Thanks Salmon Trout and BillRichardson, I think you've cracked it.
It's the "delims=" that seems to do the trick.The DEFAULT delimiters are spaces. You can change the delimiters to any other character e.g. "delims=," makes the delimiter a comma, and "delims=" makes the delimiters the start and end of the line.
Quote from: CHman on January 22, 2010, 09:15:22 AM
For /F "tokens=1*" %%g in (D:\Download\BackupList.txt) do call :echoit %%g
goto :exit
:echoit
echo %1
goto :eof
:exit

The use of tokens and a call to a LABEL will work.
At least two tokens must be used. The delims between tokens is a space. When the first token is named %%g, the second token may be named %%h


Code: [Select]@echo off
For /F "delims=" %%g in (E:\Download\BackupList.txt) do echo %%g

pause

For /F "tokens=1,2 delims= " %%g in (E:\Download\BackupList.txt)do call:echoit %%g %%h

goto :exit
goto :exit
:echoit
echo %1 %2
goto :eof
:exit
RUN

C:\batch> chman2.bat
Brain Exerciser
Captures
CpuGproj
Press any key to continue . . .
Brain Exerciser
Captures
CpuGproj
C:\batch>
8019.

Solve : edit file options?

Answer»

Hi folks,

I'll be grateful for any suggestions as it appears that there are no built in OPTIONS in Windows that I can use. I wish to copy file_1, from the first line CONTAINING a particular string (which can vary from run to run), to file_2, using only batch file command line input.

e.g. 1 transcribe file_1 file_2
----
PC/STRING/ (position to first line containing STRING)
TE (transcribe to end of file)
E (end transcription)
++++

e.g. 2 transcribe file_1 file_2 file_3 (where file_3 contains commands equivalent to those between ---- and ++++ above)

I have no problems with installing additional software so LONG as it works.

Many thanks,

John

P.S. Those familiar with ICL George, TME or VME will immediately recognise the above.
Quote from: JohnHag on April 24, 2013, 08:32:22 PM

Hi folks,

I'll be grateful for any suggestions as it appears that there are no built in options in Windows that I can use.
What you say SOUNDS like an old thread on another forum.
http://stackoverflow.com/questions/3644238/split-text-file-in-two-using-bash-script

You can use either AWK or SED for windows. Microsoft has not offered any Windows versions of these because the versions available for windows work fine.

OR
Use the Power Shell work-alike:
http://windows-powershell-scripts.blogspot.com/2009/06/awk-equivalent-in-windows-powershell.html

That should be enough to get you going.
8020.

Solve : Networking Batch File?

Answer»

Dear All,

Need to make a batch file by giving a ping command to a particular IP, and if the link is down it should give an pop up to an .exe file, i have already made an .exe file with the VB6.0,

So kindly if any one can help me on this...

Regards,
Saravanantry:
Code: [Select]set connect=<ip>
ping %connect% -n 1 1>nul 2>&1
if %errorlevel% GTR 0 (
start <exe>
) else (
echo Successfully connected to %connect%
)
pause >nul

replace with the ip you wish to check and with a path to your .exe you with top RUN on failure.Hi, Lemonilla,
Great
Thanks for the help....
but in this below program, i want to add a loop so that when link goes down suddenly it should directly pop up the .exe file
so that we will be aware of that
so can u pls help me out in this.



@echo off

set connect= 74.125.236.115
ping %connect% -n 1 1>nul 2>&1
if %errorlevel% GTR 0 (
start /d "F:\Link Files" et.exe
) else (
echo Successfully connected to 74.125.236.115
ping www.google.com -t
)
pause >nulHI..

Compare to the above given program i have made a small changes here

@echo off
:loop
set connect= 74.125.236.115
ping %connect% -n 1 1>nul 2>&1
if %errorlevel% GTR 0 (
start /d "F:\Link Files" et.exe
)else (
echo Successfully connected to 74.125.236.115
ping www.google.com -w 4
)
Goto loop
pause >nul


But in this program WHENEVER i disconnect my internet connection he keeps poping up the .exe file until the internet connection comes,
so is there any way that only 1 time i have to get the pop up of .exe file
Please help

Regards,
Saravanan
This is untested: The random number just lets you know that the batch is still running.

Code: [Select]@echo off
set connect=74.125.236.115
:loop
echo %random%
ping %connect% -n 2 >nul
if not errorlevel 1 (
echo Successfully connected to %connect%
ping localhost -n 10 >nul
Goto loop
) else (
start "" "F:\Link Files\vb6exe.exe"
)
Hmm,,,

Not working... any other suggestion for the below :

@echo off

set connect= 74.125.236.115
ping %connect% -n 1 1>nul 2>&1
if %errorlevel% GTR 0 (
start /d "F:\Link Files" et.exe
) else (
echo Successfully connected to 74.125.236.115
ping www.google.com -t
)
pause >nul


Need to edit in this program itself...


Quote from: sarava_1986 on April 18, 2013, 01:29:02 AM

Hmm,,,

Not working...

I tested my last contribution and it works fine. What do you see on the screen?Quote from: foxidrive on April 18, 2013, 03:46:01 AM
I tested my last contribution and it works fine. What do you see on the screen?
From what I can see, the code the OP posted is not your most recent contribution, but is just the code from lemonilla with the loop removed. Maybe the OP wants to run the EXE file when the connection is down, and then continue to test for a connection, but only run the EXE once.

That is complicated by the fact that the connection could flutter and go up and down rapidly. We'd need to know how he wants to handle that.Hi All,

Below is my Query to make a batch file :

1. My ping to Google.com should continuously be on so that i can see the reply from the site
2. As my link goes down (Request time out) it should give me an pop of an .exe file (which i have made) only once, and it should continuously check the connection when it comes up.

Regards,
Saravanan My ping isn't working in general, try this out, and see if it works (or if it's close to what you want.)
Code: [Select]@echo off
set a=0
:loop
ping www.google.com -n 1 >nul 2>&1
if "%errorlevel%"=="0" set a=0
if "%errorlevel%"=="1" if "%a%"=="0" call :loss
goto loop

:loss
start FILE.exe
set a=1
goto :eof
Hi Lemonilla,

the command which u gave me last one, when ever i used to run it, it just shows blank cmd screen.


Please help me on the below command :
*******************************************************************************
@echo off
:PING
ECHO Checking connection, please wait...
PING -n 1 www.google.com|find "Reply from " >NUL
IF NOT ERRORLEVEL 1 goto :SUCCESS
IF ERRORLEVEL 1 goto :TRYAGAIN
:TRYAGAIN
ECHO -------------------------------------------------------
ECHO -------------------------------------------------------
ECHO FAILURE!
ECHO Let me try a BIT more, please wait...
@echo off
start /d "c:\Ping files\Link Files" et.exe
PING -n 3 www.google.com|find "Reply from " >NUL
IF NOT ERRORLEVEL 1 goto :SUCCESS
IF ERRORLEVEL 1 goto :FAILURE
:SUCCESS
ECHO -------------------------------------------------------
ECHO -------------------------------------------------------
ECHO You have an active Internet connection
ping www.google.com -w 4
goto PING
:FAILURE
ECHO -------------------------------------------------------
ECHO -------------------------------------------------------
ECHO Kindly Check the connection.........!
ECHO -------------------------------------------------------
ECHO -------------------------------------------------------
goto PING
sleep 20
:END
*******************************************************************************

When i run the above batch file
I get:
"Please see the screen shot 1.jpg as attached"

and when i disconnect my network cable
I get:
"Please see the screen shot of 2.jpg as attached"

So in this i just want that it should display only once the error "ET link is down" when the link goes down.
and it should keep checking the link status....

So can you please modify on the above program and resend at the earliest.

Hope you got my needs

Thanks,

Regards,
Saravanan

[recovering disk space, attachment deleted by admin]try:
Code: [Select]@echo off
set a=0

:PING
ECHO Checking connection, please wait...
PING -n 1 www.google.com|find "Reply from " >NUL
IF NOT ERRORLEVEL 1 goto :SUCCESS
IF ERRORLEVEL 1 goto :TRYAGAIN

:TRYAGAIN
ECHO -------------------------------------------------------
ECHO -------------------------------------------------------
ECHO FAILURE!
ECHO Let me try a bit more, please wait...
@echo off
if "%a%"=="1" start /d "c:\Ping files\Link Files" et.exe
PING -n 3 www.google.com|find "Reply from " >NUL
IF NOT ERRORLEVEL 1 goto :SUCCESS
IF ERRORLEVEL 1 goto :FAILURE

:SUCCESS
set a=1
ECHO -------------------------------------------------------
ECHO -------------------------------------------------------
ECHO You have an active Internet connection
ping www.google.com -w 4
goto PING

:FAILURE
set a=0
ECHO -------------------------------------------------------
ECHO -------------------------------------------------------
ECHO Kindly Check the connection.........!
ECHO -------------------------------------------------------
ECHO -------------------------------------------------------
goto PING

%a% holds the value of the last ping (success/failure). When it checks to run your exe, it checks to see if the last ping was a failure, and then does not run.

About the blank screen, I did that purpusfuly, as I figured it would run in the background and would be annoying with lots of flashing text. Here is some with text:
Code: [Select]@echo off
set a=1

:loop
ping www.google.com -n 1 >nul 2>&1
if "%errorlevel%"=="0" (
if "%a%"=="1" cls
if "%a%"=="1" echo Connected
set a=0
)
if "%errorlevel%"=="1" if "%a%"=="0" call :loss
goto loop

:loss
cls
echo Connection Error.
echo Reconnecting. . .
start /d "c:\Ping files\Link Files" et.exe
set a=1
goto :eof
It should write only "Connected" while connected, and write "Connection Error. Reconnecting. . . " while not. You will have to test it to check though. Also changed 'start FILE.exe' to 'start /d "c:\Ping files\Link Files" et.exe' from your code.[/code]alt + printscreen for screen shots!Hi Lemonilla,

Awesome...... it has started working, thanks a lot, it was a excellent help by you...

One last thing in the last program you have edited and send to me... in that when the .exe file runs can that .exe file is it possible to display on the other computer which is in the network.

Regards,
Saravanan. U
8021.

Solve : renumbering files using .BAT?

Answer»

Hi All,
I am having trouble trying to figure out if its is possible to change a sequence of numbered frames using a batch file. I can move and rename OK, but what I need is to move a SERIES of sequentially numbered files (ex: Az_361.tif - Az_720.tif) to a NEW folder and renumber not rename (ex: they are now Az_001.tif - 360.tif).

I have software for this, but it involves selecting the files and specifying the new sequence over and over. I typically need to do 200 of these move and renumber sets at a time.

While I am not exacly a beginner, I haven't spent a LOT of time in DOS recently Any help is appreciated.

TonyQuote from: hamiltony on January 21, 2010, 01:16:56 PM

Move a series of sequentially numbered files (ex: Az_361.tif - Az_720.tif) to a new folder and renumber not rename (ex: they are now Az_001.tif - 360.tif).

The old numbers are part of the file name:AZ_361.tif.
And the new numbers are part of the file name.

You are renaming the files. Copy the files, rename the files with new numbers as part of the name. If all works well, del the ORIGINAL files.

A batch file with a for loop and number generator will do the job.Code: [Select]@echo off

REM ren may misfire with long file names.
REM Use dir /x for short name list
REM C:\>dir /?
rem /X This displays the short names generated for non-8dot3 file
rem names. The format is that of /N with the short name inserted
rem before the long name. If no short name is present, blanks are
rem displayed in its PLACE.


REM Az_361.tif - Az_720.tif) to a new folder and rename
REM (ex: they are now Az_001.tif - 360.tif).

setLocal EnableDelayedExpansion

rem dir /b *.tif > tiffiles.txt

set N=0
for /f "tokens=* delims= " %%a in (tiffiles.txt) do (
set /a N+=1
set var=%%a

ren !var! AZ00!N!.tif
)
dir /b AZ*
dir /b *.tif
Output:

C:\batch> numfiles.bat
.
.
.

AZ004.tif
AZ005.tif
AZ006.tif
AZ007.tif
.
.
.

C:\batch>ren might work better with a shorter name

Instead of:

ren !var! AZ00!N!.tif

use:

ren !var! AZ!N!.tif

Thanks Bill,
This is a big help. I figured out how to generate a batch move list with using C++, but this is what I was trying to do in the first place.

Tony
8022.

Solve : Trying to find ip of printer connected to network?

Answer»

I did arp -a to GET all ips on network,

i then done net view which shows all ips with there computer names.

but it doesnt show printers, etc.

i am tring to add a network printer and i want the ip address to connect.

there is no screen on my printer and there is no ip address marked on the test PAGE or in the properties page for the printer.Are you sure it is a network printer?WELL it has a ethernet port.

im trying to intall it on the server.

but there are other network printers on the server already that dont shop up with the dos COMMANDS that i stated.You may need to RDP into the server and run arp -a again from there. also MAYBE your network driver hasnt been installed for the printer.

Hope this helpsSorry what do you mean rdp into server.

also the arp -a list about 20 -30 differnet ip's but it doesent show what they are.

net view shows all the computer ip's along with their names. but no device ip's and no device names.

8023.

Solve : Compress file using Windows 7 zip utility?

Answer»

Hello, I am trying to zip a file using the zip utility that comes with windows 7, how can I do this in a batch file? I can not download any third party software and have to use what is included in windows due to admin rights.

As of right now I have it copy, rename and add date then move it to a backup folder but I need to zip it as well.

Thanks!

Code: [Select]@echo off
title BackUp My DATABASE

::========Set the date as day-month-year========::
SET currdate= %date:~-10,2%-%date:~-7,2%-%date:~-4,4%

::========Set where your going to backup folder is located========::
SET backupdir="X:\MyFolderName\Backups"

::========Set your backup command========::
::========http://ss64.com/nt/xcopy.html========::
SET backupcmd=xcopy /s /c /d /e /H /i /r /y

::========Copy and move DB to a folder named Backups and rename the file and add the current date========::
%backupcmd% "X:\MyFolderName\MyFolderName\MyFileName.accdb" "%backupdir%\bak_%currdate%_MyFileName.accdb"

::\\\\\\\\DELETE OLD FILES START////////::
:: Searches for any file(s) older than 300 days (based on the Last Modification Date attribute)
:: in the path %backupdir% and will execute del @file where del == delete, @file is the variable which holds the filename.
:: Source-http://ss64.com/nt/forfiles.html

FORFILES /p %backupdir% /d -300 /c "cmd /c del @file"

::\\\\\\\\\DELETE OLD FILES END/////////::

pauseIt's not exposed through batch, and even using it through VBScript is rather involvedGreetings oxicottin,
What about using makecab.exe to create a cabinet file or must your
resulting file be in the zip format only?

Good luck!And why, exactly, do you not have admin privileges? If this is a work computer, and this is a work task, why can't the boss pony up for WinZip like mine did? Or if the destination folder is NTFS, use the Windows 7 native compact command? Or it's easy enough in Powershell (also native to Windows 7), and therefore, by a hybrid script, from batch.



I don't care if its in zip format as long as I can use zip to extract it. What exactly do I have to do to "makecab.exe to create a cabinet file" and my plant doesnt have a tech at it so were kinda on our own and if I ask it will take forever and if they do come they always screw something up... lol im better off not doing it or doing it myself.

Thanks!oxicottin,
A cabinet file is different than a zipped file thus you can not use
"Zip" to do the EXTRACTION. To extract the contents of a cabinet file
you will need to use expand.exe. Makecab.exe and Expand.exe are
indigenous to Windows.

Using makecab.exe the file(s) will be compression but you will not be
able to right click on the file and extract its contents. A second
'expand' batch file would need to be written. (or use the command prompt)

From a command promt have a looky loo at:
makecab /?
expand /?

Does that help you?yes its not what im looking for. I will have to see if they will let me install zip or something other. Thanks everyone!Here's a VBS script that will zip a file - POSTED today to another forum.

It seems to have a filesize limitation of around 1GB.
The last line to delete the source file is REMed out.

Code: [Select] Option Explicit
Dim FileToZip, Result
Dim oShell
Dim file
Dim oFileSys
Dim winShell
FileToZip = "C:\Program Files\logs\File_2013-04-29.log"
Result = "C:\Program Files\logs\File_2013-04-29.log.zip"
Set oShell = CreateObject("WScript.Shell")
Set oFileSys = CreateObject("Scripting.FileSystemObject")
Set file = oFileSys.CreateTextFile(Result, True)
file.Write "PK" & Chr(5) & Chr(6) & STRING(18, 0)
file.Close
Set file = nothing
set winShell = createObject("shell.application")
winShell.namespace(Result).CopyHere FileToZip
wScript.Sleep(5000)
'oFileSys.DeleteFile FileToZip

8024.

Solve : Refining net view command in batch?

Answer»

I am trying to make a batch FILE that simply outputs the name of every computer on the network. The problem is that "net view" command decides that it needs formatting and labels. I just want the computer names. So I am making a batch to strip out all of the unnecessary labels and stuff. It works well, BUT it says 2==\\ is unexpected at this time when reading the last line. I FIGURE that this is because the last COUPLE of lines in the net view list file are blank, but I don't know how to tell it to skip blank lines. Could someone please help me make this run without errors.

Here is what I have:
Code: [Select]@echo off
setLocal EnableDelayedExpansion
set tmpfile=B:\comps.tmp
echo Getting COMP names. . .
net view &GT; %tmpfile%
echo Checking comps. Please wait. . .
for /F %%i IN (%tmpfile%) do call ::CheckIt %%i
:CheckIt
set line=%1
set line=%line:~0,2%
if not %line%==\\ goto:EOF
echo %1
goto:EOF

Here is what's in the %tmpfile%:
Code: [Select]Server Name Remark

-------------------------------------------------------------------------------
\\SMALLSERVER
\\DELLLAPTOP
\\DRAWERCOMP
The command completed successfully.


To check for an empty variable, add something to the variable you are checking so that if it is empty, there is still something to test, eg
Code: [Select]if not [%line%]==[\\] goto:EOF
If %line% is blank, the test will look like this to the interpreter
Code: [Select]if not []==[\\] goto:EOFwhich is still a valid testAdd a line with GOTO:EOF before the line containing :CheckItCode: [Select]if not "%line%"=="\\" goto:EOF
An empty string in an IF will get you a error message so use quotes or brackets.
Thanks for the help. I used. . .
Quote

GOTO:EOF before the line containing :CheckIt

AND

Quote
use quotes or brackets.

Here is the finished batch file. It can scan computers using net view or with a list of computers stored in comps.lst. The default method is using comps.lst so if you try it you will need to make a comps.lst file. You will also probably have to change the location of the temp file because I have it set to "B:\comps.tmp" for my RAM drive.

Comps.lst should look like this:
Code: [Select]bla bla bla
this is ignored
\\server
more comments
\\seccondserver

Here is the batch:
Code: [Select]@echo off
setLocal EnableDelayedExpansion
set tmpfile=B:\comps.tmp
call ::initnewline
if "%1"=="-?" goto help
if "%1"=="-a" (
echo Using autoscan mode.
net view > %tmpfile%
) else (
echo Using comps.lst mode.
copy /Y comps.lst %tmpfile% >nul
)
echo Getting comp names. . .
echo Type whatson -? for modes.
echo Checking comps. Please wait. . .%NL%
for /F %%i IN (%tmpfile%) do call ::CheckIt %%i
echo %NL%Any key to exit. . .
pause >nul
goto:EOF
:CheckIt
set line=%1
set line=%line:~0,2%
if not "%line%"=="\\" goto:EOF
set line=%1
set line=%line:~2%
ping -n 1 %line% >nul
if errorlevel 1 (
echo %line% is off.
) else (
echo %line% is on.
)
goto:EOF
:initnewline
REM extra empty lines required
set NLM=^


set NL=^^^%NLM%%NLM%^%NLM%%NLM%
goto:EOF
:help
echo Type whatson -a to automatically scan for comps.
echo Type whatson -n or just whatson to use the list
echo of computers in the comps.lst file.
echo Any key to exit. . .
pause >nul
8025.

Solve : Loading and playing old DOS games in MS-DOS?

Answer»

I would like to PLAY some of the early Ultima DOS games in MS-DOS instead of trying to run them through windows. Is that possible on a windows 95 computer?Have you tried it? A Win95 machine should play most dos games.I haven't tried it yet. I was going to get the Ultima 1-8 package which are probably some of the oldest dos games there are. I was reading reviews how they run badly in windows and thought running them in DOS would give them the best shot. It wouldn't hurt to try windows first but I would like to find some info on how to run them from dos since that is what they were made for.Quote from: Amats on April 29, 2013, 09:12:54 AM

I was reading reviews how they run badly in windows

Windows 95/98/ME/W2K/XP/Win7/Win8? Which windows? Why not just give DOSBox a try ? ?
I was going to suggest that - but the spec PC in his SIG shows an old machine - and DOSBOX is very slow on a 3.5 GHz I7 Quad core machine. At least for SkyGlobe it is.

Maybe Virtualbox using MSDOS would give better SPEED than DosBox... (if Virtualbox runs under Win95 - that's not likely)

or an older version of VMware.I may misunderstand but wouldn't you want it to slow down an i7 for older DOS games ? ?Emulators generally have an automated throttle to slow them down to real frame speed - when they are fast emulators.

My point is that running a slow emulator on a 466 MHz machine means it is going to be even slower. I had nowhere near real speed in SkyGlobe on my I7 box.Why not just get an old PC from a thrift shop?Quote from: foxidrive on April 29, 2013, 08:46:22 PM
I had nowhere near real speed in SkyGlobe on my I7 box.
This is off-topic, and I don't know specifically what you use that software for, but you could try a program like Celestia.Thanks for the thought.The Ultima series of games (1-8) came out for the Atari 8 bit 400/800/XL/XE and Commodore 64 systems and I don't know what others it was programmed for and reviews SAY the early ones run very fast but instructions are given for how to make them playable so I think I will just get the 1-8 package and see what it takes to run it. Should be an interesting experience to see the way it used to be.
8026.

Solve : Opening multiple IE in different windows not in one Window as a tabs!?

Answer»

Hi,

Please guide me to write a program on opening multiple IE in different WINDOWS not in ONE Window as a tabs! USING batch file.

Regards,

TalwarQuote from: Talwar on January 19, 2010, 11:16:18 PM


Please guide me to write a program on opening multiple IE in different windows not in one Window as a tabs! using batch file.

The following information might help:

http://support.microsoft.com/kb/281679
or

http://www.tech-recipes.com/rx/1164/internet-explorer-7-open-new-windows-in-tabs-in-ie7/

Tools, Internet Options, Tabs, Settings . . . ( below)

In batch file simply write :
Code: [Select]start iexploreit always open IE as a new window .Start "" iexplore http://www.google.ca
start "" iexplore http://www.hotmail.com

That should work.
8027.

Solve : The Ren Command Glitch??

Answer»

If I create a file LIKE this ...

"my.bla.JPG"

And then use the command ...

"ren *.jpg.bla *.jpg"

The file in the end looks like this ...

"my.jpg.jpg"

What is this? It should be "my.jpg" no? Could it be a DOS glitch??!Wit hthe file names and commands the rename command issues a "The system cannot find the file specified" error.

If you are talking about pure dos, Files follow the 8.3; up to 8 characters for the filename, up to 3 for the extension. A file MAY not have more than one extension in 'pure' DOS environments.Quote from: guideX on April 30, 2013, 11:21:31 PM

If I create a file like this ...

"my.bla.jpg"

And then use the command ...

"ren *.jpg.bla *.jpg"

You are mistaken. Some thing else happened while you were testing.

d:\abc>dir /b
my.bla.jpg

d:\abc>ren *.jpg.bla *.jpg
The system cannot find the file specified.
Quote from: guideX on April 30, 2013, 11:21:31 PM
If I create a file like this ...

"my.bla.jpg"

And then use the command ...

"ren *.jpg.bla *.jpg"

Surely you meant
file like this ...

"my.jpg.bla"

which then matches the filespec for the rename.
This behaviour is not a glitch, the filename is my.jpg, the extension is .bla

to rename it the way you want, simply rename it without an extension, thus

ren *.jpg.bla *.
now the .jpg from the name is PROMOTED to the extension

simples
Whoops! Let me CORRECT my experiment, and give a little more information.. I'm using Windows 7 64bit cmd.


1) Create a file, called m.txt.bla
2) Type ren *.txt.bla *.txt (logically, you should have a file m.txt)
3) You now have a file called m.txt.txt

To me this make little sense, and I'd suggest it's a glitch.
I did encounter it as working when you use ren *.jpg.bla *. however, this also seems like a glitch ... If I did this command, wouldn't I end up with a file called "my."?

Quote from: gpl on May 01, 2013, 05:05:57 AM
Surely you meant
file like this ...

"my.jpg.bla"

which then matches the filespec for the rename.
This behaviour is not a glitch, the filename is my.jpg, the extension is .bla

to rename it the way you want, simply rename it without an extension, thus

ren *.jpg.bla *.
now the .jpg from the name is promoted to the extension

simples
Quote from: guideX on May 01, 2013, 06:38:47 PM
I did encounter it as working when you use ren *.jpg.bla *. however, this also seems like a glitch ... If I did this command, wouldn't I end up with a file called "my."?
no, its not a glitch, the extension follows the last dot - the name of the file is my.jpg, the filetype is bla
8028.

Solve : Trying to figure out how to do this, should be simple, but hit a wall?

Answer»

So I have an old 80GB external hard drive at E:\ that has data some of it redundant scattered like a mess among many directories and I WANT to copy all files on this external hard drive to a single folder at C:\cleanedup\ but the part that I am stumped on is how to get a copy of all files to C:\cleanedup\ with an xcopy /d/y so that I only get the newest file of redundant file copied to C:\cleanedup\ and not have the directory paths reconstructed at c:\cleanedup\

Attempt to try and use just xcopy /d/y will only copy files in the root at which the command is executed, and I need it to fetch the files out of the many directories and subdirectories from within all on E:\ and pass all files to a single folder at C:\cleanedup\ and looking for a solution to make this happen.

example:

E:\data1\somefile1.txt ( date stamp of say 4:30pm 7/27/2006 )
E:\data2\somefile1.txt ( date stamp of say 5:39pm 8/22/2006 )
E:\somefile1.txt ( date stamp of say 7:39pm 9/21/2007 )
E:\somefile2.txt


and it will copy only the newest somefile1.txt and somefile2.txt to C:\cleanedup\I think I may have found a way finally. Reworded google search and found this: http://stackoverflow.com/questions/15209559/copy-all-files-recursively-into-a-single-folder-without-recreating-folders

The person who started this at the site wanted .mp3 files and I am going to try it with wildcard of all *.* files and see if that works.

Code: [Select]e:
for /d %a in (*) do @copy %a\*.* c:\cleanedupGot an interesting error I have never seen before:

Quote

E:\>%a\*.* was unexpected at this time.

E:\>

Any suggestions on how to correct this? OS of system I am testing this on is Windows XP Home SP3Code from stackoverflow - it's a command line and you need to double all % to execute it in a batch file.

Code: [Select]for /d %a in (*) do @copy %a\*.mp3 e:\myfolder
It won't handle filename collisions.




The easiest way to handle this is to add a counter to each filename, so they are unique names.

filename 0001.ext
apple 0002.ext
apple 0003.ext
banana 0004.ext

etcHello Foxidrive... thanks for your help. I forgot about using the extra % as an escape character.

In regards to appending a number to the end of the files... I was looking into if DIR /S /B /O:d could be used to sort all files by oldest first and newest last so that the order that the batch executes, the newest like file name would overwrite the oldest.

But its not working as intended and not sure why?

Here is the latest one I created:

Code: [Select]for /f "delims==" %%k in ('dir e:\*.* /s /b /o:d') do copy "%%k" f:\test1\
pause
Looking at the /O switch for DIR, it looks as if I should be able to pass the output from DIR to the FOR loop and process oldest first and then newest last as the order in which the DIR output is oldest files first and newest files last, so it should be the same as an xcopy /d switch that overwrites the old same file name with the new same file name. ( But not working out as intended when testing )

Quote
C:\>dir /?
Displays a list of files and subdirectories in a directory.

DIR [drive:][path][filename] [/A[[:]attributes]] [/B] [/C] [/D] [/L] [/N]
[/O[[:]sortorder]] [/P] [/Q] [/R] [/S] [/T[[:]timefield]] [/W] [/X] [/4]

[drive:][path][filename]
Specifies drive, directory, and/or files to list.

/A Displays files with specified attributes.
attributes D Directories R Read-only files
H Hidden files A Files ready for archiving
S System files I Not content indexed files
L Reparse Points - Prefix meaning not
/B Uses bare format (no heading information or summary).
/C Display the thousand separator in file sizes. This is the
default. Use /-C to disable display of separator.
/D Same as wide but files are list sorted by column.
/L Uses lowercase.
/N New long list format where filenames are on the far right.
/O List by files in sorted order.
sortorder N By name (alphabetic) S By size (smallest first)
E By extension (alphabetic) D By date/time (oldest first)
G Group directories first - Prefix to reverse order
Press any key to continue . . .

My test was 3 folders such as folder1, folder2, and folder3 all containing a same test.txt file. In folder2 I have the newest date/time stamp version to test if its executing the process alpha numeric order or by the DIR O/:D method that should place them in an order in which it should be:

folder1\test.txt
folder3\test.txt
folder2\test.txt

so the latest/newest date time stamp file in folder2 should be the last file of like file name to write to the destination, but it seems to still be executing alpha numerically as folder1, folder2, and folder3 since the file written to the destination is the date/time stamp of that of the same date/time stamp that is on the test.txt file in folder3 .... so kind of stumped as to why its not working as I believe it should

The one way i can see this MAYBE malfunctioning is if its looking only at the roots of each folder to sort the files by date/time in which in will process the transfer alpha numerically but oldest to newest in each folder not taking into account the oldest from newest in neighboring folders.

Here is the output showing the process of transfer, which seems alpha numeric still when it shouldnt be with the DIR /O:D I would think.

Quote
Z:\>for /F "delims==" %k in ('dir e:\*.* /s /b /o:d') do copy "%k" f:\test1\

Z:\>copy "e:\folder1" f:\test1\
e:\folder1\test.txt
1 file(s) copied.

Z:\>copy "e:\folder2" f:\test1\
e:\folder2\test.txt
1 file(s) copied.

Z:\>copy "e:\folder3" f:\test1\
e:\folder3\test.txt
1 file(s) copied.

Z:\>copy "e:\test.txt" f:\test1\
1 file(s) copied.

Z:\>copy "e:\folder1\test.txt" f:\test1\
1 file(s) copied.

Z:\>copy "e:\folder2\insidefolder" f:\test1\
e:\folder2\insidefolder\test.txt
1 file(s) copied.

Z:\>copy "e:\folder2\test.txt" f:\test1\
1 file(s) copied.

Z:\>copy "e:\folder2\insidefolder\test.txt" f:\test1\
1 file(s) copied.

Z:\>copy "e:\folder3\test.txt" f:\test1\
1 file(s) copied.

Z:\>pause
Press any key to continue . . .

So the last:

Z:\>copy "e:\folder3\test.txt" f:\test1\
1 file(s) copied.

Is the last file to overwrite the destination when it should be the file located at folder2\insiderfolder\test.txt which has the newest date/time stamp among all like files at E:\>

<<< Update: >>>

Just tested the DIR /O:D and DIR /O:-D inverse and it appears that it only sorts the root directory files and not subdirectories Is there a way to make it look at subdirectory date/time stamps to sort the order oldest to newest?

Quote
E:\>dir
Volume in drive E is NEW VOLUME
Volume Serial Number is 089B-F770

Directory of E:\

09/01/2013 09:03 PM <DIR> folder1
09/01/2013 09:03 PM <DIR> folder2
09/01/2013 09:03 PM <DIR> folder3
09/01/2013 09:04 PM 14 test.txt
1 File(s) 14 bytes
3 Dir(s) 122,673,152 bytes free

E:\>dir /o:d
Volume in drive E is NEW VOLUME
Volume Serial Number is 089B-F770

Directory of E:\

09/01/2013 09:03 PM <DIR> folder1
09/01/2013 09:03 PM <DIR> folder2
09/01/2013 09:03 PM <DIR> folder3
09/01/2013 09:04 PM 14 test.txt
1 File(s) 14 bytes
3 Dir(s) 122,673,152 bytes free

E:\>dir /o:-d
Volume in drive E is NEW VOLUME
Volume Serial Number is 089B-F770

Directory of E:\

09/01/2013 09:04 PM 14 test.txt
09/01/2013 09:03 PM <DIR> folder3
09/01/2013 09:03 PM <DIR> folder2
09/01/2013 09:03 PM <DIR> folder1
1 File(s) 14 bytes
3 Dir(s) 122,673,152 bytes free

E:\>

Excuse me for not following all your text -

DIR will sort in a folder, but not in a folder tree.

You can use this code to get a list of timestamps and filenames.

Code: [Select]@echo off
cd \
del \list.txt 2>nul
for /r %%a in (*) do >>\list.txt echo %%~ta %%a
The resulting list.txt file can be changed to list in yymmdd hhmm format and then sorted to give you a list of oldest to newest file,
but to make this easier it will help to change your msdos date and time format to yyyy/mm/dd and 24 hour time hh:mm
and change it back to what you prefer afterward. Even just changing to 24 hour time will help to rewrite the file in a sortable format.

If you want to use this method (you can use this sorted file to easily copy all the files) then supply a few lines of the list.txt file
and someone can help massage it into a sortable format.

Thanks for your help foxidrive ... going to play around with suggestions and see if I can make it work somehow, but I have some doubts I will be able to get it to work because DOS has been around for many years and google is generally good at coming up with hits with other people that wanted to do something a certain way before yourself, and those who have and have instructions listed that can be placed into batches all dont seem to do the trick. The biggest issue is that DIR only works with the local folder that it is targeting and not with directory trees as you said and I have seen in testing. Have also come across a tool called xxcopy that I am going to check out. Never used it before and the google search for info on doing what I am trying to do has had info suggesting that others have used it for this purpose possibly.

Definately going to play around with the code you supplied though as for with all files in a list.txt in an order from oldest to newest etc, depending on what is written to this file, I could import that list to C++ or Perl and maybe process this list to transfer all files from start to finish to the single folder from oldest files first to newest files last so that only the newest version is located at the destination as for any processed prior of the same file name would be overwritten due to the order of processing the file copying.
Just wanted to follow up with the end result of what I ended up going with to ACHIEVE what I needed. After lots of digging, I found that XXCOPY with the /SGNO switch will copy all files from a source with directory tree all to 1 location collapsing the directory tree and it keeps the newest files of like file names in what it copies. I DOWNLOADED the freeware version and it works flawlessly on my Windows XP Home SP3 Netbook that I tested it on with a flash drive as the source drive with test files in a junk test tree.

Below is the first run of it with test data in a test tree with data hidden in subdirectories.

Quote
C:\>xxcopy f:\*.* c:\crush1\ /SGNO

XXCOPY == Freeware == Ver 3.21.0 (c)1995-2013 Pixelab, Inc.

-------------------------------------------------------------------------------
F:\testfile1.txt 80
F:\testfile2.txt 34
F:\testfile3.txt 34
F:\testfile4.txt 34
F:\1\fff\fffff\testthis\testfile5.txt 34
F:\2\testfile1.txt 80
-------------------------------------------------------------------------------
Directories Processed = 7
Total Data in Bytes = 296
Elapsed time in sec. = 0.078
Action speed (MB/min) = 0.2277
Files Examined = 8
Files Copied = 6
Exit code = 0 (No error, Successful operation)

C:\>

I then tested to see if xxcopy acted like xcopy in that it would update/copy over only the single file that changed, and it did as seen below.

Quote
C:\>xxcopy f:\*.* c:\crush1\ /SGNO

XXCOPY == Freeware == Ver 3.21.0 (c)1995-2013 Pixelab, Inc.

-------------------------------------------------------------------------------
F:\2\testfile1.txt 22
-------------------------------------------------------------------------------
Directories Processed = 7
Total Data in Bytes = 22
Elapsed time in sec. = 0.047
Action speed (MB/min) = 0.02809
Files Examined = 8
Files Copied = 1
Exit code = 0 (No error, Successful operation)


C:\>

So I'm all set and thanks for help. I wanted to post back with what I ended up doing so that anyone else in the future who finds this will save themselves hours of trial and error trying to get it to work.
8029.

Solve : output on second batch?

Answer»

hi all
i need your suggestion

there are 2 batch window open...

i enter text in first batch...and the text out on 2nd batch...

first batch look like
_____________________________________

hellooo

hahhaha

_
_____________________________________

2nd batch i want to look like
_____________________________________

user: hellooo

user: hahhaha
_____________________________________


how can i make text in first batch appear on 2nd batch?

this code i MADE so far...
first batch
Code: [Select]@echo off
mode 20, 4

title taip in
color 02

:loop
set /p message=

goto loop


2nd batch
Code: [Select]@echo off
mode 20, 32
setlocal disableDelayedExpansion
set user=user

set q=^"
echo(
call :c 04 "%user%:"&call :c 0b "%message%" /n

I usually USE a file system type thing.

code I used on another project:
display.bat
Code: [Select]@echo off
title GHX ^| Chat
mode con cols=50 lines=10
cd ..
:loop
copy /Y chat\chat.txt chatb.txt >nul
cls
type chat\chat.txt
:loop2
fc chat\chat.txt chatb.txt >nul
if "%errorlevel%"=="1" goto loop
goto loop2
input.bat
Code: [Select]@echo off
mode con cols=50 lines=1
title GHX ^| Chat
if exist chat.txt del chat.txt
if not exist chat.txt echo Welcome to GHX chat system >>chat.txt
:main
cls
call :clearvar
cscript //nologo write.vbs
if not exist chat.txt (
ping 127.0.0.1 >nul
goto main
)
set /p tosend=<write.txt
del write.txt
if "%tosend%"=="" goto main
echo %computername% ^:^: %tosend%>>chat.txt
if "%tosend%"=="::cls" (
del chat.txt
echo %computername% cleared the screen >>chat.txt
)
call :send
goto main

:clearvar
set tosend=
goto :eof

:send
if "%computername%"=="COMPAQ-3" robocopy "%cd%" "\\gearhead1189\shareddocs\ghx\chat" *.* /s /e >nul
if "%computername%"=="GEARHEAD1189" robocopy "%cd%" "\\compaq-3\shareddocs\ghx\chat" *.* /s /e >nul
goto :eof
write.vbs To remove special characters that could CRASH the program
Code: [Select]dim text
Wscript.Stdout.Write(">")
Wscript.StdIn.Read(0)
text = Wscript.StdIn.Readline()

Set RegEx = New RegExp

RegEx.Global = True
RegEx.IgnoreCase = False
RegEx.Pattern = "[^A-Za-z0-9: ]"

Set colMatches = RegEx.Execute(text)
If colMatches.Count <> 0 Then
WScript.Echo "Special Characters Found"
Else
set fso = CreateObject("Scripting.FileSystemObject")
'-filename
'-2 = writing
'-1 = reading
'-8 = appending
'-true = create if not exist
set fl = fso.OpenTextFile("C:\Documents and Settings\All Users\Documents\ghx\chat\write.txt", 2, True)
fl.Write(text)
fl.Close : Set fl = Nothing
Set fso = Nothing
end if

This might not work quite the way you want it to, but it should be at least something to look at. This was written for 2 Windows XP computers on a network (COMPAQ-3 and GEARHEAD1189)

It is a little easyer to do if you want it to only refresh on enter/chat. You can then condense it to 1 file.

Code: [Select]@echo off
:loop
cls
if exist chat.txt type chat.txt
echo.
set /p tosend=^>
echo %tosend% >>chat.txt
goto loop

For the username thing, you might want to look into 'for /f' to remove it from each line, so the file actually has both usernames, but only displays the one that isn't it's.
Code: [Select]for /f "tokens=1,2 delims=:" %%A in (chat.txt) do (
if "%%A"=="%username%" ( echo %%B
) else (
echo %%A : %%B
)
file:
Code: [Select]Name1:Message
Name1:Message
Name2:Message

Hope this helped at least a bit. Good luck on your project!ty
i learn something from yours code...but not all i can understand...

now i'm able to make text on input.bat display on display.bat
use

Quote

type chat.txt

display.bat

Code: [Select]@echo off
mode 20, 32
setlocal disableDelayedExpansion
set user=user

:loop
echo ---
type chat.txt
echo ---
cls
goto loop

input.bat

Code: [Select]@echo off
mode 20, 4

title taip in
color 02
if exist chat.txt del chat.txt
if not exist chat.txt echo Welcome to chat system >>chat.txt
:loop
set /p message=
echo %user%: %message%>>chat.txt

goto loop


now how can i make content in chat.txt like this

Quote
user=kaka

message1
massage2
massage3

and on display.bat show like this
Quote
kaka: message1
kaka: massage2
kaka: massage3
because its easy i want to make kaka different color
Quote
kaka: message1
kaka: message2
kaka: message3

this code i able made so far
display.bat
Code: [Select]@echo off
mode 20, 32
title start6
start input.bat
setlocal disableDelayedExpansion
set user=kaka

set q=^"
echo(
call :c 02 "%messageV%" /n
call :c 04 "%messagex%" /n
call :c 02 "%downloadV%" /n
call :c 04 "%downloadx%" /n
call :c 02 "%doneV%" /n
call :c 04 "%donex%" /n

:loop
echo ---
type chat.txt
echo ---

ping -n 3 localhost >nul
cls
goto loop


:c
setlocal enableDelayedExpansion
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:colorPrint Color Str [/n]
setlocal
set "s=%~2"
call :colorPrintVar %1 s %3
exit /b

:colorPrintVar Color StrVar [/n]
if not defined DEL call :initColorPrint
setlocal enableDelayedExpansion
pushd .
':
cd \
set "s=!%~2!"
:: The single blank line within the following IN() clause is critical - DO NOT REMOVE
for %%n in (^"^

^") do (
set "s=!s:\=%%~n\%%~n!"
set "s=!s:/=%%~n/%%~n!"
set "s=!s::=%%~n:%%~n!"
)
for /f delims^=^ eol^= %%s in ("!s!") do (
if "!" equ "" setlocal disableDelayedExpansion
if %%s==\ (
findstr /a:%~1 "." "\'" nul
<nul set /p "=%DEL%%DEL%%DEL%"
) else if %%s==/ (
findstr /a:%~1 "." "/.\'" nul
<nul set /p "=%DEL%%DEL%%DEL%%DEL%%DEL%"
) else (
>colorPrint.txt (echo %%s\..\')
findstr /a:%~1 /f:colorPrint.txt "."
<nul set /p "=%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%"
)
)
if /i "%~3"=="/n" echo(
popd
exit /b


:initColorPrint
for /f %%A in ('"prompt $H&for %%B in (1) do rem"') do set "DEL=%%A %%A"
<nul >"%TEMP%\'" set /p "=."
subst ': "%temp%" >nul
exit /b


:cleanupColorPrint
2>nul del "%temp%\'"
2>nul del "%temp%\colorPrint.txt"
>nul subst ': /d
exit /b

input.bat

Code: [Select]@echo off
mode 20, 4
title input
setlocal disableDelayedExpansion
set user=kaka
set messagev=message sent
set "messagex=message fail"
set downloadv=download finished
set downloadx=download failed
set donev=done
set donex=failed

set q=^"
echo(
call :c 02 "%messageV%" /n
call :c 04 "%messagex%" /n
call :c 02 "%downloadV%" /n
call :c 04 "%downloadx%" /n
call :c 02 "%doneV%" /n
call :c 04 "%donex%" /n

:loop
set /p message=
echo %user%: %message%>>chat.txt
call :c 04 "%user%:"&call :c 0b "%message%" /n
goto loop


:c
setlocal enableDelayedExpansion
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:colorPrint Color Str [/n]
setlocal
set "s=%~2"
call :colorPrintVar %1 s %3
exit /b

:colorPrintVar Color StrVar [/n]
if not defined DEL call :initColorPrint
setlocal enableDelayedExpansion
pushd .
':
cd \
set "s=!%~2!"
:: The single blank line within the following IN() clause is critical - DO NOT REMOVE
for %%n in (^"^

^") do (
set "s=!s:\=%%~n\%%~n!"
set "s=!s:/=%%~n/%%~n!"
set "s=!s::=%%~n:%%~n!"
)
for /f delims^=^ eol^= %%s in ("!s!") do (
if "!" equ "" setlocal disableDelayedExpansion
if %%s==\ (
findstr /a:%~1 "." "\'" nul
<nul set /p "=%DEL%%DEL%%DEL%"
) else if %%s==/ (
findstr /a:%~1 "." "/.\'" nul
<nul set /p "=%DEL%%DEL%%DEL%%DEL%%DEL%"
) else (
>colorPrint.txt (echo %%s\..\')
findstr /a:%~1 /f:colorPrint.txt "."
<nul set /p "=%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%"
)
)
if /i "%~3"=="/n" echo(
popd
exit /b


:initColorPrint
for /f %%A in ('"prompt $H&for %%B in (1) do rem"') do set "DEL=%%A %%A"
<nul >"%temp%\'" set /p "=."
subst ': "%temp%" >nul
exit /b


:cleanupColorPrint
2>nul del "%temp%\'"
2>nul del "%temp%\colorPrint.txt"
>nul subst ': /d
exit /b


The only way I know of to make words diffrent colors on batch only works on Windows 7, and I don't quite understand it. Here is the code, It can't do special characters
Code: [Select]@echo off
SETLOCAL EnableDelayedExpansion
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
set "DEL=%%a"
)

echo say the name of the colors, don't read

call :ColorText 0a "blue"
call :ColorText 0C "green"
call :ColorText 0b "red"
echo.
call :ColorText 19 "yellow"
call :ColorText 2F "black"
call :ColorText 4e "white"
pause


goto :eof

:ColorText
echo off
<nul set /p ".=%DEL%" > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1
goto :eof

Try this out (as it's own program) and SEE if it runs. You must include the loop at the top, and the :ColorText at the bottom (after the 'exit').

You will have to use a FOR /F to apply this to chat.txt.Quote
The only way I know of to make words diffrent colors on batch only works on Windows 7, and I don't quite understand it. Here is the code, It can't do special characters

Thanks for sharing this Lemonilla ... Just learned something new.

With batch the color change use to always change all text on the display. And with old Basic the color x,y,z command use to change the entire lines color to whatever the last color call was prior to line return, which was slightly better, but never achieved the multiple colors on a single line until making websites with HTML..LOL

Interesting that microsoft added this ability to command shell/batch.
8030.

Solve : batch file that deletes a file based on date in filename?

Answer»

Hi everyone,
I was able to create a batch file that renames a file to include a date. The format will be:
testfile01152010.txt

I should have a new file every day so I'd like to delete them once they are 90 DAYS old. Can anyone help me with this? I've tried researching this but everything I see is based on date modified or date created which I am trying to avoid using. Thanks in advance!Quote from: tmoe30 on January 20, 2010, 01:56:17 AM

Hi everyone,
I was able to create a batch file that renames a file to include a date. The format will be:
testfile01152010.txt

I should have a new file every day so I'd like to delete them once they are 90 days old. Can anyone help me with this? I've tried researching this but everything I see is based on date modified or date created which I am trying to avoid using. Thanks in advance!

the only other date data files have is "Date last accessed"...I'm not looking to use date modified, accessed or created. I would like to base this off of the date I have in the filename.Do you have ADMIN privileges which allow you to download/install a small utility program?no, i do not have admin privileges.Quote from: tmoe30 on January 20, 2010, 03:12:32 AM
I'm not looking to use date modified, accessed or created. I would like to base this off of the date I have in the filename.

The date created and the date in the file NAME might be the same?

Can you POST the batch file that renamed the date file? That same batch file might be modified to delete the date file?Quote from: tmoe30 on January 20, 2010, 03:12:32 AM
I'm not looking to use date modified, accessed or created. I would like to base this off of the date I have in the filename.

Is the following batch file similar to the batch file that renamed the testfile.txt to testfile01202010.txt



C:\batch>type datename.bat
Code: [Select]@echo off


for /f "tokens=2-4 delims=/- " %%a in ('date /t') do set date2=%%a%%b%%c

echo date2 = %date2%

echo hello > testfile.txt
ren testfile.txt testfile%date2%.txt

dir testfile%date2%.txt

rem AT 14:30 NEXT:90 "del c:\batch\testfile01202010.txt"
rem The above has not been tested
rem * below
rem testfile01152010.txt


Output:


C:\batch>datename.bat
date2 = 01202010
Volume in drive C has no label.
Volume Serial Number is F4A3-D6B3

Directory of C:\batch

01/20/2010 07:45 PM 8 testfile01202010.txt
1 File(s) 8 bytes
0 Dir(s) 303,377,936,384 bytes free
C:\batch>

_______________________________________ ______
http://www.instructables.com/answers/Is-there-a-batch-script-that-you-can-compile-and-/

*
Let the cron, the AT command or the scheduler do the date math.

A better way of doing what you want is to use the built-in scheduler. To get to this, go to Control Panel then Scheduled Tasks. You can run any program you like (including batch files) from there.

You can also set up the scheduler from a batch file, which is closer to what you're after. It can run once, or every hour, week etc. You need to use the AT command, so your set-up batch would be something like :

rem AT 14:30 NEXT:90 "del c:\batch\testfile01202010.txt"
rem The above has not been tested by Bill Richardson

Quote from: tmoe30 on January 20, 2010, 03:12:32 AM
I'm not looking to use date modified, accessed or created. I would like to base this off of the date I have in the filename.

A slight modification from above. How to save 90 days, wakeup and delete?

C:\batch>type datename.bat
Code: [Select]@echo off

for /f "tokens=2-4 delims=/- " %%a in ('date /t') do set date2=%%a%%b%%c

echo date2 = %date2%

echo hello > testfile.txt
ren testfile.txt testfile%date2%.txt

dir testfile%date2%.txt

dir /b testfile%date2%.txt

dir /b testfile%date2%.txt >> save90.txt

rem AT 14:30 NEXT:90 "del c:\batch\testfile01202010.txt"
rem The above has not been tested by Bill Richardson

rem testfile01152010.txt
Output:

C:\batch>datename.bat
date2 = 01202010
Volume in drive C has no label.
Volume Serial Number is F4A3-D6B3

Directory of C:\batch

01/20/2010 08:01 PM 8 testfile01202010.txt
1 File(s) 8 bytes
0 Dir(s) 303,377,649,664 bytes free
testfile01202010.txt
C:\batch>Quote from: tmoe30 on January 20, 2010, 06:06:22 PM
no, i do not have admin privileges.

Okay. Try the script below. There is no provision for paths/filenames containing spaces and the script is not fully tested. Please ensure you have a secure testing environment when you remove the rem from the If/Del command line.

Good luck.

Code: [Select]@echo off
cls
setlocal enabledelayedexpansion

:: With acknowledgement to Dias de verano

:: Compares the current date -90 days with the date in the filename
:: of files named testfilemmddyyyy.txt and deletes the file if it
:: is 90 or 90+ days older than current.

set vb=%temp%\newdate.vbs
(
echo Newdate = (Date(^)-90^)
echo Yyyy = DatePart("YYYY", Newdate^)
echo Mm = DatePart("M" , Newdate^)
echo Dd = DatePart("D" , Newdate^)

echo Wscript.Echo Yyyy^&" "^&Mm^&" "^&Dd
)>>%vb%

FOR /F "tokens=1-3" %%A in ('cscript //nologo %vb%') do (
set Yyyy=%%A
set Mm=%%B
set Dd=%%C
)

set olddate=%Yyyy%%Mm%%Dd%
echo Old date = %olddate%

del %vb%


for /f "delims=." %%1 in ('dir /b testfile*.txt') do (
set filename=%%1
set filedate=!filename:~-8!
set filedate=!filedate:~-4!!filedate:~0,2!!filedate:~2,2!
echo Filename date = !filedate!
rem if !filedate! leq !olddate! del !filename!.txt

)

8031.

Solve : create 13letter combination?

Answer»

hi all...i hope some one will help me fast as possible

i need a batch...which create combination 13 letter a-z

exp-

aaaaaaaaaaaaa
aaaaaaaaaaaab
aaaaaaaaaaaac
....
....
....
yzzzzzzzzzzzzzz
zzzzzzzzzzzzzzz


i need right away...i try but i take whole day...

Code: [Select]@echo off

set "letter=abcdefghijklmnopqrstuvwxyz"
:loop
%%13

echo %output% >> "letter.txt"

goto loop
echo done
pause



What is this for?
Visual Basic Script

cscript //nologo scriptname.vbs > letter.txt

dim a(13)
startcode=97
for j = 1 to 13
a(j) = startcode
next
for index=13 to 1 step -1
thiscode=startcode
do until thiscode > asc("z")
a(index)=thiscode
Mystring = ""
for j = 1 to 13
Mystring = mystring & chr(a(j))
next
wscript.echo Mystring
thiscode=thiscode + 1
loop
next





Password generators for DOS and Windows are readily available.
And some have been written in BATCH also.
Code: [Select]The folowing is not a true random password, but you can build on it replacing the conditional statement

@Echo Off
SetLocal EnableDelayedExpansion
Set Alpha=abcdefghijklmnopqrstuvwxyz

For /L %%j in (1,1,8) Do Call :PSW

Echo Password is [%PSWRD%]
EndLocal
GoTo :EOF

:PSW
If %random% gtr 10000 (
Set PSWRD=%PSWRD%%random:~0,1%
) else (
Set /A i=%random:~-1,1%+%random:~1,1%
If !i! gtr 25 Set i=25
Set PSWRD=%PSWRD%!Alpha:~%i%,1!
)
GoTo :EOF
http://www.computing.net/answers/windows-xp/password-generator-batchfile/151369.html
it some thing i want to try...it start when i watch some movie...on the screen flow many combination letter to search password... i want to see if really works...i want to test it, if its work maybe my password on it...Ah, movie password cracker PROGRAMS... in a real program you would not WASTE time echoing the trial passwords to the screen... and would anyone choose a password like aaaaagzzzzzzz ?
it will become some word...

passwordaxdrt or else...

but i dont know to make that...

aaaaaaaaaaaaa
aaaaaaaaaaaab

change letter one by one...
Quote from: Salmon Trout on May 30, 2013, 02:02:17 PM

Ah, movie password cracker programs... in a real program you would not waste time echoing the trial passwords to the screen... and would anyone choose a password like aaaaagzzzzzzz ?
Thank you! I will use it!
If real password (generator) crackers were used in movies it would make for a very very long and boring movie that would go on for days, MONTHS, or maybe even years depending on complexity, and might not end in the lifetime of the director! Those scenes where someone gains access in less than 10 seconds and you see characters and or digits scrolling or scrolling and locking on matches is completely ALL HOLLYWOOD!!! The fastest crack would be if it was strictly 13 digits 0 - 9 in which you have 10,000,000,000,000 combinations, but that still would take a long time, just not as long as ones with Alpha involved.

A good realistic security system in a 007 movie for example with extremely restricted access would probably send a silent alert upon the 5th attempt to enter a password and entering it wrong, should have doors that would lock the person into a controlled space between the last door entered locked shut and the next door they are trying to get past. This system would not allow for the code to be intered unless the door behind them was shut, and sensors could not be overriden which sense for doors position. Then they would get hauled away and likely killed after the 5th wrong password with generator... most people want Bond to Live! ... LOL So that is why most of the time its a retna scanner with a contact etc, fake fingerprints, and so on for fooling biometric security SYSTEMS.

Scenes like Terminator 2 where John Connor rips off an ATM with his friend for arcade money with an account/pin generator are strictly a laugh or "Give me a break" factor for those who know better!!!

In addition to this, many systems that are used for password authentication in the real world especially for computer or server access will block any further attempts after so many failed attempts were made within a given period of time. Any system not having a lock out is just extremely dumb and left to the movies to display extremely poor security systems.

I created a table that shows just how complex and how long cracking a 13 character password would be for both Alpha and Alpha-Numeric with a generator that tests ALL COMBINATIONS. With home computers unless you own warehouses full of them and have each one cracking a segment of the whole of all possible combination of possibilities, the odds are greatly against you that it will get cracked in many many lifetimes. The computer is likely to let out its secret smoke long before it gets to a match. However if the password was aaaaaaaaaaaaa and the program started at aaaaaaaaaaaaa and ended at zzzzzzzzzzzzz it would start and find a match immediately, however if it is zzzzzzzzzzzzz it is likely not to happen in your lifetime unless computers become way way more powerful or you have a huge team of systems to use combined processing power of and you allocate smaller chunks of range to generate and test against, and the system that is receiving the password attempts does not get flooded or lock you out. If there is no lockout, there is likely a flood condition where it is overwhelmed, UNLESS you are able to farm the hive of the security system and run this locally at each computer that is looking for a match. The hive being an encrypted pool of passwords that the real system has and you can test against, its very much not likely to happen in your lifetime.

That is why dictionary attacks, social engineering someone to giving away the password, keyloggers, exploits by phishing, packet sniffers, etc are used to gain access and password generators are really not the way to go.

In relation to what you are trying to generate, I generated 4 places with a Perl script using the FOR A to ZZZZ instruction and writing output appended to a file, and it took a while to complete on my netbook. 456,976 combinations in all, and VERY VERY lengthy text file!



[recovering disk space, attachment deleted by admin]Not sure why anyone is even assisting with this here....I pretty much wanted to show how UNREALISTIC such a generator was by example Quote from: patio on May 30, 2013, 06:23:12 PM
Not sure why anyone is even assisting with this here....
We are bored Quote
We are bored

LOLLLLL Password programs use multi-GPU these days and are orders of magnitude faster than a one using a CPU.Quote from: foxidrive on May 30, 2013, 08:25:06 PM
Password programs use multi-GPU these days and are orders of magnitude faster than a one using a CPU.
Citation requested.
I often forget my passwords and so I need one of these.
8032.

Solve : Get File Name using Batch?

Answer» SCENARIO:- A new right click option "Get File Name" is implemented for a particular extension ..lets say for .txt
The option "Get File Name' is added for the txt file using Regedit and the action for "Get File Name" is pointed to a batch script.
So when the Get File Name option is selected , the FILENAME which called the script along with the path has to be copied into the batch.
Please provide your ideas and suggestions how to implement the above..ThanksQuote from: jack64 on June 04, 2013, 11:41:29 AM
when the Get File Name option is selected , the filename which called the script along with the path has to be copied into the batch.

By "the filename which called the script" do you mean the "name of the file which was right clicked by the user"?

Exactly!!!!!!!I bet it's held in %1. In a batch script, the replaceable parameter %1 contains the first (or only) parameter passed to the script. If it contains a valid file name, it can be modified with the standard variable modifiers (see the FOR documentation for details - type FOR /? at the prompt) ~d is drive, ~p is path, ~n is name, ~x is extension.

%1 is the raw parameter
If it is a file name, it may already hold the full drive and path, but you can check with simple tests

echo %1
echo %~d1
echo %~p1
echo %~n1
echo %~x1

They can be combined:

echo %~dpnx1

Passed to a variable:

set parameter=%1
echo Parameter is: %parameter%

(etc)

So try that & report results if you need further help.




%0 is the name of the batch file that is being executed. %1 is the first argument from the calling program. Same modifications apply to %0 as to %1
Code: [SELECT]C:\users\lemonilla>batchFile.bat argument1 argument_2 argument-3 "Argument 4"
If you entered this into command prompt,

%0 = "C:\users\lemonilla\batchFile.bat"
%1 = argument1
%2 = argument_2
%3 = argument-3
%4 = "argument 4"
%5 = Undefined
%6 = Undefined
%7 = Undefined
%8 = Undefined
%9 = UndefinedQuote from: Lemonilla on June 05, 2013, 01:38:43 PM
%0 is the name of the batch file that is being executed.

%0 unmodified is the command line that was used to call the batch.

paramtest.bat (in FOLDER c:\Batch)

Code: [Select]@echo parameter 0 is %0
Code: [Select]c:\>paramtest
parameter 0 is paramtest
c:\>paramtest.bat
parameter 0 is paramtest.bat
c:\>c:\Batch\paramtest.bat
parameter 0 is C:\Batch\paramtest.bat
However...

paramtest2.bat (in c:\Batch)

Code: [Select]@echo this script is %~dpnx0
Code: [Select]c:\>paramtest2
this script is c:\Batch\paramtest2.bat
Note: in the above examples, the folder c:\Batch is on my PATH.
8033.

Solve : help me with movement please??

Answer»

I am messing around in batch creating some games and some of my favorite games, but I need help with something.
I am making a game that when you press WASD your CHARACTER moves, and I'm WONDERING how i can do this.

-thanks choice /c wasd
if %errorlevel% == 1 THIS IS FOR W
if %errorlevel% == 2 THIS IS FOR A
if %errorlevel% == 3 THIS IS FOR S
if %errorlevel% == 4 THIS IS FOR D

8034.

Solve : another newbie batch file question?

Answer»

im making a text-based rpg. i HEARD thats a good way to flex your batch file skills.
apparently, i dont have as much skills as id have hoped.

i know %errorlevel% can be used in a window to run commands when another main window closes, after converting the batch to an exe.
in this case, it would be used as an autosave so when the player loses, they cant exit out for a do over.
i have a basic txt-file-based saving system already, so that isnt a problem.

but my predicament is that the player can exit out the autosave window to allow do overs, once they lose in the main window.

is there a way to hide another batch window, and open it once another batch file opens?There is no real way to make a bat file invisible, though if you compiled it into an exe then you can USE vbs to minimize the 2nd batch file that looks in 'tasklist' for 'xxx.exe' and when it closes saves the game. The issue with this is that both batch files have SEPARATE variables and the 2nd would not be able to recover any data from the first.

You could always save after every EQUATION. This is a little more code intensive and runs a little slower, but not enough to be noticeable as you are only saving the changing value. (keep all of your variables in .txt files and draw them out when you need them, then remake the file after you have changed the value.)

A little off topic, but you may want to consider making it in parts and then using the 'call' command to jump between the parts. There is not a lot of room for error if you write it all in one giant file.

8035.

Solve : Batch file to alter m3u file (Newbie request)?

Answer»

Hi,
I export playlists from iTunes as m3u files, but have to alter them before I can use them in my car's audio system. I currently do this by opening them in Notepad, and using 'replace all' to make the changes but as there are quite a few playlists, this takes some time, and I think there must be an easier way. Could a batch file do this for me ?.

The playlists are .m3u files, and have multiple lines of paths to music files like :-

E:\Music\Music Library\song 1.mp3

from which I want to remove the text shown red from each line. Is this possible with a batch file ? (ideally running it once to do all the different playlists). If so, could someone point me in the right direction ?

Ta There is an exact science to batch where it doesn't bend on commands at all. To get the most accurate SCRIPT we would need an example or two of the m3u files. Without them we can only really guess at what needs to be done. Here is a script that should do the job though I would run it on a backup version of your m3u folder just in case.

Code: [Select]@ECHO off
setlocal EnableDelayedExpansion

for /f "delims=" %%A in ('dir /b ^| find ".m3u"') do call :m3u "%%A"

exit /b




:m3u
0>nul set /p=Processing %~1 . . .
set m3u=%~1
for /f "delims=" %%B in (%m3u%) do (
set "WORKING=%%B"
if "!working:~0,9!"=="E:\Music\" set "working=!working:~9!"
echo !working! >>%m3u%.done
)
notepad %~1.done
:: DEL /f "%~1"
:: rename "%~1.done" "%~1"
echo Done.
goto :eof

If the file that it opens up does what you want it to, remove both "::" and the line 'notepad %~1.done'. I hope this helps.Try this:

Code: [Select]@echo off
for /f "delims=" %%a in (' dir *.m3u /b ') do (
echo %%a
call repl "E:\\Music\\" "" im <"%%a" >"%%a.tmp"
move /y "%%a.tmp" "%%a" >nul
)
pause

This uses a helper batch file called repl.bat from - http://www.dostips.com/forum/viewtopic.php?f=3&t=3855Thanks Lemonilla - that worked perfectly !

Thanks also for your response foxidrive - I did try it too, but couldn't get it to work, but that was PROBABLY due to my error.

8036.

Solve : Batch file - Multiple files to a command at once?

Answer»

Hello everyone, I am new to this forum.

My question involves batch files, please bear in mind this is only my second batch file, and I am almost completely novice.

I was using the FOR command "FOR %%variable IN (set) DO command [command parameters]" to send all files in a sole directory to an external program. I got this to work just fine. Problem is, each file was being sent one at a time. I need to find a way to send all the files in the directory to the program at once. Any ideas?

An example of the code i was using.

Code: [Select]FOR %%X IN (*.wav) DO "G:\Program Files\flac\flac.exe" "%%X"

Secondly, is there a way to "DO" multiple commands within the FOR?

Thanks for the help. Not sure what you mean by all at once. You could try something like this:

Code: [Select]"G:\Program Files\flac\flac.exe" *.wav

Doubtful that would work. You can try stringing the file names on the command line, something like this:

Code: [Select]@echo off
setlocal
for %%x in (*.wav) do (
call set strCmd=%%strCmd%%,"%%x"
)
set strCmd=%strCmd:~1%

"g:\program files\flac\flac.exe" %strCmd%
endlocal

That could possibly work. Depends more on how the program accepts input. Use parenthesis to "DO" multiple commands within the FOR. The snippet above shows how.

Good LUCK. I think the separator for multiple input files is white space not a comma, and that implies that filenames which contain spaces need quote marks before and after.

Quote from: gregory on September 23, 2008, 01:18:16 AM

Secondly, is there a way to "DO" multiple commands within the FOR?

FOR %%variable IN (set) DO (
command1 [command parameters]
command2 [command parameters]
commandn [command parameters]
)

Beware of setting variables within the loop, you will need to use delayed expansion, or they won't work!
Quote from: Dias de verano on September 23, 2008, 11:42:59 AM
I think the separator for multiple input files is white space not a comma, and that implies that filenames which contain spaces need quote marks before and after.

Not only white space, but commas, semi-colons and equal symbols are perfectly acceptable to the interpreter for use as separators.

To guard against space embedded file names, the original code brackets each file NAME with quotes:

Code: [Select]@echo off
setlocal
for %%x in (*.wav) do (
call set strCmd=%%strCmd%%,"%%x"
)
set strCmd=%strCmd:~1%

"g:\program files\flac\flac.exe" %strCmd%
endlocal



Quote from: Sidewinder on September 24, 2008, 04:14:42 AM
Not only white space, but commas, semi-colons and equal symbols are perfectly acceptable to the interpreter for use as separators.

I'm not talking about "the interpreter", I'm referring to flac.exe Oops! From what I could find out the OP's original code was correct. I didn't find any examples of how to send multiple files to flac.exe other then iterating a directory.

Examples

Flac FAQ

Quote from: Sidewinder on September 24, 2008, 11:35:49 AM
Oops! From what I could find out the OP's original code was correct. I didn't find any examples of how to send multiple files to flac.exe other then iterating a directory.

Indeed.

This suggestion from the FAQ, in answer to the question "why don't wildcards work?"...

Quote
for %F in (*.wav) do flac "%F"

That is a command line example - double up the % signs if including in a batch.

This implies that flac can only do 1 input file at a time, and that the answer to the OP's question, which was...

Quote
Problem is, each file was being sent one at a time. I need to find a way to send all the files in the directory to the program at once.

...is, "Sorry, there isn't a way to do that, because flac.exe won't accept multiple file names"

I'd be interested to know why the OP WANTS to send multiple filenames all at once to flac.exe, SINCE even if it could accept them, it would still process them one after the other, and the result would be exactly the same as the solutions outlined above.Thanks for all the help you two, it is much appreciated.

Indeed flac.exe can accept multiple files. White spaces are the seperators, each file name wrapped in quotes if it contains spaces. File names are to be listed after flac.exe and some options. Code: [Select]flac [various options] "filename1" "filename2" "filename3"
As to why I want to do this; flac supports something CALLED "replay gain" http://replaygain.hydrogenaudio.org/. Each file will be encoded separately, however flac.exe must know which files are considered an album/group to properly calculate replay gain values for each individual track.

I think sidewinders idea/code of stringing the file names together should work. I don't fully understand what exactly the code is doing, but I will try it out and report back.

Thanks again.

-edit-
grammaticalBased on your latest post, this will give you white space separators on the command line:

Code: [Select]@echo off
for %%x in (*.wav) do (
call set strCmd=%%strCmd%% "%%x"
)
"g:\program files\flac\flac.exe" [various options] %strCmd%

Be sure to put in the various options before running the code. The code is designed as a batch file. Simply reporting back as I said I would. The code does indeed work.

Thanks again.
8037.

Solve : Use DOS from CMD prompt to show file version on WinXP PC?

Answer»

I am trying to display a file's name, last modified date, and file version from the command line.

dir /q
-returns owner information and includes file name and last modified date.

now I only need a way to see the files version information

any help is much appreciatedSince you've not had any response to your post in two days, I just thought I'd stop by and say "HI".

What kind of file are you wanting to see the Version on?
A doc or txt file for instance won't usually have any Version.
However a program file like say, "Ghost.exe" will have a version and it will be shown if you type,
Ghost /ver
at the command prompt of the folder containing the file.

Maybe give more info on your needs and someone will come up with just what you need.

Cheers Mate!
The Shadow Good point Shadow

I'm trying to get version information from a directory of .dll files.

I tried the "filename /ver" at the command prompt for the home directory but get this message:
'filename.dll' is not recognized as an internal or external command,
operable program or batch file.

I tried the same option on a .exe file and it executes the file.

Do you have a TOOLKIT or package installed that allows the /ver to work?

Thanks!If I'm wrong, I'll be the first ONE to admit it.... (Really!)
But I think you're looking for something that does not exist.

I don't understand why or even how there could be a Version assigned to a Folder.
The date it was created, yes. Windows Explorer will show you that.
"That does not Compute!" to quote "The ROBOT" from Lost in Space.

The fact that a program like, say, Ghost.exe can provide you with a version is actually written into the program itself. It's NOT a function of DOS or Windows.
When I actually do that with Ghost.exe (as an example), from a command prompt, I get all the Copyright info, the date the program was created and of course, the Version number.

But if that ability was not actually written into the program itself, I'd get some kind of error by trying to run the program with the /ver extension.

Just for grins and giggles, I just did this from my ghost folder:
Ghost /ver > C:\Ghostver.txt

And the resultant text file shows this:

Symantec Ghost 8.3.0 (build=1331, cdrlib=3.1.31). Built on Nov 28 2005 17:37:37.
Copyright (C) 1998-2005 Symantec Corporation. All rights reserved.

But, the ability to divulge that information had to be written into the file itself.

Am I making any sense at all here?

Ok, I'll shut up now.

Y'all have a great day now, Y'hear?

The Shadow




If I read his clarification correctly- I can surmise he wants the version number of the DLL files, not the folder itself.

I've seen command-line programs for this, but I completely forgot where... (helpful, I know)BC: That's correct, I'm trying to get the version information from the .dll files.

From the XP GUI I can show the versions but wanted to use DOS to pipe them to a flat file.

Shadow: Thanks for the effort! Just curious, does the /ver switch work on other .exe files other than Ghost? I'm also starting to think that this option doesnt exist for DOS. Maybe an approach from ASP.... I have over 10,000 files to get version info from so trying to do this programatically.Quote

Maybe an approach from ASP.... I have over 10,000 files to get version info from so trying to do this programatically

If you would like to do this with VBScript, this may help you out:

Code: [Select]Set fso = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Shell.Application")
Set f = fso.GetFolder("c:\windows\system32") 'change directory name
Set fc = f.Files
For Each fs In fc
If fso.GetExtensionName(fs) = "dll" then
WScript.Echo fs.Name, fs.DateLastModified, fso.GetFileVersion(fs)
End if
Next

Save script with a vbs extension and run from the command line as cscript scriptname.vbs



You may want to make the OUTPUT more presentable.OMG... and to think I was just reading up on the WIndows FileVersion API FUNCTIONS and write a C Program for essentially that purpose.

You saved me a lot of work Sidewinder! Sidewinder: Thanks for the help, that was exactly what I needed! I modifed the file like below to get a flat file output.

Worked Great!


Code: [Select]Option Explicit
Dim fso, fc, f, fs
Dim strPath, strFile

'On Error Resume Next

strPath = "C:\Documents and Settings\profile\desktop\dlls.txt"

Set fso = CreateObject("Scripting.FileSystemObject")

Set strFile = fso.CreateTextFile(strPath, True)

strFile.WriteLine("FileName,Last Modified,File Version")

Set f = fso.GetFolder("C:\Documents and Settings\profile\dlldir")
Set fc = f.Files
For Each fs In fc
If fso.GetExtensionName(fs) = "dll" then
strFile.WriteLine(fs.Name & "," & fs.DateLastModified & "," & fso.GetFileVersion(fs))
End if
Next
8038.

Solve : changing dos path using batch file?

Answer»

I am new to batch programming.
I want to open a new dos window and set its path to c:/pqr/xyz at its opening, using batch file. Please help.In the beginning of the batch file, you must have the following:

cd "C:\pqr\xyz"

That will make the Command Prompt Window look at that directory.WOW, that was a brain teaser!

In my experiment I tried to open the command (cmd) window from the C:\temp FOLDER.

My LITTLE batch file looked like this:

cd\temp
cmd


That changed the current directory to my temp folder and then executed the CMD command.

When the resulting CMD windows opened, it was already in the C:\temp folder.

Well, it worked for me ANYWAY.

CHEERS Mate, and Good Luck,
The Shadow


Actually, I run my batch file currently from c:\sk\rnd directory which opens a new dos window with same path i.e. c:\sk\rnd whereas I want the new window with path as c:\pqr\xyz.
Also, if i want to open d:\abc\def from the same batch file how will i go....This sounds like school WORK to me.
Quote from: sudesh_roy on September 28, 2008, 10:31:05 AM

I want the new window with path as c:\pqr\xyz.
Also, if i want to open d:\abc\def from the same batch file how will i go....

you can try following code
Code: [Select]cd c:\pqr\xyz
call cmd
and for d:\abc\def
you can try following code
Code: [Select]d:
cd abc\def
call cmd
may code solve ur problem
8039.

Solve : copy files in harddrive?

Answer»

My Windows XP is dead and I got to boot it in an external disc. I got to the screen of dos command. How can I copy those word/excel files in desktop and my document in my harddrive?
I don't think you can do what you want to do like that.

If you have ANOTHER computer, you can hook up the current hard drive as a Slave and access the hard drive in My Computer on the other computer.

Otherwise, if you have a Flash Drive, you may want to temporarily install Portable Linux.
With that, you can boot the computer from your flash drive and copy the files to the flash drive.
(www.pendrivelinux.com)Milk,
If the XP drive is DEAD, you're not going to GET anything out of it any way you connect it.
Now, if the drive is OK, but windows is screwed up, then you have some options.

Like was just said by 'Carbon Dudeoxide' , you should attach that drive to another computer as a slave drive and extract the files you need using Windows Explorer on the OS drive. Then the files could be copied to a Flash Drive or burned to a CD/DVD.
I perform this "SERVICE" all the time for my customers.

From DOS you will NOT even be able to read the average Windows XP drive, because it will be formatted NTFS and that's INVISIBLE to DOS. (Sorry, I didn't make the rules!)

However, if you have "NTFS4DOS" on your boot disk, it will allow you to read and copy files from an NTFS drive.

Due to this restriction, I NEVER set up any HD for XP on an NTFS formatted drive.
XP runs just fine on a FAT-32 drive and then I have full control over that drive, even from a DOS boot disk.

Good Luck to you!

The Shadow

8040.

Solve : date manipulation within a batch file?

Answer»

Is there something available for date manipulation? E.G. I have a file aaa-bbb-20080930 which represents a file created on 20080930. I execute a PROCESS on 20081001 which needs the prior day's file which is aaa-bbb-20080930 . If I merely subtract 1 from today's date I'm not ending up with what I want in terms of the date part of the file I need to process.

Hopefully there may be something which is non C and Perl....search on Google Groups Usenet archive on alt.msdos.batch.nt maybe...Wow, a question Dias doesn't want to tackle... I haven't seen a lot of those in the DOS forum. :X(1) No point in reinventing the wheel, and (2) at some point in a budding batch programmer's progress they should be introduced to alt.batch.msdos and its nt variant (3) That's where I get a lot of batch solutions anyway so I thought "Hey - cut out the middle man!" and (4) I was about to OPEN a bottle of wine, organic Argentinian Malbec, and watch a film so I was a bit pressed for time.

However.

For humans it is simple to determine yesterday's date, we just have to think for a moment, but it is tricky to get RIGHT in a batch script. For example you need to cater for when today is the first day of the year or month, (How many days in last month; if last month was Feb, is this year a leap year? [Have to implement Zeller's Congruence to crack leap years properly], etc etc. Like the guys in the newsgroup say,

Quote

Getting yesterday's date is simple using a secondary language that has real time functions

so we could for example create a one line vbs script which discovers yesterday's date and echoes it

Code: [Select]wscript.echo (Date()- 1)
and then CALL it from a batch file. It is probably simplest to create the vbs script within the batch file using echo and redirection, taking care to escape the parenthesis characters.

I also see from the date format used in BRIANH's question that his local date format appears to be the US style, i.e. mm/dd/yyyy so I will assume that.

Having got yesterday's date back from the vbscript it is necessary to remove the slashes and rearrange the digits to obtain the yyyymmdd format seen in the filename datestamp examples shown.

Code: [Select]@echo off
echo wscript.echo ^(Date^(^)- 1^)>yesterday.vbs
for /f %%a in ('cscript //nologo yesterday.vbs') do set ydate1=%%a
del yesterday.vbs
set ydate1=%ydate1:/=%
set m=%ydate1:~0,2%
set d=%ydate1:~2,2%
set y=%ydate1:~4,4%
set ydate2=%y%%m%%d%
echo yesterday was %ydate2%
I wasn't saying you couldn't solve the problem- I thought you had simply- or, I should say- finally, lost patience to give it any of your time.Quote from: BC_Programmer on September 27, 2008, 11:27:06 AM
I wasn't saying you couldn't solve the problem- I thought you had simply- or, I should say- finally, lost patience to give it any of your time.

Oh ye of little faith.... I modified the code to suit my date format which is yyyy-mm-dd and it works fine except that if the current date is 2008-04-01 the new date is 2008-03-31 instead of 2008-03-29, where have I gone wrong please?

Amended code
Code: [Select]@echo off
cls

echo wscript.echo ^(Date^(^)- 1^)>yesterday.vbs
for /f %%a in ('cscript //nologo yesterday.vbs') do set ydate1=%%a
del yesterday.vbs

set m=%ydate1:~5,2%
set d=%ydate1:~-2%
set y=%ydate1:~0,4%

set ydate2=%y%-%m%-%d%
echo yesterday was %ydate2%

See below for how to make an absolute CHUMP of oneself Quote from: Hedonist on September 27, 2008, 05:03:46 PM
I modified the code to suit my date format which is yyyy-mm-dd and it works fine except that if the current date is 2008-04-01 the new date is 2008-03-31 instead of 2008-03-29, where have I gone wrong please?

The code is working fine. I suspect that "where you have gone wrong" is in confusing March and February. If "today" is the first day of the fourth month, that is, the first of April, then "yesterday" is the last day of March, which has thirty-one days (every year).

If the current date were 2008-03-01 (The first of March, the third month of the year) then yesterday, since 2008 is a leap year, would be the twenty-ninth day of February, 2008-02-29.

Here is a little rhyme which, if you learn it, may help you avoid this (evidently) tricky problem...

Thirty days hath September,
April, June, and November:
All the rest have thirty-one,
Except for February
Which hath but twenty-eight days clear,
And twenty-nine in each leap year.



Quote
I suspect that "where you have gone wrong" is in confusing March and February.

No, 'twas nowt to do with that. I have discovered that when I awoke this a.m. I failed to switch on my brain before allowing fingers on keyboard.

Thanks Dias, as usual a fine piece of coding.

8041.

Solve : compile and run both?

Answer»

hi friends,

I made a batch FILE to compile java programs using javac

here it is
Code: [Select]@ echo off

cd C:\Program Files\Java\jdk1.6.0_02\bin

javac %1

at commond line i type jrun javafile.java

then the target file GET compiled successfully.

now what code snippet should I add to run the class file also using java class LOADER tool, that has been come from compilation?This should HELP you with the mechanics, you may have to provide the details:

Code: [Select]@echo off
javac %1.java
if not errorlevel 1 java %1.class

Quote

at commond line i type jrun javafile.java

Change that to jrun javafile and let the batch file determine the file extensions.

Check your path, if the java install did not add itself to your path, then a suggestion would be to LOGIN to the directory where your source code resides and use a path pointer to java directories. This will keep your source libraries and the java libraries separate.

Code: [Select]@echo off
cd C:\YourSourceDirectory
C:\Program Files\Java\jdk1.6.0_02\bin\javac %1.java
if not errorlevel 1 C:\Program Files\Java\jdk1.6.0_02\bin\java %1.class

You will have to test this to make sure java can find all it's components.

8042.

Solve : Search and copy?

Answer»

What I'm trying to find, is a way to search for a string of text that's outputted from a command, then COPY the next couple characters, and finally store them as a variable.

In case anyone needs it, the command I'm using is "net config rdr", and I want to use it to get the network adapter's GUID, however it outputs a lot of other things that I don't need, and I want just the GUID.

Thanks in advance!Code: [Select]@echo off
for /f "tokens=3 delims={}_" %%i in ('net config rdr ^| find /i "tcpip"') do echo GUID: %%i

The snippet is designed as a batch file. The GUID is in the variable %%i.

Thanks, I got my batch file to work perfectly.

However, if you can, do you mind explaining how your snippet works?

Thanks again!First run the initial command from the command line: net config rdr which produces:

Quote

Computer name \\LAPTOP
Full Computer name Laptop
User name *****

Workstation active on
NetbiosSmb (000000000000)
NetBT_Tcpip_{96C2160D-9E3B-4AE5-97CC-4B88AE6DB75F} (001150F4851B)

Software version Windows 2002

Workstation domain ********
Workstation Domain DNS Name (null)
Logon domain LAPTOP

COM Open Timeout (sec) 0
COM Send Count (BYTE) 16
COM Send Timeout (msec) 250
The command COMPLETED successfully.

Next use the find command to extract the line where the GUID resides: net config rdr | find /i "tcpip"

Quote
NetBT_Tcpip_{96C2160D-9E3B-4AE5-97CC-4B88AE6DB75F} (001150F4851B)

Next use the for command to parse the resulting output: for /f "tokens=3 delims={}_" %i in ('net config rdr | find /i "tcpip"') do echo GUID: %i

Quote
GUID: 96C2160D-9E3B-4AE5-97CC-4B88AE6DB75F

Finally, fix up the command for use in a batch file.

Code: [Select]@echo off
for /f "tokens=3 delims={}_" %%i in ('net config rdr ^| find /i "tcpip"') do echo GUID: %%i

The for command uses a combination of arbitrary tokens, delimiters, and a starting point of sequential addressable variables to do the parsing. For instance, this version of the for would be equally correct:

Code: [Select]@echo off
for /f "tokens=2 delims={}" %%x in ('net config rdr ^| find /i "netbt"') do echo GUID: %%x

Hmm, I'm not 100% sure of what the "for /f" and the "tokens=3 delims={}_" are for. Furthermore the "%i" variable is contained within the "for" command, and cannot be used outside.


Again, thanks for your THOROUGH REPLIES!
8043.

Solve : Calculating using time?

Answer»

I also have a calculating problem.
I would like to calculate how long some commands take.
For example:

@echo off
set old=%time%
echo %old%
rem some commands here
echo %old% %time%
set /A delay="%time% - %old%"
echo %delay%
pause

I get an error "Missing operator" with an 18 on the following line.
If I remove the % signs I don't get an error just "-19" on the following line. There must be some sort of a syntax error, but I don't know enough about the set command it to rectify it. It would be nice if I understood the help file (set /?).
Any help would be appreciated.
Frankwhat does %time% look like?%time% looks like 19:44:16.85
FrankYou have to remove the colons, separate out the hours, minutes and seconds, multiply hours x 3600, minutes x 60, and add to seconds to get seconds since midnight, then you can subtract one from another.
o/k, this no longer sounds like a job for a batch file.
Frankcan be done, I've done it, when I get home in about 6 hrs I'll post it. The big trouble comes when you span midnight. You can get the PC's up time from Windows and use that. Catch me later.
Thank you very much.
In 6.5 hours it will be 3:00am here so I will be asleep. But I'll look at the post when I get up.
Thanks again.
FrankHave you got XP pro?

can you use the systeminfo command?

Yes, I have Windows XP Pro SP2.Number of seconds since computer was last booted:

for /f "tokens=1-14 delims= " %%A in ('systeminfo ^| find "System Up Time"') do set /a secs=86400*%%D+3600*%%F+60*%%H+%%JThank you very much.
This is what I did:

@echo off
for /f "tokens=1-14 delims= " %%A in ('systeminfo ^| find "System Up Time"') do set /a secs1=86400*%%D+3600*%%F+60*%%H+%%J
rem some commands to do
for /f "tokens=1-14 delims= " %%A in ('systeminfo ^| find "System Up Time"') do set /a secs2=86400*%%D+3600*%%F+60*%%H+%%J
set /a secs3=secs2-secs1
echo %secs3% seconds taken.
pause

I am not sure I understand the syntax, expecially %%H etc. but it works that's the main thing.
Thanksregarding the syntax - the output of systeminfo is a long string of words separated by spaces, so %%B to %% J are "implicit variables" created by the tokens=1-14 section. Actually, 1-11 would do just as well.

You should note that the actual systeminfo operation takes about 2 seconds, (on my system) so you should subtract that from the second time. You can establish the size of this delay overhead by running the code like this


Code: [Select]@echo off
for /f "tokens=1-14 delims= " %%A in ('systeminfo ^| find "System Up Time"') do set /a secs1=86400*%%D+3600*%%F+60*%%H+%%J

rem nothing here

for /f "tokens=1-14 delims= " %%A in ('systeminfo ^| find "System Up Time"') do set /a secs2=86400*%%D+3600*%%F+60*%%H+%%J
set /a secs3=secs2-secs1
echo %secs3% seconds taken.
pause
Thanks,
Tried it and the overhead on my system is also 2 seconds.
If you do not mind that this will give wrong RESULTS if the first time is before midnight, and the second time is after (the next, or a subsequent!) midnight, then this code takes the hours, minutes, seconds, and hundredths of a second in the %time% variable and converts to a figure in milliseconds, and it takes much less than 2 seconds! I would not TRUST it to beyond around 50 msec though.

Code: [Select]@echo off
set ntime=%time%

REM slice up %time%
REM PRESUMES 24 hr clock hh:mm:ss.nn
REM nn=1/100ths of seconds
set hh=%ntime:~0,2%
set mm=%ntime:~3,2%
set ss=%ntime:~6,2%
set cs=%ntime:~9,2%

REM remove any leading zeroes because set /a
REM treats them as indicating octal values
REM and barfs at 08 and 09, understandably!
REM also remove leading space if hour < 10
if "%hh:~0,1%"==" " set hh=%hh:~1,1%
if "%mm:~0,1%"=="0" set mm=%mm:~1,1%
if "%ss:~0,1%"=="0" set ss=%ss:~1,1%
if "%cs:~0,1%"=="0" set cs=%cs:~1,1%

REM now they are all VALID integer values, do the arithmetic
set /a msec=3600000*%hh%+60000*%mm%+1000*%ss%+10*%cs%
echo %msec%
say you called it mtime.bat and stored it somewhere on your PATH, you could use it like this

With just that "REM code to be timed" line I am mostly seeing values between 100 & 200 msec with a few as low as 70 or as high as 230.

Code: [Select]@echo off
for /f %%T in ('mtime.bat') do set time1=%%T
REM code to be timed
for /f %%T in ('mtime.bat') do set time2=%%T
set /a elapsed=%time2%-%time1%
echo elapsed %elapsed% millisecondsThat is cool.
Overhead on my computer is 110-140ms.
This is a much better solution that STEPPING through a file.
Thanks

Just thought, a dummy run could be made to determine the overhead and then subtract that amount at the end. This would be more acurate. The error that still exists is the variation between successive runs (+- 20ms).

Code: [Select]@echo off
rem DO A DUMMY RUN TO FIND THE OVERHEAD
for /f %%T in ('mtime.bat') do set time1=%%T
for /f %%T in ('mtime.bat') do set time2=%%T
set /a overh=%time2%-%time1%

for /f %%T in ('mtime.bat') do set time1=%%T
REM code to be timed
for /f %%T in ('mtime.bat') do set time2=%%T
set /a elapsed=%time2%-%time1%-%overh%
echo elapsed %elapsed% milliseconds
pause

8044.

Solve : bat file processing a file with a date as part of the file name?

Answer»

I have a file aaa-bbb_yyyymmdd - yyyymmdd = current date. The file is really a logfile, created new each day at 12 AM with the current date as part of the file name.

I am attempting to setup an automated process to access the file which has a moving name each day. The process will use a BAT with imbedded DOS commands
e.g. findstr etc. to create a file (static filename) which will be used by a secondary process.

How or what can I use to concatenate the stem filename aaa-bbb and the current date… I have displayed the %DATE% variable in the BAT file and it
is displayed as yyyy/mm/dd which is not much use to me….

I don't have any experience with C and very little Perl experience… I was hoping there might be something in DOS itself..
Quote

I have displayed the %DATE% variable in the BAT file and it
is displayed as yyyy/mm/dd which is not much use to me….

You can use this notation for the current date: %date:/=% to strip out the slashes.

Code: [Select]aaa-bbb_%date:/=%

Good LUCK. Quote from: SIDEWINDER on September 25, 2008, 06:20:11 PM
You can use this notation for the current date: %date:/=% to strip out the slashes.

The notation WORKS like this

%string:cat=dog%

That MEANS: in %string% remove every occurrence of "cat" and put "dog" in its place. In the string variable whose name appears between the first percent sign and the colon, replace whatever is between the colon and the equals sign with whatever is between the equals sign and the right hand side percent sign. So %date:/=% replaces / with nothing, and %date:/=-% replaces / with a - (minus sign or hyphen).

Many thanks.. that helped me a lot...
Now, to ramp my issues up a notch... is there something available for date manipulation? E.G. I have a file aaa-bbb-20080930 which represents a file created on 20080930. I execute a process on 20081001 which needs the prior day's file which is aaa-bbb-20080930 . If I merely SUBTRACT 1 from today's date I'm not ending up with what I want...
8045.

Solve : Vista dos to rename?

Answer»

I had a crash with the computer. I have been able to get to command prompt and save most of my files using an xcopy command. I have a few files such as My Pictures that I get an error message when trying to COPY. I believe the reason is the space in the NAME. Is there a way to rename these files to copy or is there ANOTHER command to use instead of xcopy? Or is there any other means of saving these files? ThanksQuote

I believe the reason is the space in the name

Try putting QUOTES around the file names.

ex: xcopy "c:\source" "c:\target"

This seems to be working. I appreciate your reply very MUCH. I felt there must be a way I just didn't know what it was. Thank you so much. sp
8046.

Solve : I want to delete a file if the creation date is not current.?

Answer»

I have updated the configuration file for my software distribution solution. I want to delete the existing configuration file if the creation date is older than the newly created configuration file.

Thanks,
Todd This is my current solution. I've tried to adapt some the ideas I found
in the forum to create a new solution, but no luck so far.

rem /* ================================ */
rem /* WSUS registry entry. */
rem /* 09/23/08 -tah */
rem /* ================================ */


DIR C:\NET\sus_client\wsus-*.reg | FIND "/2008" > nul
if not errorlevel==1 (goto _WSUS
) ELSE (goto _WSUS_No
)
)
GOTO _WSUS_END


:_WSUS
ECHO The date on this file does match.
GOTO _WSUS_END


:_WSUS_No
ECHO Doesn't match.
ATTRIB -R C:\NET\sus_client\wsus-*.reg
DEL C:\NET\sus_client\wsus-*.reg


:_WSUS_END


Thanks,
ToddIm not sure whether you want to keep only the latest configuration, or remove a configuration set if it is superseded.

If you want to have only the most up to date files, then xcopy will do it for you - taken from the online help
/D:m-d-y Copies files changed on or after the specified date.
If no date is given, copies only those files whose
source time is newer than the destination time.

Does this help ?
GrahamCode: [Select]if not errorlevel==1
That should be

Code: [Select]if %errorlevel% NEQ 1Quote from: gpl on September 18, 2008, 11:18:59 AM

I'm not sure whether you want to keep only the latest configuration, or remove a configuration set if it is superseded.

If you want to have only the most up to date files, then xcopy will do it for you - taken from the online help
/D:m-d-y Copies files changed on or after the specified date.
If no date is given, copies only those files whose
source time is newer than the destination time.

Does this help ?
Graham
Graham,

Your suggestion would work perfectly if I was using a batch file to replace the current configuration file.

My problem is that I have 22 subnets and a different configuration file for each subnet. A program runs during the LOGIN process and determines the 3rd octet of the PC. Then a configuration file is created on the PC based on the 3rd octet. The configuration file points the computer to a specific software distribution server.

My objective is to delete the current configuration file. That will trigger the application to create a new configuration file. The new configuration file will have a new creation date. If the PC has a new configuration file, I don't want to delete it with my login script the next time my user logs into the PC.

Hopefully you have more. I want to delete the configuration file if it is older than the date I specify in my batch file.

Thank you for your response!!!

ToddQuote from: Dias de verano on September 18, 2008, 11:56:20 AM
Code: [Select]if not errorlevel==1
That should be

Code: [Select]if %errorlevel% NEQ 1

Días de verano,

Gracias por su ayuda.

This is the only way I know to get the date on the file.
***
set todd=(
DIR C:\NET\sus_client\wsus-*.reg)

C:\Documents and Settings\THamblin>DIR C:\NET\sus_client\wsus-*.reg
Volume in drive C has no label.
Volume Serial Number is 680C-4B0F

Directory of C:\NET\sus_client

12/04/2006 10:56 AM 2,010 wsus-cc.reg
1 File(s) 2,010 bytes
0 Dir(s) 11,905,589,248 bytes free

C:\Documents and Settings\THamblin>
***

Then I saw this in the forum and thought I could use it if I could set the date of the file as a variable.
***
for /f "tokens=1-5 delims=/ " %%d in ("%date%") do set hope= %%e/%%f/%%g
***

I could get the right line of text with this.
***
DIR C:\NET\sus_client\wsus-*.reg | FIND "/2006"
***

But I have not found a way to pull the date out of that line of text.

Any ideas you can come up with would be appreciated.


Thanks,
ToddI'll be the first to admit that this is a mess, but it seems to work. You're only checking for equality, which is a simple string compare. There is no real need to fix up the dates into yyyymmdd format.

Code: [Select]@echo off
for /f "tokens=2 delims= " %%i in ("%date%") do (
set dt=%%i
)

for /f "skip=5 tokens=1,7 delims=/ " %%i in ('dir /a-d C:\NET\sus_client\wsus-*.reg') do (
if %dt% NEQ %%i echo del C:\NET\sus_client\%%~nxj 2>nul
)

As written, the script will simply list the files to be deleted. When you are satisfied with the RESULT, remove the WORD echo from the next to last line.

Good luck. To get the various dates possibly associated with a file you can use dir with the /T switch and one of these letters:

C Creation
A Last Access
W Last Written

Thus DIR /TC gets creation date / time

so:

Code: [Select]@echo off
REM assumes there is only ONE .reg file in the folder
for /f %%A ('dir /b /TC C:\NET\sus_client\wsus-*.reg') do set Cdatetime=%%~tA
for /f "tokens=1,2 delims= " %%D in ("%Cdatetime%") do set Cdate=%%D
echo creation date: %cdate%
echo today's date: %date%
if not "%cdate%"=="%date%" goto nochange

REM code to run if dates are different

:nochange


I am a bit confused because in the first post, I see this

Quote from: THamblin
I want to delete the existing configuration file if the creation date is older than the newly created configuration file.

But now I see the requirement has changed to deleting the existing configuration file if the the creation date is just different from the newly created one. Thank you Sidewinder and Días de verano. Your ideas have helped me to get my solution. You are both AWESOME!!!

Thanks,
Todd
8047.

Solve : How to run my personal exe file during boot up??

Answer»

Quote from: getkiran1 on SEPTEMBER 25, 2008, 04:17:49 AM

NB: my INTENTION was not to hack or somthng lik dat.. jst for gaining knowledge.. ok?

Ok, whatever you SAY.
8048.

Solve : batch file - multiple lines in one?

Answer»

Hi, I have been looking for a way to do the following :

I have a text file, for example MyTextFile.txt containing the text :

C:\File1
C:\File2
C:\File3

within a batch file, i want to retrieve what is contained in MyTextFile.txt and generate a string which looks like this :
C:\File1;C:\File2;C:\File3

in order to subsequently LAUNCH a command using this as argument.

in a way, this amounts to reading MyTextFile.txt and REPLACING end-of-lines by semicolumns.
i was not able to do this in my batch.

any ideas ?

Code: [Select]@echo off
for /f "tokens=* delims=" %%x in (MyTextFile.txt) do (
call set strArg=%%strArg%%;"%%x"
)
set strArg=%strArg:~1%

strArg CONTAINS your data.

Welcome to COMPUTER Hope. Please do a search before posting your questions. As it happens, a very similar question was posted earlier this morning.

8049.

Solve : Recycling an Application Pool (IIS 6.0)?

Answer»

Hello everyone,

Been a while since I last visited so I hope all are well.

WOULD like to know if it is possible for a batch script to recycle an application pool in IIS.

I have a application that monitors a large number of websites and on occassion some of these websites get themselves tied up. This means that generally I need to recycle their application pool (note - each website has their own independant application pool).

Within the application MONITOR I can stipulate to execute a script/executable dependant on certain conditions. And I began wondering if a batch script was plauseable.

Your thought on the MATTER appreciated.

Cheers,
CameronExactly what needs to be done to recycle an application pool? As IIS is INTERNET BASED, my best guess is batch would not be suitable. But hey! you never know.

Most any of the Windows script languages might be useful.

Let us know.

Hi Sidewinder,

Coincidence is a funny thing.
Found the following while trawling the net moments ago ...

cscript.exe c:\windows\system32\iisapp.vbs [AppPoolName] /r

Now I just need to apply to a remote host.

Cheers,
Cameron

8050.

Solve : Batch file to read a text file?

Answer»

Hi,

I want to run a batch file that will read text file on a file share then if the INFORMATION in the text file does not match what I have set then an msiexec.exe if start a slient install.

What WOULD be the COMMAND to read a text file the search for a certain string of text. Sorry the file I want to read is a dat file not a text file, this HOLDS the version of the software that I want to check