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.

3951.

Solve : answer yes or no?

Answer»

If you have DEL *.* how do you tell TEH batch file you WANT to answer YES to all?If your OS supports it, USE the /Q switch.

3952.

Solve : DOS commands having more than 127 chars, pls help!?

Answer»

Hello Everyone,

I am facing one problem while writing an automation batch program.

I think MS command prompt(cmd.exe/command.exe) allows maximum of 127 characters in a single line of command. I am building some commands dynamically in a batch file and executing it. This batch file runs successfully if number of characters in the dynamic command are <= 127 and fails otherwise. Following is the test scenario:

C:\COBCF3~1>sed -e "s/([Ss][Ee][Ll][Ee][Cc][ \t]*[Ss][Uu][Mm](\(.*\))[ \t]*[Ff][Rr][Oo][Mm][ \t]*[Dd][Uu][Aa][Ll])/Sum(\1)/g" test1.sql

CREATE or replace VIEW vwBrowse1x402x187 AS SELECT(SELECT PartyDetails.Party FROM Parties INNER Join PartyDetails ON Parties.PartyDetailID = PartyDetails.PartyDetailID WHERE Parties.PartyID = PatentMasters.ClientDivision) Division,Sum(PatentExpenses.Amount) "YTD Total"
FROM PatentExpenses INNER JOIN PatentMasters
ON PatentExpenses.PatentMasterID = PatentMasters.PatentMasterID where(DATENAME('Year',PatentExpenses.ExpenseDate) = DATENAME('Year',SYSDATE))
GROUP BY PatentMasters.ClientDivision;

C:\COBCF3~1>rem above command is having 127 characters in it and EXECUTED successfully

C:\COBCF3~1>rem To make command exceed 127 characters, I will increase the characters in the command by increasing the INPUT file name to sed command(dos version of sed)

C:\COBCF3~1>ren test1.sql test12.sql

C:\COBCF3~1>sed -e "s/([Ss][Ee][Ll][Ee][Cc][ \t]*[Ss][Uu][Mm](\(.*\))[ \t]*[Ff][Rr][Oo][Mm][ \t]*[Dd][Uu][Aa][Ll])/Sum(\1)/g" test12.sql
The system cannot execute the specified program.




I know that there is concept of command continuation character in many interpreted command prompts like Unix (\) but I am not aware if such things exist in MS Command prompt as "\" doesn't work for me.

Any help will be highly appreciated.

Thanks in advance.

DG
It's true that early versions of DOS had a 127 byte character limitation. It's equally true there is no continuation character in DOS...just keep typing until you overrun the buffer.

Confused though. I was under the impression that SED was an editor. Are you trying to execute the SQL? Most database programs allow sql statements to come from external files where there is no character limitation.

Let us know. Thanks for your reply.
I am sorry to confuse you
"sed" is string manipulation utility command for MS Dos... its exactly similar to "sed" command in Unix. The SQL scripts you are seeing is the output of the SED command which takes one input file test1.sql and is nothing to do with this command. The content of input file test1.sql could be any text. test1.sql is one SQL Server file GENERATED using some automated script and I need to do some string manipulation before executing that to its target database.
Pls let me know if you can think of any solution.

Thanks for your valuble time and help.

After reading about SED, AWK is a walk in the PARK I couldn't find anything to help you. You might try redirecting a text file with all the parameters into SED but there is no guarantee. Only programs written to accept input from STDIN will accept redirected input.

Good luck. Thanks for the try :-)
Yes, I found alternative to handle this scenario using sed script file. SED can accept commands from a script file where there is no such limit on the number of characters in single command line.

3953.

Solve : BIOS through DOS?

Answer»

Hello,

How do i access the BIOS through DOS?

Is it possible?

Cheers.I'm not AWARE of any. NORMALLY you don't need any OS, just boot the machine and during the POST, there should be an on screen graphic telling you which key to hit to enter SETUP.

Hello,

My only ISSUE is that i access my machines via - either telminal services, telnet or rmeote desktop, that makes it very hard to catch the boot options menu.

Does anyone know if it is possible....../???

3954.

Solve : DOS redirection?

Answer»

I'm running a DOS command from a VB APP using the VB shell command. I WANT to redirect OUTPUT from the DOS command to a LOG file. The DOS command executes with no redirection, but does not execute with redirection. The DOS command is less than 127 char. Any suggestions?Can you give us the command.

That will be more helpful.

3955.

Solve : Monitoring tape mounts?

Answer»

Hi all,

HAAVE been given the task to have a scipt run on servers with a tap unit in them.
At a particular time, the script will (or rather should) report what tape is currently mounted in the drive.

I have no IDEA where I'd start WIH this.

Any suggestions / LEADS / past examples, etc. ??No suggestions ANYONE ??

3956.

Solve : FTP Script Help?

Answer»

I need help running an ftp SCRIPT from within a batch file. When I run the FOLLOWING command from a batch file:

ftp -s:script.txt

I get this error:

'ftp' is not recognized as an internal or external command, operable program or batch file

Can you MANUALLY FTP to the server you wish to connect to?

I.E:
ftp xxx.xxx.xxx.xxx
[enter userid]
[enter passwd]
[connected ??]

Otherwise, you'll need to show what the CONTENTS are of the script.txt file.Yes, that works just fine.Then the cause of your error will be with the content of the scriptfile script.txt.

Can you provide details of this file ??

3957.

Solve : recursive find work around??

Answer»

I am working on a way to find all images used in all my webpages using this to search the files in a directory and print the RESULTS. Ultimately what I would like to do is get a good enough report so that I can do some housekeeping on the image folder.

find /N /i "
[42]
[52]
[69]

<img src="images/firewise.jpg" width=311 height=64 border=0 alt="Fire Wise website">



---------- INDEX.HTM
[35]
[50]


So far this is GREAT for SEARCHING just that SPECIFIC folder. Is there a way to recurse the search so that it penitrates all subdirectories also? All the information I find says you can not do a recursive "find" if that is true can I determine the directory structure with a command before the "find" and then loop until all directories have been gone through? Also is there a way to format the output a little you can see that under INDEX.HTM the tags are right up against the line number ( I like this) but in HOMEFIRE.HTM line 35 and 52 have a space before the tag.yes you can ...

:: clear the logfile
Rem>found.log
FOR /D %A IN (*.*) DO call MyFind %A

(in a batch file, call the variables %%A) -- this will walk the directory tree recursively from the current dir

then create MyFind.Bat
cd %~f1
find /n /i "
Graham
OK after testing it appears to be attempting to step down each time if finds a subdirectory and only at the first subdirectory. It would probably work if I had the directory then just one subdir and then just one subdir inside that and so on. what I have is a main dir with multiple subdirectories that also have multiple subdirectories. I hope this makes since.Ive just had a quick play, change the FOR to read
FOR /D /R .........

the /R means recursive, sorry I thought the /D would have done that

Graham
3958.

Solve : Where do FTP files go??

Answer»

Hi, I used the DOS command to FTP files into my computer and am WONDERING where the files go? It said the transfer was a success but when I did a search on my computer it didn't findy anything. Thanks.They go to the current working directory

fire up FTP then type in
LCD
that will tell you where the files were dropped ... just ran ftp from the Run dialog and it shows
Local directory now C:\DOCUMENTS and Settings\

GrahamGraham,

Thanks so much for your reply. That help show me where they went. I have another question, how do you change the location?? Thanks again

-ChristyThats easy, use LCD again, its just LIKE the CD command, so for example
LCD "C:\My Data\Downloaded Files"
Graham

3959.

Solve : Run shutdown from a flash drive??

Answer»

I tried this on some of the computers at work today without much success!

I wrote a .bat that the last line is:

Code: [Select]shutdown -s -c "Please varify all of the data. The COMPUTER will shutdown in 30 seconds."

It only worked on two out of 18 XP MACHINES and zero of our 2000 machines. I found that if I copy the command to the desktop, it works!

But since it's written at the end of a long list of commands, this just doesn't work for me! I guess I can have my origional .bat copy a shutdown.bat to the desktop, call it, then delete it. But what is the nature of the shutdown command? Does it call a .dll? Could I copy that .dll to my FLASH drive and call it there? Will that work for XP and 2000 machines alike?Maybe the 2ks need a reg patch.......with what you have got.........save the files to a a hardrive on a server.Well, the problem is the computers that I run this on change weekly so there is no CENTRAL server. It has to be run on a flash drive.

Thanks for the reply though!try another bat script


http://www.robvanderwoude.com/index.htmlCould it be as simple as changing it to...

%sysroot%\system32\shutdown.exe -s -c "Please varify all of the data. The computer will shutdown in 30 seconds."

?I don't think so,

That path will be in the path variable itself.

Does a error come, or it simply ignores that command.There is no error, it just keeps calling it over and over until I close the WINDOW or just doesn't exicute it. I worked arround the problem with this:

Code: [Select]copy \Programs\DataCollection\Shutdown.bat C:\
call c:\Shutdown.bat
del c:\Shutdown.bat

I wonder if I copied %sysroot%\system32\shutdown.exe to my thumb drive, could I get it to work on a 2K machine . . .

I'll try and let you know!It doesn't run on either XP or 2K!Let me repeat.

It works in XP.
In 2000 it doesn't work whether its at the end of file or a simple line written somewhere.

But if you copy that file to desktop it works.
With that complex file also?

Correct me if i am wrong.

3960.

Solve : Totalling in Bat Files?

Answer»

In my bat file, I am copying print files to a directory. I need to count each time I log an entry of a file that was COPIED to that directory. Is there a way in DOS, via the BAT file that I can take a running total of the files and update the log file with this total? I know that you can perform a CALL to a subroutine, but is there a DOS total function that I can make a CALL to?Without knowing your OS, you may be able to use the set /a batch command. This will allow you to do simple integer arithmetic.

If you are using a wildcard in your copy there would be no way to intercept and count each file.

You don't need a subroutine, you can use inline code. You can use redirection to push the total into your log file.

There is no built in DOS total function. Get back to us if you need more info, but mention your OS and POST your batch file.

Hope this helps. Won't using a simple LOOP will server your purpose.

Just increment your counter in the loop.We are using Windows 2003 server. You certainly brought something to light that I totally forgot and that is that we are copying globally. We could actually be copying more than one file at a time. Anyway, if you can, will you please provide a code example on how you would use the set /a command and the code to add to the counter for a batch file. I would appreciate it since I am not a DOS programmer.

Also, Vibhor mentioned using a simple loop, just increment the count in the loop. Can you provide an example?
Thank you so MUCH. Ernest.This simple loop, which I posted earlier to another user, will provide a loop and count arguments passed to the batch file

Code: [Select]
@echo off
set count=0
:start
if .%1==. goto next
set /a count=%count%+1
shift
goto start
:next
echo %count% arg(s) were passed


As mentioned global copies are not practical. You would only count the number of copy statements executed not the number of files. As with any loop, you must provide a way to exit.

In a Win2003 environment, a script would be more practical, easier to read, and you would have more control over what does and does not get counted.

Hope this gives you some ideas you can use to customize to your environment. Sidewinder,
Thank you so much for your help. I think you are correct. I will do this in VB and call it. However, since we do use DOS in our production cycle, I can probably use your example further down the road. Again, thanks for your help. We do appreciate it. Ernest.

3961.

Solve : batch file - internet explorer?

Answer»

hey,
im trying to schedule my internet explorer to activate its home page.....
on that home page requires me to select an option in two different DROP down menu's and to put my username and password in..........

the site is https://education.computerpower.edu.au

I want to try and log in automatically when im at work or without a pc.......

can anyone help me please..... You need a script for this not a batch file:

Code: [Select]
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Navigate "https://education.computerpower.edu.au "

Do Until objIE.Busy = False
WScript.Sleep 100
Loop
objIE.Visible = True

theForm = objIE.Document.GetElementsByName("frmAuthenticate")
With theForm
.loginaccess.Value = "STUDENT"
.servername.Value = "???????"
.username.value="youruserid"
.password.value="yourpassword"
END With
theLink = objIE.Document.GetElementsByName("SUBMIT")
theLink.Click()


Use the Windows Task Scheduler to run your script.

Note: Change USERID and password to something valid. I could not find a valid server name and the loginaccess I just whimsically picked a valid value. In case you're wondering, you need to view the page source of https://education.computerpower.edu.au and get valid values.

Hope this helps.

3962.

Solve : Create file with current date?

Answer»

I have a batch file which creates a directory named, Backup. I would like INSTEAD to create a directory named the current days DATE so that each day it is RUN the data goes into a new directory. How can I do this?You never MENTIONED an OS but this work on most of them:

Code: [Select]
@echo off
for /f "tokens=2-4 delims=/ " %%a in ('date /t') do (
set mm=%%a
set dd=%%b
set yy=%%c
)


Once you have the variables, you can use them as you wish. Example md %mm%%dd%%yy% will make a directory with today's date. Use your imagination.

Hope this helps.

3963.

Solve : y-splitter serial cable?

Answer»

We are RUNNING on a DOS system for our stores and we are INSTALLING new scanners. However, we have about 33 stores that have the change machine that use COM2. Our registers only have 2 COM ports and does ANYONE know if we will run into any problems installing this cable or will DOS automatically recognize the extra COM port from the cable? Any help here WOULD be great, so we know what to prepare for.

what server is use........for the hub.....

3964.

Solve : batch file to hibernate?

Answer»

I want to create a batch file that hibernates the computer as SOON as the user logs off from computer....OS= win2k Professional, SP4, PC is on a domain, administrator PASSWORD is known to me.......help...anyonerundll32.exe PowrProf.dll, SetSuspendState

It's something LIKE that... SEE here for more info: http://www.pcmag.com/article2/0,1759,1722737,00.asp

3965.

Solve : msdOs on win xp??

Answer»

im just curious, is there any way that i could access msdOs through a computer running windows XP OS? if so, how could i possibly do so? :-?I think this is possible. With ANOTHER computer I reinstalled WIN XP, and it was possible to run it, but you needed to install something extra for it, i reinstalled windows XP home SP2It DEPENDS what you want to do. For most DOS-like purposes, the command terminal is adequate. If you want to run DOS games though (on an XP MACHINE?!)) you'll need something like DOSBox.

3966.

Solve : search for string in file and remove that line?

Answer»

Hey all,
I am trying to figure out a way to search for a text string WITHIN a FILE, and if found, delete the entire line that it is on. Is there a simple way to do that?
I know that i can use find command from command line, but i dont' think that WORKS within a batch file.
Thanks,
JasonAll a batch file is is a bunch of DOS commands in one, so if it can be DONE from the prompt, it can be done in BATCH.Yeah, i FIGURED that out after i posted. My solution was to do a findstr with /V and >> to another file. i then just copied over the original. Anyone have a better solution?

3967.

Solve : compress of file or folder?

Answer»

In my WINDOWS 2000 servers I am able to cinnect through TELNET
Now I need comman for compress some files & folders pl TELL me in detail

I used compact But its for 1:1

I installed winzip8.0

pl get in DETAILS

3968.

Solve : Deleting folders through logoff?

Answer»

The problem with the for command is that it uses spaces as default delimiter, that's why only C:\Documents is returned when parsing. Two solutions:

1. specify that all tokens are to be returned like this:

for /f [HIGHLIGHT]"tokens=*"[/highlight] %%i in ('dir /a:d /s /b "%userprofile%\Desktop"') do @ECHO.%%i

or 2. change the delimiter to 'no delimiter'

for /f [highlight]"delims="[/highlight] %%i in ('dir /a:d /s /b "%userprofile%\Desktop"') do @echo.%%i

Hope this information is still useful Actually yes this helps a bunch. This worked like a charm. Thanks

Update:
Almost like a charm. After running the script the folder still exists. I modified the one that you posted and changed the @echo part with rd /s /q %%i. The script gives me a "The system cannot find the file specified." message. What am I doing wrong?Try with quotes:

rd /s /q "%%i"
if it still doesn't work, create a dump like this

Code: [Select]for /f "delims=" %%i in ('dir /a:d /s /b "%userprofile%\Desktop"') do echo.rd /s /q "%%i"&rd /s /q "%%i"

and post it to the forum so I can take a look and help.
That go it. It works great now. Just what I needed. Thank you.Now that I have the deleting folders thing down I have just hit another snag. I caught a user saving internet explorer shortcuts to their desktops and my log off scrtipt is not erasing them. I am unsure of what extension I need to use to get these to delete. My script includes *.lnk files but this shortcut is OBVIOUSLY not one of these as it is not deleting. Here is what my script looks like.

cd "%userprofile%"\Desktop\
del *.doc,*.txt,*.xls,*.lnk,*.exe,*.zip,*.jpg,*.jpeg,*.bmp,*.ppt,*.dat,*.mp*,*.rar,*.pdf,*.tab,*.html,*.htm,*.php
cls
cd %userprofile%
rd /s/q cookies
rd /s/q locals~1\history
rd /s/q locals~1\tempor~1

Everything that I attempt to delete does delete so I know that the del part of the script works fine but the internet shortcut does not delete. I can replicate creating the shortcut by going under the File menu in Internet Exploder and selecting Send then choose "Shortcut to desktop".

You all have PRODUCED great results so far so I'm counting on you again.*.lnk should do it, not sure why it wouldn't work :-?Yeah, I'm stumped to. It must be saved with another file extension. Did you happen to try making the shortcut and attempt to delete it. Maybe it does work and I am doing something wrong?

3969.

Solve : Redirecting BAT output to file?

Answer»

This is a newbie question...

How do I REDIRECT ALL the BAT output that normally goes to the screen, to instead go to a SINGLE FILE?

In my BAT file I am executing several different third-party applications, and DOS commands, etc. I WANT everything that goes to the screen now to also/instead go to a file.

Can I SIMPLY wrap my BAT file in another BAT file and make the screen output somehow go to a file redirect somehow? (I did try this with no success using myouterbat.bat >log.txt). That try only sent a reference to each separate command to the file, I need anything thats on the screen to be in the file verbose.

Can I call my BAT file with some other DOS command then redirect the output of that command to a file?

tia
Rick

3970.

Solve : disc tray?

Answer»

hi,

is there a way to open the DISC tray from a batch file?
anyhelp would be appreciated

thanks,I don't know of any batch prog instructions which will ACHIEVE this but there are many free SMALL utilities which will suit, (Google for them). You could then start the utility from within a .bat file to open the tray.

Good luckThere is a way to do this with a VISUAL basic script. If you NEED that, I will try to dig it up.True, but even Norton will halt a .vbs file, when .bat files get no such warning.

3971.

Solve : Mutex?

Answer» HELLO,

I would like to create a mutex in MS DOS .

Does Anybody have an ideas ?? :-? :-?

Thanks

AlmnWhat on earth is a mutex ??
GrahamIt's like Goretex but QUIETER. Mutex - not as daft as it sounds but I haven't GOT a clue how to create one in Dos, Assembler, C++ or any other language/system.

See here....

Good LUCK

3972.

Solve : Running html files from dos?

Answer»

[size=16]I would like to run a html file from a batch file this is the command I am using:

"C:\Program Files\flash items\readme.html\"

but when i run it it just says '"C:\Program Files\flash items\readme.html\"' is not recognised as an internal or EXTERNAL command, OPERABLE program or batch file.

Please Help[/size]You want to "call" the file :

call "C:\Program Files\flash items\readme.html"

Good Luck

AlmnIt still replys with the same error message :-?Quote

'"C:\Program Files\flash items\readme.html\"'

You've entered


"

AND

'

It's just the => " <= you should enter...YES when it replys it puts ' round the file name (i dont actually type it like that!!)Seems to me you are TRYING to Run a file, is it not necessary to Run a program (.exe etc) to DISPLAY a .html file :-?

Maybe something like Start "c:\internet explorer" and somehow point I.E. at the file to be displayed :-?

At the command prompt enter Start/? to see the parameters etc...

3973.

Solve : How to compare two strings in a dos batch file ??

Answer»

I'd like to WRITE a batch file as a login script for ad user.
In my COMPANY, computers are with many windows os version, like windows 98,windows xp,etc.
To decide what to execute, I need to distinguish the operation system of computer that user login from.
May any body give me a HAND ? Thank a lot !If you redirect VER to a file, you can then read the file to DETERMINE the OS version
Graham

3974.

Solve : Bat file renaming?

Answer»

I am trying to find a way to change a single file NAME automaticlly daily with a batch file. I need the file name to include current date while keeping the extension. Can anyone help me with the SYNTAX for the bat file.For that case I think you need to have that file in a seperate folder then you can do this:

ren c:\folder\*.fileextension c:\folder\%time%.fileextension

Hope this works

AlmnQuote

For that case I think you need to have that file in a seperate folder then you can do this:

ren c:\folder\*.fileextension c:\folder\%time%.fileextension

Hope this works

Almn

In the command string the %TIME% is not a vaild syntax is there anything i can do with FOR command?
The following CODE will put todays date in mmddyy format. Just use %currentDate% as the variable. (That is the variable that holds the date) So your code should look SOMETHING like this.

SET dateMonth=%DATE:~4,2%
SET dateDay=%DATE:~7,2%
SET dateYear=%DATE:~12,2%
SET currentDate=%dateMonth%%dateDay%%dateYear%
ren "c:\folder\*.fileextension" "c:\folder\%currentDate%.fileextension"


I didn't test this but i'm pretty sure it will work.
3975.

Solve : Batch File Assistance Needed?

Answer»

I'm trying to write a .BAT file that will ASK for the users imput, then create a directory combining the imput as the new file name along with the system date... ie. 06-04-12_Users Imput

:-?

Any suggestions???

LET %1 be the name of the file to be created. For example, if it was CREATE.BAT, and the user typed "create test", the batch should create a test file (but no extension).

This would require input from the user. So, a batch file could be created that asks for Ctrl-Z to be pressed, and then it could copy con the file.

I am not skilled with dates, but start small. Start with the %1. A sample would be this:

REM - Create.BAT
@ECHO OFF
ECHO PLEASE press CTRL-Z and press ENTER...
COPY CON %1

This would have this outcome:

C:\>Create test.txt
Press CTRL-Z and press ENTER...
^z
1 file(s) copied
C:\>

3976.

Solve : registery?

Answer»

Hello,

I am trying to create a file that checks the presence of a registery key and if it finds it echo yes.
So FAR I came up with that :


@echo off

if exist "hklm\software\microsoft\windows\currentversion\run" /v "avast" (
echo yes
) else (
echo no
)
pause


Any HELP would be apriciated

AlmnIF EXIST is useful for checking the existence of files but not very useful for REGISTRY keys.

Code: [Select]@echo off
reg query "hklm\software\microsoft\windows\currentversion\run" /v "avast"
if errorlevel 1 (echo no) else (echo yes)

Good luck. 8-)THANK YOU

Almn

3977.

Solve : Runing Program Files from a batch file?

Answer»

Hi i would LIKE to create a batch file that will run a specific file. the file is in C:\program Files\
the command i used is start /Dc:\ /max C:\Program Files\MSNmessengerTEST\MSN8\msn 8.exe but it just comes up with an error box saying cannot find "C:\Program" Please help! :-?The space between Program & Files is giving you the problem. Enclose the parameters in double quotes ("params")A possible atlernate solution: Use the CD command to NAVIGATE to the folder, and then simply run it. But that's just a matter of preference. i have just realised that i can just type the file name straight into MS dos and it will run he .exe file but now i have anouther problem when the file launches i want it to be full screen but it is not, is there a way to launch it full screen :-?You're talking about MSN 8, right? Well, if you maximize it once, and close it, it should remember that it's full screen when loaded again. thankyou I'm just curious, but why not a shortcut?Analysis: 80% probability that he is attempting to learn DOS and is using his browser as an EXAMPLE, 5% probability that he just didn't think of that, and 15% probability that he's using this as part of a larger batch file.its part of a larger batch fileWell, that explains that. Feel free to write again if you have any other questions/problems. At least I was partially right; I got the ACTUAL motive in there. Let that be a lesson: Never partner with me in Clue.

3978.

Solve : my computer time error?

Answer»

Hi everyone,

My computer time clock is slower than the right time. I fix it, but about after one month always about 1 hour behind or slower than the actual right time.
1. Does anyone have any idea? pls help me.
2. Regarding with my previous question about BOOTING, i insert reboot flopy disk and try to reboot. But i got the message saying Flopy fail (40). what does it MEAN?

Sincerely,

ArficeuIf you are regularly connected to the internet, use the automatic time ADJUST feature of XP (if that's your O/S - you don't say). Double-CLICK on the clock (bottom right) and click the TAB "internet time".

3979.

Solve : Search?

Answer»

Hi there, I can't really work good with the command FOR under windows xp so if sombody could help me with the following thing I would try to reach (or if somebody have a link to a place where I can learn the command). I want to make a batch file, that search in every file, of the same folder where the batch file is placed in, to the word: "boom" and REPLACE it by "aplle". Can anybody help me pleas? P.S. the extentions and file names doesn't mather, so you can use *.*)This may help you out. If batch language gets any more cryptic than this, I have yet to see it :-/

Code: [Select]@echo off
setlocal enableextensions
setlocal enabledelayedexpansion
for /f %%X in ('dir /a:-d /s /b') do (
for /f "tokens=* delims=" %%i in (%%x) do (
set input=%%i
set input=!input:boom=aplle!
echo !input! > %%x.chg
)
)
endlocal

As far as documentation for the FOR command, type for /? at a command prompt. It's as good as any.

Good luck. 8-)

Note: To keep it simple, I just appended a .chg extension to the file name. You may want to change this.First of all, thanks for the help and the script so far yet. I appreciate your help.

Second, could it be that there is a fault in the batch script. Because when I use the script, the following thing happens (with only one file to replace in the foulder):

The computer makes two extra files, one with as name: filename of the replaced file + extention. (so i get test.txt.txt)
and one, text file, with the same name as my batch file.

I'm still trying to learn the command, but if I may ask you why is the command "setlocal enabledelayedexpansion" in the script.

Anyhow, thanks for the help so far


greetz


Blackberry 8-)The setlocal enabledelayedexpansion allows the user to set an environment variable inside of a block of code and then REFERENCE it inside of the block with the set value.

I tried to keep the solution simple. In the real world the batch file would not be in the same directory (otherwise it gets caught up in the DIR collection of filenames; you would have to reference a path to the directory where the files live) as the files it's acting on. It is also possible to parse the filenames and addon WHATEVER extension you like.

Text files cannot be opened as input output which explains why you end up with separate output files. The original files remain unchanged.

Good luck. 8-)Sidewinder's script snippet will replace boom with apple but will also remove all empty LINES from the files. If this side effect needs to be avoided then replace

for /f "tokens=* delims=" %%i in (%%x) do (

with

for /f "tokens=1,* delims=]" %%h in ('"find /n /v "" "%%x""') do (

Hope this information is useful

3980.

Solve : press 1 to exit, press 2 to continue!??

Answer»

How could you make a batch file that would "goto" a label if a certain key is pressed?
(I am doing this for making backups. I am going to make it so I can choose to make backups of different things) :-/Code: [Select]:begin
set /p var=Type 1 or 2>
If '%var%'=='1' GOTO 1
If '%var%'=='2' GOTO 2

ECHO Incorrect answer
GOTO begin

:1

:2thanks!It doesn'tseem to be working! :-/ :-?Try adding this right above the "set /p var":

Code: [Select]set var=
so it should read

Code: [Select]@echo off
:begin
set var=
set /p var=Type 1 or 2:
If '%var%'=='1' GOTO 1
If '%var%'=='2' GOTO 2

ECHO Incorrect answer
GOTO begin

:1

:2
Copy that into notepad and save it with a .bat extension. Find cool simple menu here: http://dostips.cmdtips.com/DtTipsMenu.php

Consists of the generic main loop that parses the batch file itself for menu labels:

Code: [Select]:menuLOOP
echo.
echo.= Menu =================================================
echo.
for /f "tokens=1,2,* delims=_ " %%A in ('"findstr /b /c:":menu_" "%~F0""') do echo. %%B %%C
set choice=
echo.&set /p choice=Make a choice or hit ENTER to quit: ||GOTO:EOF
echo.&call:menu_%choice%
GOTO:menuLOOP
Then you can add self descriptive menu functions as code blocks like this:

Code: [Select]:menu_1 Do some copy
echo.do some copy
GOTO:EOF

:menu_2 Do some more
echo.do some more
GOTO:EOF

:menu_Q Quit
echo.bye bye
GOTO:EOF

Would show the FOLLOWING menu when running the batch:

= Menu =================================================

1 Do some copy
2 Do some more
Q Quit

Make a choice or hit ENTER to quit:


Enjoy

3981.

Solve : Use output as variable?

Answer»

Is there a simple way to define the output of a dos command as a variable for use in a batch file?
I'll be using both dos622 and the windows nt/xp cmd functions.Yes there is, by filtering the command output thru a FIND command and parsing the results. It would depend on the actual OS and the specific command involved.

Perhaps you could share some details of what you need. 8-)I want to use the output of the time /t command called from a batch to set a variable and then use the variable further on in the batch.
The os at present is dos622 but I woud like it to fit win98 thru to xp.
Im not sure how find is relevent?I'm not sure the /t switch would be valid for all versions of the command processor. What is valid for XP most likely would not work for DOS 6.22 or even Win98.

This little snippet will work on XP:

Code: [SELECT]@echo off
for /f "tokens=1-3 delims=: " %%i in ('time /t') do (
set hh=%%i
set mm=%%j
set meridian=%%k
echo %hh% %mm% %meridian%
)

There may be ways to produce the same result on DOS 6.22 that will also work on XP:

Code: [Select]@echo off
%comspec% /e:2048/c for %%v in (1 2) do prompt set TM$q$t$_ | find/v "$" >{t}.bat
for %%v in (call del) do %%v {t}.bat

for /f "tokens=1-2 delims=:." %%i in ("%tm%") do echo %%i %%j


As you can see, the more current the OS, the easier it gets. 8-)

I don't have my DOS machine available right now, but the LATTER example should work.

THANKS- I'll give it a go. At least Ive got something to play with now.

3982.

Solve : Del Archives?

Answer»

Necessary in ACCORDANCE with deletar archives the date of creation.

Standard of the ARCHIVE: Backup_ddmmaaaa
Operational system: Windows XP

Always that I will be to create a new archive, I have that to deletar oldest. How I make this for the DOS?

Since already I thank the help !

*************************************************************************

Preciso deletar arquivos de acordo com a data de criação.

Padrão do arquivo: Backup_ddmmaaaa
Sistema Operacional: Windows XP

Sempre que eu for criar UM novo arquivo, preciso deletar o mais antigo. Como fazer isso pelo DOS?

DESDE já agradeço a AJUDA!The following code removes the oldest file matching the filter Backup_*.*.
It look for the creation/last modification date of the file rather than for the date in the file name. But I guess it still does what you want:

Code: [Select]set obsolete=
for /f "tokens=*" %%f in ('"dir /b/o-d Backup_*.*"') do set obsolete=%%f
del %obsolete%
Right? I go to test. Thank you!

3983.

Solve : Hacking through DOS??

Answer»

Is there a way to hack through DOS?Just wonderingYes.hummm, thought so, just wasn't sureLMAO

Just out of curiosity, are you LOOKING to hack or to protect from HACKING? If it's the former, we can't help you. If it's the latter, we may be able to ASSIST you. NEITHER, I was really just wondering.

3984.

Solve : textfile contents as batchfile parameter?

Answer»

Dear Alll
i have been searching this subject for a long TIME
please help me ,,
i have created a batch file named test.bat
i have STORED one ip address in a text file
now i want to pass the contents of that text file (namely the id address) as a parameter to test.bat AUTOMATICALLY (or ATLEAST from command prompt in DOS)
pl tell me how to do this
earliest suggestions will be very much appreciated
thanks a lot


Code: [Select]@echo off
if not .%1==. goto SKIP
for /f %%i in (test.txt) do test.bat %%i
:skip
echo %1

This uses recursion to get the IP address from test.txt and then re-enter test.bat with the IP address passed along the command line. Use %1 when referring to the IP address in any code after the :skip label.

Happy Computing. 8-)

3985.

Solve : xcopy and print log file help??

Answer»

Hi,

I have this batch FILES created xcopy d:\backupl g:\backup /e /c /i /f /h /d /y in WINDOWS XP.
The drive letter d: is the partition d: and the drive letter g: is a Firewire external HDD.

I don´t know hi, but in the last week the batch files doesn´t run until he is finishid, but i can´t see the error MESSAGE because the windows close to quickly and i can see...

I think that is possible to put a command file in this batch to write a LOG file to the HDD, and read the log file discoreved the error...?

I don´t know how to do it

Someone can help me please.

Thanks,

MigasMike
xcopy issues error codes that can be checked by a batch file.

0 Files were COPIED without error.
1 No files were found to copy.
2 The user pressed CTRL+C to terminate xcopy.
4 Initialization error occurred. There is not enough memory or disk space, or you entered an invalid
name or invalid syntax on the command line.
5 Disk write error occurred.

Something like this may work:

Code: [Select]xcopy d:\backupl g:\backup /e /c /i /f /h /d /y > file.log
if errorlevel 1 notepad file.log

You may have to use pathnames for the file.log depending where you want to put the log.

Hope this helps. 8-)

3986.

Solve : How do i send a messege through cmd in xp?

Answer»

In win xp run cmd how do i SEND a messege to another computer using code because i see the ping number when i put ping in but i cannot communicate i wish to send a messge to them through cmd baxnet send (domain)-(compnumber) (message)

Assuming you're on a network, of course. Quote

net send (domain)-(compnumber) (message)
Assuming you're on a network, of course.

Of course he'll need to start the Messenger Service first on both computers.

Way 1: If you don't know how to do this GO to Start - Control Panel - Classic View - Administrative Tools - SERVICES, and then select the Messenger Service and start it.

Way 2: Or just type "net start messenger" in a cmd.exe console session.
Oh... right. i have tried this and it is not working :-?What's the error message? :-?I forgot. You might need an administrator account to modify services. :-/it comes up with error 3772 or something like that and i am the administrator so it should work
plus im sending it through a network not the internet so that COULD be why all i know is that every timne i TRY it it just says something eles [ch351]s wrong
Quote
it comes up with error 3772 or something like that and i am the administrator so it should work
plus im sending it through a network not the internet so that could be why all i know is that every timne i try it it just says something eles [ch351]s wrong
Using it over a LAN should be alot easier than over the internet.

Could you tell me exactly what is says? I tried typing "net helpmsg 3772", but that couldn't find it.
3987.

Solve : hms-dos help?

Answer»

I have several cd's for my fids and we keep GETTING the error c:\windows\system32\autoexec.nt. what do i need to doUse the search function in the forum and then read that this is a very common problem, covered every week or so.

Copy the autoexec.nt file from the c:\windows\repair directory and PASTE it into the c:\windows\system32 directory, overwriting the old one.

I don't understand what hms-dos refers to. :-?Quote

I don't understand what hms-dos refers to. :-?

I think he meant to TYPE MS-DOS but the "H" got in there by mistake.
I hope he realizes that MS-DOS has absolutely nothing to do with this either. Maybe he thought it did... Which is no big deal, posts get posted in the wrong place all the time. That's why we got QA MODS.
3988.

Solve : Setting dos variable to file's contents?

Answer»

I've been playing around with batch files, and have a question:
How do you SET a variable to the contents of a saved FILE?
I have figured out how to get keyboard INPUT and save it via copy con.
I would like to get this information (it's only one word) defined as a variable I can work with
within my batch file. Any suggestions would be greatly appreciated.Which OS?

3989.

Solve : For Loop and option ... delims="?

Answer»

Hi all,
Am doing the following...

schtasks /query /s %Server2Chk% /FO CSV /NH /V | findstr /C:"%SearchString%" > %TempFile1%

Sample Output ...
[size=10]"CAMS-LAPTOP","test","15:18:00, 06/04/2006","Could not start","14:02:34, 06/04/2006","0","cyoung","Every 30 minute(s) from 13:18 for 1438 minutes every day, starting 06/04/2006","C:\test.bat ","C:\","N/A","Enabled","Minute ","13:18:00","06/04/2006","N/A","Everyday","N/A","CAMS-LAPTOP\xxx","Disabled","72:0","30 Minute(s)","None","23 Hour(s): 58 Minute(s)","Disabled","Disabled","No Start On Batteries, Stop On Battery Mode"[/size]

Then ... I try to do the following ...

[size=11]for /F "tokens=1,2,3,4 delims="" %%j in (%TempFile1%) do call %0 UpdateTask %%j %%k %%l %%m[/size][/color]

I'd like to have the (") as the delimiter - is it possible? I just don't WANT quotes around the resulting tokens if I'm forced to USE `delims=,`.

Hope that makes sence & many thanks in advance.CameronY,

Use the tilde to trim the quotes, i.e. %%[HIGHLIGHT]~[/highlight]j %%[highlight]~[/highlight]k %%[highlight]~[/highlight]l %%[highlight]~[/highlight]m

for /F "tokens=1,2,3,4 delims="" %%j in (%TempFile1%) do call %0 UpdateTask %%~j %%~k %%~l %%~m

That WORKS, right ?

It's described in the COMMAND reference for the for command: http://dostips.cmdtips.com/DosCommandRef.htm#for

3990.

Solve : Add variable to DOS command prompt title?

Answer»

Is there a WAY to add a varible to the DOS command prompt title in a batch file? I wanted to do something like the following:

set /p var=Enter the name of the file and the .img extension (filename.img):
title The file now being programmed is var into your card

There's a different part of the code that I also wanted to add a VARIABLE to the title:

for /f %%a in ('dir *.img /b') do (set var=%%a)
title The file now being programmed is %%a
I wasn't aware batch files had titles. I'm sure that they can if you REM them in, but... What exactly do you want it to look like?If you use a title statement within your loop, it should work.

Something like this:

Code: [Select]@echo off
for /l %%i in (1,1,10000) do (
title Now Processing %%i
)

Note: Batch files run quick. You may only see the FINAL result! 8-)

The batch file I run is for USERS who are programming pcmcia cards for a vehicle diagnostic tool. The batch file is slow because it waits for user input, one step at a time, then launches an executable program that takes as much as 30 minutes. I was trying to snazz it up a little.

I'll try the code Monday. THANKS.

3991.

Solve : Pinging?

Answer»

Hello,

I KNOW a little bit about MS DOS however I can't SEEM to get how to go a program that pings google.com and if it cannot FIND it (meaning he is not connected to internet ) launch notepad

Any help would be appreciated

AlmnOk, dont ping Google, thats just stupidok,

The point is to ping any adress.

Thank You

AlmnThis may work:

CODE: [Select]ping www.google.com
if errorlevel 1 notepad.exe

8-)

3992.

Solve : Deleting System 32 Through DOS?

Answer»

yeah, pretty straigh forward, can any one give me the command i would need to do this?By far the easiest WAY is to obtain the Inkutils, and use the DD command from those tools (which deletes entire directories). Very useful for this kind of thing.Sorry, I am really DOS retarded...I have no idea what any of what you said means...LOL...can you please explain?The word Inkutils in his post is actually a link. Click there, and download Inkutils. Then do what he SAYS. alright but SEE, I am not trying to remove it from my[/b] computer, but another persons, long story, but yeah i just wondered if there was a line of command that could be entered into DOS through the command prompt that could do this wihtout having to download anything....This can be done with the rd command but why on earth for? The system32 DIRECTORY contains many critical files that keeps Windows happy.

:-?

3993.

Solve : Using copy with 2-word folder names...?

Answer»

How can I use the copy command when the PATH for the file to be copied has FOLDERS with spaces in the names?

Thanks!When using path and/or file names or environment variables that expand to values with embedded spaces, use quotes:

EXAMPLE only:

copy "%userprofile%\Desktop\xxx yyyy.zzz" ....

HOPE this HELPS. 8-)

3994.

Solve : Help with MS-DOS prompt command for "mounting"?

Answer»

Objective: To mount a CD image from drive E: to drive D: in order to play a game.

I have found a mount command for ms-dos but it does not work for some reason. Maybe because the starting point is C:\Documents and Settings\Legend> ? I mean when i use this starting point and type mount with it , it says that it's not recognized as an internal or external command, operation or batch file.

Can anyone please give me the exact command to mount cd image from drive E: to drive D:? (Including the starting point like E:\, or the above one "C:\Documents and Settings\Legend>)

Please give exact command for mounting CD image from drive E: to D:,

Thanks a lot.Try using the subst command to assign a virtual drive letter to a path.

subst [drive1: [drive2:]Path]

Good luck. 8-)Hm.. interesting..IM glad that the "subst" command is not an invalid one but i still have a prob

Can u give me the exact command? i mean i have DRIVES E: and D: and i tried your format and i inserted all the drive letters: "subst [E: [D:]Path] .... But it says invalid parameter E:

By the way i'm using Zdaemon tools..

Can anyone tell me how to make it not an invalid parameter?

Or am i doing the command right ? "Subst [E: [D:]Path]

hmm... Thanks
You never mentioned an OS. I found some commands in an old DOS book (aka: Book Of The Dead) which may be helpful:

The format of the subst command is

subst virtual drive: real drive:\real path

The purpose of this command was to allow the user to substitute pathnames for a drive letter. Many programs in the olden days would not ACCEPT pathnames.

There is also assign. ANYBODY who has ever tried to stuff a 5¼ floppy into a 3½ drive would see the usefulness of this command. ASSIGN has been discontinued in later version of Windows.

Of course there is the always faithful append which allowed the user to string DIRECTORY names to the current directory. This would probably not be helpful in your situation.

In later versions of Windows there is diskpart which can be run from the command line or thru the GUI.

If your D: and E: are real physical drives you may need to use diskpart and simply reassign the drive letters.

Curious though, you mentioned that Zdaemon Tools had a MOUNT command. Can you not use that?

Good luck. 8-)

Note: Assignments made with SUBST, APPEND, ASSIGN do not survive a boot. I'm fairly certain DISKPART assignments will.

Well, drives E: is a virtual one and drive D: (DVD-CDROM) is a physical drive.

I use zdaemon tools in order to mount an image of a pirated star wars battlefront II game i got from a torrent. However, the problem really is , is that zdaemon cant mount cd images on drive D: but it can mount it on drives E: after so (like F:, H:, ect).

I mounted the BFII image on the E: drive using zdaemon tools and ran the game but the game says i need an original cd in order to run it
..A.K.A. i need to get the cd image from the virtual drive E: (i only get this drive when i use ZDAEMON tools) to the physical drive D:.

Is this enough info for u to give me an exact command ? Thx the cd image is called BFII if u need that info jus in case. I mean i hope u can give me one where all the drive letters and paths are like already there and that path part i dont really get either. sorry dam i am newbie at this ms-dos stuff lol.

Again, it might be that i'm putting path as the word..is there something that suppose to be in palce instead of path?
thanks

3995.

Solve : Trying to repair system32 file, MS-DOS illiterate?

Answer»

I'm trying to repair or replace the system32/config/system file on my computer using the Recovery Console, however, I have never used MS-DOS before. I have found a help file to guide me through the process, but as mentioned earlier, I have no clue how to OPERATE my computer in MS-DOS. I do have my Windows XP Home recovery disk. When I am in the MS-DOS Recovery Console, I type in C:\>'cd system32\config' (minus the ') and I get a message saying: The system cannot find the file or directory specified. Am I doing something wrong? If I can't repair the file, then I'm just going to reformat. Any help on this dillema will be GREATLY appreciated!!!

System Information:
Dell Dimension 2350
Intel Celeron Processor
Windows XP Home Edition with Service PACK 1
I have not done a DOS recovery, but Windows XP I know well. Try this (assuming you're at C:\):

CD Windows\system32\configactually, i've tried that too. the only thing that will respond without giving me a message is: 'dir' and 'help'. I have tried accessing MSDOS.SYS from the directory, but it TELLS me that my access is denied. After reading a bit on DOS help, i found out that I have to be logging in as an ADMINISTRATOR(?). How would I do that in DOS?

3996.

Solve : Ipconfig batch file?

Answer»

I want to create a batch file to CONFIRM a users IP ADDRESS, can this be done and how?Quote

I want to create a batch file to confirm a users IP address, can this be done and how?

You didn't said your OS. But I ASUME that your working under windows XP. Than you can do this by the following code


Code: [Select]@echo off
ipconfig
pause
3997.

Solve : Dos to Windows?

Answer»

Hello all,
My Win98 pc has opened in DOS and I can't get back to Windows. The monitor says:
Invalid COMMAND.COM
Enter correct name of Command INTERPRETER (eg, C:\COMMAND.COM)

after every thing I've typed in- I've tried C:\Win, exit, and nothing works
Any help/advice would be most welcomedDownload a Win98 bootdisk (For the appropriate one - Win98 OR Win98 Second Edition) at www.bootdisk.com and RESTART the MACHINE after you have created the floppy by ouble CLICKING on the file.

From the a:> type

sys c:

and press enter. Reboot and tell us what happens.Hi, thanks for your reply-a friend pointed out something which I don't know is relevant-
When the pc is turned on, the screen flashes on the Windows98 logo, and then goes to a black screen, w/ the words "Windows 98 is now restarting", followed by "this driver is provided by,,,", and then the stuff about Command.com- so I'm not sure that I am actually in DOS, or what- still think I need to reboot?Did you follow the above suggestion?

3998.

Solve : Boot disks and System Restore?

Answer»

I recently decided to do a System Restore because my scanner and printer and SEVERAL other things are being wiggy. When it was finished it kept freezing on a certain page of System Restore and after a while it stopped GOING to that page at all and TOLD me that the system wasn't properly installed and I have to do that. I don't have the boot cd that came with my computer (no IDEA where that WENT) so I decided to make a boot disk myself.

Is that going to fix my problem?

Ok.. I know how to make a boot disk, and because my computer died I went to the school library and made on there. I get home, put it in, and turned my computer on... it takes me to DOS and the A:\>... but then I realized I had no idea what to do after that. Oops.

So, also. If making a boot disk will save me, how do I run it?You didn't specify what operating system you're using so I'll guess Windows XP. A single boot disk will be of no help. There is a six diskette set that willget you going, BUT if your system has no recovy data usable there uis no point. Time to find your XP CD!

3999.

Solve : get result of std out and set to env var?

Answer» HEY all,
I am trying to write a bat file that gets the output of an exe that would normally print its data to the screen and use the result to SET an env variable.
This is the example
C:\progs\readReg.exe THIS_VAR would result in C:\thisVAR
but what i want is basically this
set ENV_THISVAR=C:\progs\readReg.exe THIS_VAR .
obviously, ENV_THISVAR gets set to C:\progs\readReg.exe THIS_VAR

Please help,
Thanks,
JasonI'm not really clear on what you're asking. As FAR as I know a batch file stores it's own name (%0) and it's parameters (%1-%9) but it's the command processor that keeps track of any executables that the batch file actually runs.

A VBScript can be constructed to capture and process a program's output, but of course the information you're looking for would have to be included in that data.

More info on the output of readReg.exe might be helpful.

Let US know. 8-)Jason,

This is what you want:

Code: [Select]for /f "tokens=*" %%a in ('"C:\progs\readReg.exe THIS_VAR"') do set ENV_THISVAR=%%a
echo.%ENV_THISVAR%
Right?
THATS exactly what i was looking for. Thanks a ton DosItHelp!
4000.

Solve : Batch file for USB applications?

Answer» OKAY so HERES what happens. We connect a camera to the usb, it automatically uploads images to a FOLDER located on the desktop. Is there a WAY to MAKE a batch file so that when the camera is connected, all the old files in the folder are automatically deleted after detection of device activity?