25 Interview Question Set For Microsoft DOS in Microsoft

27
1. Solve : Close The Current Program With A Batch File? Preffered Answer: I'd like a way, if possible, to close the current running program through a batch file. I don't think the kill.exe (run the kill eh?) tool can do this as the program to be CLOSED will vary. It doesn't need to be fancy, it just needs to close whatever is running, which will be the only visible window. Thanks in advance for any help.I know Taskkill can end processes. For example, if you have notepad OPEN, taskkill /im notepad.exe will close it.Taskkill ALSO doesn't work for my needs, as as far as I am aware the program itself needs to be specified. I can't specify the program as it will vary. By the way, this isn't homework, although it is starting to SOUND like it huh? Quote By the way, this isn't homework, although it is starting to sound like it huh? Is everyone getting PARANOID? I doubt you can do this in batch. In fact even using the Windows Shell, you can only kill Explorer windows. One solution would be to use Word (don't ask) which can enumerate the open windows and more importantly close them. Code: [Select]Set wd = CreateObject("Word.Application") Set colJobs = wd.Tasks For Each job In colJobs If job.Visible = True And job.Name <> "Program Manager" Then colJobs(job.Name).Close End If Next wd.Quit Save with a vbs extension and run from the Windows run box as wscript scriptname.vbs. Use a path to the script if necessary. Good luck. Wow, that was more effective than I thought, I neglected to close what I had open because for some for some reason I expected it to fail, things like this usually don't work for me. That's great, just what I need. Thanks a lot Sidewinder! 2. Solve : Connecting To Unix? Preffered Answer: Hi, I'm trying to CONNECT to unix machine and tranfer(FTP) some FILES from my local to somewhere in unix machine. Can you please advice.. 25 Interview Question Set For Microsoft DOS in Microsoft Copyright © 2022 https://interviewquestions.tuteehub.com

Transcript of 25 Interview Question Set For Microsoft DOS in Microsoft

1. Solve : Close The Current Program With A Batch File?

Preffered Answer:

I'd like a way, if possible, to close the current running program through a batch file.

I don't think the kill.exe (run the kill eh?) tool can do this as the program to be CLOSED will vary.

It doesn't need to be fancy, it just needs to close whatever is running, which will be the only visible window.

Thanks in advance for any help.I know Taskkill can end processes.

For example, if you have notepad OPEN, taskkill /im notepad.exe will close it.Taskkill ALSO doesn't work for my needs, as as far

as I am aware the program itself needs to be specified.

I can't specify the program as it will vary.

By the way, this isn't homework, although it is starting to SOUND like it huh? Quote

By the way, this isn't homework, although it is starting to sound like it huh?

Is everyone getting PARANOID?

I doubt you can do this in batch. In fact even using the Windows Shell, you can only kill Explorer windows. One solution would be to

use Word (don't ask) which can enumerate the open windows and more importantly close them.

Code: [Select]Set wd = CreateObject("Word.Application")

Set colJobs = wd.Tasks

For Each job In colJobs

If job.Visible = True And job.Name <> "Program Manager" Then

colJobs(job.Name).Close

End If

Next

wd.Quit

Save with a vbs extension and run from the Windows run box as wscript scriptname.vbs. Use a path to the script if necessary.

Good luck. Wow, that was more effective than I thought, I neglected to close what I had open because for some for some reason I

expected it to fail, things like this usually don't work for me.

That's great, just what I need.

Thanks a lot Sidewinder!

2. Solve : Connecting To Unix?

Preffered Answer:

Hi,

I'm trying to CONNECT to unix machine and tranfer(FTP) some FILES from my local to somewhere in unix machine. Can you

please advice..

25 Interview Question Set For Microsoft DOS in Microsoft

Copyright © 2022

http

s://i

nter

view

ques

tions

.tute

ehub

.com

Unix machine name : uwsst10

path : /usr/local/files/

I don't want to enter the path everytime after I connected to unix machine to FTP the files. I just wanted to encode the same path in

my batch script so it will automatically change the path after we connected to unix machine.

I have code LIKE this.

e:

cd GPS_TEST\Tags\RPT1.txt

ftp uwsst10

After we enter the USERNAME and password it should automatically change the path to "/usr/local/files/" and then FTP the files for

us..

3. Solve : Inserting Blank Lines In A Set Of Text Files?

Preffered Answer:

Hi,

This being my first ever post, i would want to ask for some help with Dos/Batch file.

I have a set of 20 files in a Folder in my C Drive.

these files are plain text files, i want to add a Blank line at the end of these files.

I want to create a Bath file that can open these files and insert the Blank line at the end n save the file.

Is it possible? please help me out.. im a total newbie in this field..

Thanks alot for your help.can someone please help me out.. i really need to get this working

DAILY i have to edit 20 files or more.. If all you need is a blank line on the end of all files in a folder then type this in at the command

line

Code: [Select]For %A in ("*.*") do Echo. &GT;> %A

explanation available on request! Quote from: gpl on August 03, 2010, 05:01:01 AM

If all you need is a blank line on the end of all files in a folder then type this in at the command line

Code: [Select]For %A in ("*.*") do Echo. >> %A

explanation available on request!

Hi, thanks alot for ur reply.. yes for sure i would want an explanation as im not much into scri[pting so i really dont knw how to go

about doin this.

please assist me.I get the impression that you are not sure even how to get to the command prompt ?

In the start menu, click on Run and then enter cmd and press return. If you find yourself using the command prompt a lot, then there

25 Interview Question Set For Microsoft DOS in Microsoft

Copyright © 2022

http

s://i

nter

view

ques

tions

.tute

ehub

.com

is a useful microsoft tool that adds a new option to the right-click contect menu in windows explorer called 'Command Prompt Here'

which opens up a command window in the selected folder http://gallery.technet.microsoft.com/ScriptCenter/en-us/d50e36fd-0454-

4df1-aa35-3416f44789cc however as even microsoft do not guarantee this for VISTA or win 7, I would hold off for now.

When the command window opens, you need to go to the folder that you wish to process the files in:

Code: [Select]cd /d "x:\PATH\to my files"the x: refers to the disk drive the files are on (if a network drive, it needs to be mapped to a

drive letter) and \path\to my files refers to the folder on the drive that contains the files. the quotes around the drive and folder name

are important if the path might contain spaces, it doesnt hurt to include them. CD is the command to change directory (folder) the /d

parameter tells it to change the drive too.

Now for the command I told you to type in ....

the first PART

Code: [Select]For %A in ("*.*") dosets up a loop to look at all of the files in the current folder (thats the *.* part). The %A is a variable

that for each iteration will hold the filename.

The last part is what we do with each file

Code: [Select]Echo. >> %AEcho is used to send a message to the screen, however you can send the message to a file (or the

printer or comm port) by using the > and >> 'redirection' symbols.

> will replace the file, while >> tacks the message on to the end.

Echo on its own give the (not very) useful message 'Echo is on' - or off. Adding the dot to the end makes it send a blank line

And thats all there is to it. I recommend that you try stuff out, read the various help guides on this site and others and come back

when you are stuck.

Good luck

Graham

Thanks alot gpl

It has solved my problem!To follow up my previous post, I have stumbled across this with regasrd to opening a command window in

Vista and I assume Win 7 also

"Open Command Window Here" in Vista

It is now easy to open a command prompt referenced to a folder of your choice in Vista. If the Shift key is held down while right-

clicking a folder, the context menu will contain an entry, "Open Command Window Here". Selecting this entry will open a command

prompt with the chosen folder as the reference point for commands.

You live and learn!!

4. Solve : Xcopy Error Report To Txt File Help.?

Preffered Answer:

I am copying large amounts of files to different servers using the following command

Code: [SELECT]XCOPY  *.* "\\192.168.1.99\C$\Test Folder" /EXCLUDE:copyfiles.cfg /s/y/z/v/k

How can I output individual file errors to a LOG.TXT file?

Currently I have this, but i need more detailed info of what was not copied. not just that an error occurred withing the 100+ files

copied. I WANT to know what files were not copied.

Code: [Select]if errorlevel 4 echo "An error has be found" && echo. Please check the log.txt file. && echo %date% %time%

25 Interview Question Set For Microsoft DOS in Microsoft

Copyright © 2022

http

s://i

nter

view

ques

tions

.tute

ehub

.com

Insufficient disk access, space, on Serve 1>> .\LOG.TXT

if errorlevel 5 echo echo %date% %time% Disk WRITE error occurred on Server 1>> .\LOG.TXT

I havent used xcopy much, but if it outputs errors to the screen, you can CAPTURE them with

Code: [Select]XCOPY  *.* "\\192.168.1.99\C$\Test Folder" /EXCLUDE:copyfiles.cfg /s/y/z/v/k > LOG.TXT 2>&1which copies both

'normal' and error messages

5. Solve : Deleting Folder Based On Name?

Preffered Answer:

I am running batch FILES to create directories and backup selected files to those directories. The directories are named based on

the date (ie. 09212005).

Is it possible to create a batch file to run and delete certain directories if they are say 15 days old? Somehow perform a less than

compared to todays date.

An example WOULD be APPRECIATED greatly!

Thanks so much for your help.DOS batch does not do date arithmetic unless you are prepared to write a boatload of IF statements.

Windows Script is an option but need more info. Are the directory names the actual dates created? and what version of Windows

are you using?

Get back to US.

The folders would have a name such as:

09212005

and I am using Windows XP Prof, any help would be greatly appreciated. There isn't a utitily for windows that would do something

like this is it?

6. Solve : Partition Resizing Command In Win98 DOS?

Preffered Answer:

what is the command for resizing the partition in WINDOWS98 DOSFor resizing partitions you NEED partition magic.

"Fdisk" can only create and delete partitions.

uliQuote

For resizing partitions you need partition magic.

"Fdisk" can only create and delete partitions.

uli

Not neccessarily : From our VAST KNOWLEDGE Base...

See HereThanks for the link. I didn't KNOW the scripting possibility.

25 Interview Question Set For Microsoft DOS in Microsoft

Copyright © 2022

http

s://i

nter

view

ques

tions

.tute

ehub

.com

uliYou're Welcome, uli.

7. Solve : Output .csv File In Windows Format?

Preffered Answer:

I run a batch file that kicks off Oracle Discoverer, runs a workbook with multiple SHEETS and then outputs the sheets to my PC. My

GOAL is to output the files in Excel ".csv" format. My problem is, it's defaulting to MacDOS ".csv" format versus Windows DOS

format. Is there a specific COMMAND in my batch file I can add to FORCE the output file to Windows format?

8. Solve : MSDOS PROBLEM???

Preffered Answer:

I get this POP up on alot of things i try to INSTALL and im REALLY CONFUSED here, someone please help me.

http://support.microsoft.com/default.aspx?scid=kb;en-us;324767

9. Solve : Copy File To An Unknown Folder Name?

Preffered Answer:

I am trying to copy a file to another directory from a batch file but the problem I am having is that part of the directory path will

change.

For example one of the folder names in the path will be 1w2e3.default and on another MACHINE it could be 1wed45.default. The

folder name always has .default at the end so I need to know if there is some kind of wild card you can USE for the beginning of a

folder name.

Any ideas?My guess is that you would need to know which machine the output is going to and then hardcode the output directory

accordingly. Is there SOMEWAY you can distinguish one machine from another?

An easy trick is to put a zero byte file on each machine with a file label that will indicate which machine is which. Your batch file can

then query the file label and determine which output directory is appropriate.

Good LUCK. 8-)chris_cs,

Piping the DIR command through FINDSTR and PARSING the output with the FOR command may help.

FINDSTR allows some kind of regular expression.

Code: [Select]set parentfolder=<foldername with *.default folder in it>

for /f "tokens=*" %%a in ('"dir /b "%parentfolder%"|findstr ".*\.default""') do set folder=%%~fa\

echo.%folder%DOS IT HELP? Tried the For statement and it worked like a dream!!!

Thanks for the help chris_cs,

Actually it can be simplified:

Code: [Select]set parentfolder=<foldername with *.default folder in it>

for /f "tokens=*" %%a in ('"dir /b *.default"') do set folder=%%~fa\

25 Interview Question Set For Microsoft DOS in Microsoft

Copyright © 2022

http

s://i

nter

view

ques

tions

.tute

ehub

.com

echo.%folder%

10. Solve : Undelete?

Preffered Answer:

Hi & thanks in advance for any advice provided.

In the old days the COMMAND undelete [drive:][path] *.* could bring back the dead and deleted. What do we do to bring back

trashed files in 2k (nt5.0)? Note in this case the files were emptied from the recycle bin ALSO.  I heard "recover" maybe but how do

you use it? Also I would like to check if a text string is still there but Find with the following path does not seem to work:

 Find "text string" c:\documents and settings\[user]\*.*    

the above seems to NOT find "documents"      

then "settings" as though that is what I was looking for.  

The origin of this is that we deleted a .pfc file which is AOL's address book (they dont have a copy of this ONE on their server). Is

there any way we can get back the address book contents? We have NOT installed any additional  programs nor have we written

and/or saved anything.  

EVEN IF WE COULD GET BACK SOME CONTENTS!!!!! it would be greatly appreciated because of the valuable CONTACTS

therein!!  thanks again

Al

    If it has been emptied from the recycle bin then you may be SOL.

Keep in mind that the more the machine is used, the greater the chance that the affected part of the hard drive will be writeen over.

Do not defrag! This may help, but other than that you would be looking at some VERY expen$ive data RECOVERY - hundreds of

dollars. I don't know what the info is worth to you, though.

http://www.google.com/search?hl=en&sa=X&oi=spell&resnum=0&ct=result&cd=1&q=free+data+recovery+software&spell=1

11. Solve : Updating Bios?

Preffered Answer:

i NEED to update bios to ACCEPT 160gb h/d how do i do it and is it fairly simple it is a ASUS m/b a7a266 can u HELP please

http://www.asus.com/support/download/download2.aspx?item=A7A266&type=like&file_type=BIOS

12. Solve : .bat Send File?

Preffered Answer:

How can i send a file with .bat to other comp moast easy copy test.txt \\standby\c\test.txt

This command just copied the TEST.TXT file from my local machine's current directory to my machine named STANDBY, the

shared drive C, and named it test.txt there too.

25 Interview Question Set For Microsoft DOS in Microsoft

Copyright © 2022

http

s://i

nter

view

ques

tions

.tute

ehub

.com

Just like a local copy with network path as the destination.but cant you just send it like e-mail to ip? :-/how can i copy 2 txt's in to

one? with  batch?and how can i USE choice?? How about you state your PROBLEM FULLY and in complete sentences.  It's pretty

hard to offer a solution without knowing what the real problem is.   Quote

how can i copy 2 txt's in to one? with  batch?

copy file1+file2

Can be run from the command line or a batch file

Quote

and how can i use choice??

Choicei've got lots of problems, choise doesnt seem to work on xp, and "can not FIND file C:\text.txt+C:\text2.txt"How can i send a

file with .bat to other comp moast easy?

- i would recommend ftp or if you're on a network, put it on a share drive(either one can be done throught batch files

how can i copy 2 txt's in to one? with  batch?

-easy, create a batch file and put this command in it

"type test.txt >> test2.txt"

every time the batch file is run,  the contents of test.txt are added to test2.txt

13. Solve : Dos:Unable To Call Multiple Bat Files From Single Bat File?

Preffered Answer:

I am trying to CALL the bat file(main.bat) which contains 2 bat files(first, second and first bat files internally calls multiple bat files

and outputs that to a file(also echos) and second bat file reads that file and calculates the total and echos back to the dos

so when I execute the main bat file, it is executing the first bat file and giving the results, but the second bat file I dont see it is

executing as it is not echoing any results.

Following is the code of the main bat file

D:\DAT\SAS\DMT\Lev1\SASMain\Data\MAMisc\MAbatch\jobs\old_Campaign_DB_Person al.bat --- first bat

call D:\DAT\SAS\DMT\Lev1\SASMain\Data\MAMisc\MAbatch\jobs\Count_db_pers.bat----second bat

Can some body please help me on this?

In the code you posted, control is passed to the first batch script, but you did not use CALL, so therefore control will never return.

Thankyou..I have tried with the Call, but still it is not working.. following is the code for the bat files..

Following is the code of the first bat file...

setlocal

REM *********************************************************

25 Interview Question Set For Microsoft DOS in Microsoft

Copyright © 2022

http

s://i

nter

view

ques

tions

.tute

ehub

.com

REM * Rundate 'D'YYMMDD must be SPECIFIED as first argument *

REM *********************************************************

REM *********************************************************

REM * Command-file must exist *

REM *********************************************************

FOR /R D:\DAT\SAS\DMT\Lev1\SASMain\Data\MAMisc\MASched\jobs\DB_Personal\ %%G IN (*.bat) DO start /b "call

D:\DAT\SAS\DMT\Lev1\SASMain\Data\MAMisc\MASched\jobs\DB_Personal\" %%G

set rc=%errorlevel%

REM *******************************************************

REM * Exit script and report return code *

REM *******************************************************

:done

echo rc=%rc%

exit /b %rc%

REM *******************************************************

REM * Handle argument errors *

REM *******************************************************

:noargument

echo Error: No argument specified

set rc=2

goto done

:nopgm

echo Error: Command file "%sch_command%" does not exist

set rc=2

goto done

Following is the code of the second bat file.

echo off & setLocal enableDELAYedexpansion

set toterrors=

set totjobs=

for /f "tokens=1 delims= " %%a in (D:\DAT\SAS\DMT\Lev1\SASMain\Data\MAMisc\MASched\jobs\count\count.txt) do (

set /a toterrors+=%%a

)

for /f "tokens=2 delims= " %%b in (D:\DAT\SAS\DMT\Lev1\SASMain\Data\MAMisc\MASched\jobs\count\count.txt) do (

set /a totjobs+=%%b

)

echo total errors is !toterrors!

echo total jobs is !totjobs!

goto :eof

I am sorry but you have a needlessly complicated problem.

You are using D:\DAT\SAS\DMT\Lev1\SASMain\Data\MAMisc\MASched\jobs\DB_Personal\

25 Interview Question Set For Microsoft DOS in Microsoft

Copyright © 2022

http

s://i

nter

view

ques

tions

.tute

ehub

.com

Better to use

Code: [Select]D:\DAT\SAS\DMT\Lev1\SASMain\Data\MAMisc\MASched\jobs\DB_Personal\

INFINITELY better to alter your problem and the code for which you need help by using

Code: [Select]D:\DB_Personal\

You seem to have a problem involving CALL and START.

Why do you confuse the whole situation with the complication of

FOR /R ...... %%G IN (*.bat) DO .....

Finally, this code fragment is ludicrously wrong

Code: [Select]DO start /b "call D:\DAT\SAS\DMT\Lev1\SASMain\Data\MAMisc\MASched\jobs\DB_Personal\" %%G

As Sidewinder has already pointed out in your simultaneous topic on this same horrible code,

you should use start or call, but not both.

REGARDLESS of all the previous horrors, buried at the end of all the needless verbiage, is the SPACE character, i.e.

Code: [Select]D:\DAT\SAS\DMT\Lev1\SASMain\Data\MAMisc\MASched\jobs\DB_Personal\" %%G

I think you might have better luck with

Code: [Select]"D:\DAT\SAS\DMT\Lev1\SASMain\Data\MAMisc\MASched\jobs\DB_Personal\%%G"

Alan

Quote from: ALAN_BR on November 21, 2010, 10:02:35 AM

You are using D:\DAT\SAS\DMT\Lev1\SASMain\Data\MAMisc\MASched\jobs\DB_Personal\

Better to use

Code: [Select]D:\DAT\SAS\DMT\Lev1\SASMain\Data\MAMisc\MASched\jobs\DB_Personal\

INFINITELY better to alter your problem and the code for which you need help by using

Code: [Select]D:\DB_Personal\

True, but chances are the file system arrangement is beyond their control. You can't just say "Because it is easier for me, everybody

must store their files in this particular arrangement" in a company.

Quote

Why do you confuse the whole situation with the complication of

FOR /R ...... %%G IN (*.bat) DO .....

Probably because that was in his batch file.

Quote

Finally, this code fragment is ludicrously wrong

Code: [Select]DO start /b "call D:\DAT\SAS\DMT\Lev1\SASMain\Data\MAMisc\MASched\jobs\DB_Personal\" %%G

As Sidewinder has already pointed out in your simultaneous topic on this same horrible code,

you should use start or call, but not both.

It works fine. It looks like they were trying to run the various batch files asynchronously, but because /b was specified they all end up

waiting on each other for the console anyway.

Quote

25 Interview Question Set For Microsoft DOS in Microsoft

Copyright © 2022

http

s://i

nter

view

ques

tions

.tute

ehub

.com

REGARDLESS of all the previous horrors, buried at the end of all the needless verbiage, is the SPACE character, i.e.

Code: [Select]D:\DAT\SAS\DMT\Lev1\SASMain\Data\MAMisc\MASched\jobs\DB_Personal\" %%G

I think you might have better luck with

Code: [Select]"D:\DAT\SAS\DMT\Lev1\SASMain\Data\MAMisc\MASched\jobs\DB_Personal\%%G"

it works either way.

Quote from: BC_Programmer on November 22, 2010, 02:09:34 PM

True, but chances are the file system arrangement is beyond their control. You can't just say "Because it is easier for me, everybody

must store their files in this particular arrangement" in a company.

Probably because that was in his batch file.

I accept that he cannot stipulate the paths that are used company wide,

but he SHOULD have the ability to compose a very concise file path with which to explore how to call / start bat scripts.

I find extremely verbose scripts to be a pain and tend to obscure any tiny (but significant) code error.

I always prefer to have a small script with the one feature that does not work for me,

and only after learning how to use it will I go back to the grand picture.

Quote

it works either way.

Are you sure, or did you fail to spot the obscure error to which I drew attention ?

Please explain any error in my test and explanation which follows.

I have created TEST.BAT at location D:\DAT

TEST.BAT code

Code: [Select]echo This script is %0

I have used RUN and launched CMD.EXE and invoked TEST.BAT twice, with and without the extraneous space character, and

selected and pasted the window contents below.

Code: [Select]Microsoft Windows XP [Version 5.1.2600]

(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\Dad>CALL D:\DAT\ TEST

'D:\DAT\' is not recognized as an internal or external command,

operable program or batch file.

C:\Documents and Settings\Dad>CALL D:\DAT\TEST

C:\Documents and Settings\Dad>echo This script is D:\DAT\TEST

This script is D:\DAT\TEST

C:\Documents and Settings\Dad>

Regards

Alan

Quote from: ALAN_BR on November 22, 2010, 03:22:49 PM

25 Interview Question Set For Microsoft DOS in Microsoft

Copyright © 2022

http

s://i

nter

view

ques

tions

.tute

ehub

.com

Are you sure, or did you fail to spot the obscure error to which I drew attention ?

Please explain any error in my test and explanation which follows.

I have created TEST.BAT at location D:\DAT

TEST.BAT code

Code: [Select]echo This script is %0

I have used RUN and launched CMD.EXE and invoked TEST.BAT twice, with and without the extraneous space character, and

selected and pasted the window contents below.

Code: [Select]Microsoft Windows XP [Version 5.1.2600]

(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\Dad>CALL D:\DAT\ TEST

'D:\DAT\' is not recognized as an internal or external command,

operable program or batch file.

C:\Documents and Settings\Dad>CALL D:\DAT\TEST

C:\Documents and Settings\Dad>echo This script is D:\DAT\TEST

This script is D:\DAT\TEST

C:\Documents and Settings\Dad>

Regards

Alan

Works for me. Probably because I tested what he had and was executing, rather then a more bare case that essentially avoids any

issue.

First, I created a bunch of batch files in D:\testbat, test1.bat through test9.bat, they simple contained:

Code: [Select]echo this is %0

and then this one (in a separate folder)

Code: [Select]FOR /R D:\testbat\ %%G IN (*.bat) DO start /b "call D:\testbat\" %%G

and the output:

Code: [Select]

D:\testbat>start /b "call D:\testbat\" D:\testbat\test1.bat

D:\testbat>start /b "call D:\testbat\" D:\testbat\test10.bat

D:\testbat>start /b "call D:\testbat\" D:\testbat\test2.bat

25 Interview Question Set For Microsoft DOS in Microsoft

Copyright © 2022

http

s://i

nter

view

ques

tions

.tute

ehub

.com

D:\testbat>start /b "call D:\testbat\" D:\testbat\test3.bat

D:\testbat>start /b "call D:\testbat\" D:\testbat\test4.bat ??

D:\testbat>start /b "call D:\testbat\" D:\testbat\test5.bat

this is D:\testbat\test1.bat

D:\testbat>start /b "call D:\testbat\" D:\testbat\test6.bat ??

D:\testbat>start /b "call D:\testbat\" D:\testbat\test7.bat

D:\testbat>this is D:\testbat\test2.bat

this is D:\testbat\test10.bat

D:\testbat>this is D:\testbat\test3.bat

start /b "call D:\testbat\" D:\testbat\test8.bat

D:\testbat>

D:\testbat>start /b "call D:\testbat\" D:\testbat\test9.bat

D:\testbat>

D:\testbat>

D:\testbat>this is D:\testbat\test4.bat

this is D:\testbat\test7.bat

D:\testbat>this is D:\testbat\test5.bat

this is D:\testbat\test6.bat

D:\testbat>

D:\testbat>this is D:\testbat\test8.bat

D:\testbat>

D:\testbat>this is D:\testbat\test9.bat

which was certainly weird (what with the starts and the fact that the output was usually delayed and they had to wait for each other

and all) but there were no syntax errors.

On the other hand, when I said "it works either way"  I was being disingenuous; truly, it doesn't work with the %%G in the quotes. In

the first case (outside the quotes) start is using the quoted portion as the window title, and then executes the second part (the batch

filename). Whether this was intended, I haven't a clue. Including the %%G within the quotes would cause an error, as it would then

expand to start /b "call D:\testbat\D:\testbat\test9.bat"  which clearly wouldn't work.

Also, I rather like the musical symbols that the batch throws in the output. adds a nice touch.

Thanks for the explanation.

I like your concise code, i.e.

Code: [Select]FOR /R D:\testbat\ %%G IN (*.bat) DO start /b "call D:\testbat\" %%G

I now see that "call D:\testbat\" is the title  and not part of the command.

25 Interview Question Set For Microsoft DOS in Microsoft

Copyright © 2022

http

s://i

nter

view

ques

tions

.tute

ehub

.com

I was rather confused that the title was preceded by the argument /b.

I thought the title was always first after the start.

It has been a long time since I used "FOR /R" and I wrongly guessed that %%G would be appending the name of each *.bat in the

folder, so assumed the intention was

Code: [Select]call "D:\very long path which MAY have spaces that need quotes\"%%Gin which case a space before the %%G would

have broken the path

Question, what are the benefits and side effects of giving a title to a program with no window so no title BAR ?

I have just created t.bat and started it with a title,

it ran in the "DOS window" that invoked it and had no effect on the existing title bar,

no effect whilst it was paused,

no effect after it was ended.

Code: [Select]C:\Documents and Settings\Dad>echo pause > t.bat

C:\Documents and Settings\Dad>start /b "a silly misleading title" t

C:\Documents and Settings\Dad>

C:\Documents and Settings\Dad>pause

Press any key to continue . . .

C:\Documents and Settings\Dad>

Regards

Alan

Quote from: ALAN_BR on November 23, 2010, 05:23:44 AM

I like your concise code, i.e.

Code: [Select]FOR /R D:\testbat\ %%G IN (*.bat) DO start /b "call D:\testbat\" %%G

Not sure if it's sarcasm... but in any case, I basically wanted to test what they had; so that I could see the same sort of behaviour.

Upon seeing that it worked, it was possible to  figure out why.

Quote

I was rather confused that the title was preceded by the argument /b.

I thought the title was always first after the start.

I don't think it really matters wether switches appear before or after; although they have to appear before the command (which in

this case is %%G) (otherwise those switches will be sent to the command)

Quote

Question, what are the benefits and side effects of giving a title to a program with no window so no title bar ?

none... since the /b switch suppresses creating a new window, the title has no effect. I suspect the batch was only working entirely

accidentally.

Quote from: BC_Programmer on November 23, 2010, 05:28:24 AM

Not sure if it's sarcasm...

Definitely not sarcasm.

25 Interview Question Set For Microsoft DOS in Microsoft

Copyright © 2022

http

s://i

nter

view

ques

tions

.tute

ehub

.com

Short and all on one line, not long and wrapped to continue on following line.  Simple to read.

I admire your patience at testing every aspect of the original code.

I developed undying hatred of software verbosity when I inherited and had to correct code from vandals that MOVED away.

They left me with 'C' code in which every line of code was up to 400 characters wide.

When I scrolled to the last bug on a line, I could no longer see the previous 75% of the line.

Partly the problem was that they chose to indent the code by increments of 8 characters and they had many levels of indentation,

but mostly they chose NOT to document Global Variables with a comment upon the real purpose,

and instead the variable was given a LENGTHY self documenting name.  e.g. code such as

Value_to_put_in_DAC_register_1 ^= Value_for_DAC_register_1 *= Scaling_Factor_for PAL_Colour - PAL_SECAM_OFFSET etc

etc

Some of their code depended upon the "rules of precedence" for which there are ANSI standard rules,

but the compilers in use were not quite compliant ! ! !

Regards

Alan

14. Solve : Concatenate Two Variables?

Preffered Answer:

Hi,

    I have a variable predefined, let's call it Apples.  I want to move all files with this as the prefix followed by _TEST followed by

anything and then .zip to a differnt DIRECTORY i.e.

IF EXIST %Apples%_TEST*.zip MOVE %Apples%_TEST*.zip .\Zipped

It's not WORKING, how do I do this?

Thanks.

Raymondyou may find the answer here>http://home7.inet.tele.dk/batfiles/Thanks, since you sound confident of where to find it,

wanna give me a TIP as to what to search for on the webpage?  I.e. "variable"?

Thanks.Looks like you need to put the filespecs in quotes.

IF EXIST "%Apples%_TEST*.zip" MOVE "%Apples%_TEST*.zip" .\Zipped

This will force recognition of long file NAMES.

15. Solve : %PATH% - Environment Looking For A PATH?

Preffered Answer:

Looking for a way to pull a directory out of the PATH environmental VARIABLE. Guess I'm more so looking for the drive letter. I

know my path will CONTAIN \vision\bin ... I was thinking I could do a FOR loop but I'm just not getting it at midnight. Help is

appreciated.

25 Interview Question Set For Microsoft DOS in Microsoft

Copyright © 2022

http

s://i

nter

view

ques

tions

.tute

ehub

.com

Code: [Select]for /F "tokens=1-26 delims=;" %%a in ('echo %PATH% ^ FIND /I "\vision\bin"') do set direct=%%a

I figured I would use delims=; to separate each path out, but then again maybe that is my problem that when I set direct %%a isn't

my path? I'm not sure.

Nevermind ... I got something to work.

Code: [Select]ECHO off

setlocal enabledelayedexpansion

 for %%G in ("%PATH:;=" "%") do (

    echo %%G | find /I "\vision\bin" >nul

    if !errorlevel! EQU 0 set direct=%%G

 )

setlocal disabledelayedexpansion

if "%direct%"=="" ECHO direct equals nothing & pause

set direct=%direct:"=%

set direct=%direct:~0,9%

echo "%direct%"

Pause

16. Solve : Using Vaiables In A Path?

Preffered Answer:

Hey guys,

I'm STARTING to code in DOS and I am having some troubles with the use of variables. I wrote a code to ROBOCOPY a given file

to a disk of my choosing using a variable. Here's a shortened version of my code:

set backupdisk=G:

robocopy c:\users\... %backupdisk%\documents\backups /E /copyall

Every time I run it, the command prompt interprets it with a space between the variable and the rest of the path (%backupdisk%

\documents\backups) so it never works,

Does someone know what's wrong with my code? Thanks!It doesn'tt do that on my system.

Code: [Select]echo off

set backupdisk=G:

echo robocopy c:\users\... %backupdisk%\documents\backups /E /copyall

Code: [Select]robocopy c:\users\... G:\documents\backups /E /copyall The space is a real character and the set statement takes

everything literally. Open your code in an editor and check for a trailing space on the set statement.

Sometimes it's the SIMPLE things,

SidewinderYes. I am so used to my editor (Scite) removing trailing white space when saving I forgot it was possible. I TRIED it with

Notepad and got the space in the variable.

Hi 

I CREATED this batch script for incremental and scheduled backup using xcopy command in batch.

The first execution of this script is to configure the paths of the source and the destination. And saves them in a .cfg file and then

25 Interview Question Set For Microsoft DOS in Microsoft

Copyright © 2022

http

s://i

nter

view

ques

tions

.tute

ehub

.com

makes a full copy for the first time.

It creates a scheduled task to run every hour with an incremental copy (ie : only copies the new FILES or has been modified from

the source).

Incemental Backup.bat

17. Solve : Real DOS TSR Programming Question?

Preffered Answer:

From Turbo C in DOS, how can I execute an EXTERNAL program without using any INTERRUPTS? I am making a SCREEN saver

TSR which has to execute an external EXE as the screen saver.

18. Solve : File Names Too Long - Following An Attempted Backup?

Preffered Answer:

Hi, I recently had computer issues and I decided to copy my music files on to an external hard drive. I now wish to access the files,

but when I try I get a MESSAGE that the file name is too long and the  file(s) will not open. A more worrying aspect of this issue is

that some files APPEAR to be empty. If anyone out there has a solution to this issue I WOULD be very grateful your for assistance. 

Thank you linx4,

Please provide information about what operating system you are using.

Also, what BACKUP program?

Hi,

I am using Windows 10. Foolishly I didn't use a backup program, just copy and paste from the computer hard drive to a blank dvd

disc. Then the data was copied and pasted again to the new computer HD. Other files went over OK, but the music files did not and

I am now unable to open them because the file name is too long. I believe that this error has been caused by the system  repeatedly

accessing the files and adding to the file names. However, although I believe that to be the cause of the problem, how to cure it is

unknown to me.

Regards

19. Solve : Displayed Comment In A Batch?

Preffered Answer:

how would you make a comment appear on the cmd screen but the script wont exicut it

so it would not exicut the highlighted area

TYPE a number in

1.---

2.---

3.---

type here:well you would have to TURN on ECHO before the comment like so:

Code: [Select]echo on

rem 1,---2,---3,---

25 Interview Question Set For Microsoft DOS in Microsoft

Copyright © 2022

http

s://i

nter

view

ques

tions

.tute

ehub

.com

echo offThis will do it:

Code: [Select]echo off

cls

echo Type a number in:

echo 1...

echo 2...

echo 3...

set /p Selection=Type here

:: The next line displays the entered number..

echo %Selection%

The Environment Variable %Selection% will contain the number entered.

20. Solve : Batch File For Text File Read "surround" And Write?

Preffered Answer:

I have some simple text files that contain the file paths for folders and sub folders.  My current batch file creates the folder with a list

of the file paths.  This is the command I am using to make the files:

     dir /ad /s /b >> New_File.txt

What I get written to the file (say I ran this from My Documents) is similar to the following:

     C:\Documents and Setting\Administrator\My Documents\My Pictures

     C:\Documents and Setting\Administrator\My Documents\My Videos

     C:\Documents and Setting\Administrator\My Documents\My Music

What I need to do now is to be able to read this file one line at a time and put each line in " " so as to look like the following:

     "C:\Documents and Setting\Administrator\My Documents\My Pictures"

     "C:\Documents and Setting\Administrator\My Documents\My Videos"

     "C:\Documents and Setting\Administrator\My Documents\My Music"

The program that takes this file as an input can be particular about how it takes in a list of paths.  I can do this in VBA, however, I

would rather not use excell for a rather simple operation if at all possible.

Thanks for the help.

Try this:

Code: [Select]ECHO off

cls

for /f "Delims=" %%a in (New_File.txt) do (

    echo "%%a" >> New_File1.txt

25 Interview Question Set For Microsoft DOS in Microsoft

Copyright © 2022

http

s://i

nter

view

ques

tions

.tute

ehub

.com

)

New_File1.txt should contain

"C:\Documents and Setting\Administrator\My Documents\My Pictures"

"C:\Documents and Setting\Administrator\My Documents\My Videos"

"C:\Documents and Setting\Administrator\My Documents\My Music"

Good LUCK. Quote from: Dusty on November 20, 2008, 07:40:20 PM

Try this:

Code: [Select]echo off

cls

for /f "Delims=" %%a in (New_File.txt) do (

    echo "%%a" >> New_File1.txt

)

New_File1.txt should contain

"C:\Documents and Setting\Administrator\My Documents\My Pictures"

"C:\Documents and Setting\Administrator\My Documents\My Videos"

"C:\Documents and Setting\Administrator\My Documents\My Music"

Good luck.

Dusty,

Thank you, that works perfectly!    I am only going to add a few things so as to create a temp file that can be deleted and to create a

new file each time.  This is to create a Search.pro file for ProEngineer so that it can find exactly where it needs to look for all of the

parts of an assembly each time AUTOMATICALLY when a file is opened.  It'll save a lot of time for people importing new

assemblies to their computer so that they can keep their standard Config.pro file and simply create new search.pro files when they

open an assembly.  Long story with the ProEngineer side of things, but needless to say this will make my life a lot easier.

Thanks again for your help!

SEBNN

Oh, and so someone can see what the code looks like, it is below.

Code: [Select]echo !TrialFile >TrialFile.txt

dir /ad /s /b >>TrialFile.tmp

echo off

cls

for /f "Delims=" %%a in (TrialFile.tmp) do (

echo "%%a" >>TrialFile.txt

25 Interview Question Set For Microsoft DOS in Microsoft

Copyright © 2022

http

s://i

nter

view

ques

tions

.tute

ehub

.com

)

del .\TrialFile.tmp

Like I said, it works great and I have tested it multiple times.  Also, as an explanation, the ! in the code is to indicate to ProEngineer

that the CHARACTERS following it are a comment and to write SOMETHING other than a blank line when the file is cleared for the

first run.Thanks for coming back to report your success and post your coding.

D.

21. Solve : XP NTLDR And Adding DOS To Boot Menu?

Preffered Answer:

Hi!

I have installed on 1st partition MS-DOS 7.10 formatted by FAT32.

On second partition I have Windows XP formatted by FAT32.

I'm using to boot into DOS floppy, to XP NTLDR.

Several YEARS ago I CREATED adding DOS to NTLDR, but note was lost after disk crash.

So, Q is maybe simple but need to confirm it.

I found over the web this info:

Add to boot.ini:

Code: [Select][boot loader]

timeout=10

default=multi(0)disk(0)rdisk(0)partition(2)\WINDOWS

[operating systems]

multi(0)disk(0)rdisk(0)partition(2)\WINDOWS="Windows XP" /fastdetect

C:\bootsect.dos="MS-DOS" /win95dos

But is it correct if MBR was OVERWRITTEN?

Even, I'm not sure about bootsect.dos and /win95dos parameter...

Can anybody explain it me how it works and/or what to fix?

Thank you very MUCH!

Miro

22. Solve : Elegant Batch File To Make Folder And Copy 2 Specific File Into?

Preffered Answer:

Hi Folks

It's been some time since I last resorted to a batch file and I'm a little rusty so wondered if anyone could help. I have a large number

of docs with files names in the in the format XXX-YYY-ZZZ1.DOC

25 Interview Question Set For Microsoft DOS in Microsoft

Copyright © 2022

http

s://i

nter

view

ques

tions

.tute

ehub

.com

The batch file I'm trying to write would repeatedly generate a folder and then move 2 specific files into it, then move on till all files

have been moved. I have a table that associates each file with a specific folder.

So the batch file could be cintructed in the form:

MD d:\AAA BBB1    [The unique folder name]

MOVE XXX-YYY-ZZZ001.DOC d:\AAA BBB1\XXX-YYY-ZZZ001.DOC

MOVE XXX-YYY-ZZZ002.DOC d:\AAA BBB1\XXX-YYY-ZZZ002.DOC

MD d:\AAA BBB2    [The unique folder name]

MOVE XXX-YYY-ZZZ003.DOC d:\AAA BBB1\XXX-YYY-ZZZ003.DOC

MOVE XXX-YYY-ZZZ004.DOC d:\AAA BBB1\XXX-YYY-ZZZ004.DOC

........ and so on till all files have been moved.

This works but is long winded as I'm are talking of 1000 plus files and the excercise will need to be repeated several times.

Was wondering if there is a more elegant way of doing this, preferably with a batch file that will make the folder and then copy the 2

files into it using a single command line.

Any Guidance Much Apreciated

Biscuit

This discussion at Stack Overflow might apply to your scenario.

https://stackoverflow.com/questions/41804814/batch-file-to-move-files-based-on-part-of-filename-to-folder-based-on-part-of-fWhat is

the rule that decides which files get moved to which folder?

Quote from: Salmon Trout on March 26, 2019, 11:37:45 AM

What is the rule that decides which files get moved to which folder?

Hi and thanks for getting back to me.

Currently I've a very large Excel file (1200 lines) which I'd like to edit and then save a a txt file, so I can use this as the basis of my

batch.

Each line of the xls file currently has, 2 columns  Column1 is name Name of the Folder and Column 2 is the name of the of file, all

files are unique and the folders are usually referenced twice, as most folders should end up with 2 files moved in.

Hope I'm making myseld clear.

Thanks

Biscuit Please show a sample of the Excel file.

Hi Thanks for getting back to me

Here is a sample of the spreadsheet (which could end up being over 2000 lines long). Currently all the files are in a single folder, so

25 Interview Question Set For Microsoft DOS in Microsoft

Copyright © 2022

http

s://i

nter

view

ques

tions

.tute

ehub

.com

all file names will be unique. Folder names are defined and will usually be referenced 2-3 times in the spreadsheet as each is

ASSOCIATED with 2-3 drawings.

Looking for a nice script that will both generate the folder and move each file into it's RESPECTIVE folder.

Thanks

BiscuitYou can make the lines of a batch script in Excel itself; I often do this.

Have Notepad open.

Step 1. Create commands to make the folders if they don't already exist (you can skip this if each folder does already exist, but it

won't do any harm if you run it)

I am using the letters for the columns, and numbers for the rows, as they are in your example spreadsheet.

I hope you can see the formula in cell D3. Copy this down so it is in column D all the way down. Duplicated folder names won't

matter.

Highlight the cells in Column D that have the formula and paste into Notepad first.

Step 2. make the commands to move the files

Again, I hope you can see the formulas

Highlight and copy the formulas in Column E into Notepad, below the commands you did in step (1) above.

Finally, in Notepad, save the TEXT as a .bat file in the folder where the .dwg files are located, and run it.

If you don't want to see the commands scroll past, put echo off as the first line of the batch.

If you want the batch window to stay open until you press a key, put pause as the last line of the batch.

The other alternative is to save the columns with the .dwg filenames and the folder names, from Excel, as a .csv file and make a

batch to process that. Let me know if that is preferable.

Quote from: Salmon Trout on March 29, 2019, 12:29:47 PM

25 Interview Question Set For Microsoft DOS in Microsoft

Copyright © 2022

http

s://i

nter

view

ques

tions

.tute

ehub

.com

The other alternative is to save the columns with the .dwg filenames and the folder names, from Excel, as a .csv file and make a

batch to process that.

CSV file looks like this (I called it MyFile.csv for this exercise):

Code: [Select]FOLDER,DRAWING

Product 0021,765-245.dwg

Product 0107,963-541.dwg

Product 0956,524-890.dwg

Product 0584,769-527.dwg

Product 0022,835-245.dwg

Product 0096,963-523.dwg

Product 0021,192-879.dwg

Product 1584,769-524.dwg

Batch file

Code: [Select]echo off

for /f "skip=1 tokens=1-2 delims=," %%A in ('type MyFile.csv') do (

if not exist "%%A" md "%%A"

echo Moving file "%%B" to folder "%%A"

move "%%B" "%%A"

)

echo Finished

pause

A third possibility is to use Visual Basic Script (which is on all Windows) to directly extract the data from the Excel spreadsheet, and

I have been working on that, but as this thread has gone silent, I am not inclined to spend any more time on it. A fourth would be a

VBA macro, (but likewise).

Many Many Thanks for your response looks very interesting Sorry I didn't reply earlier I took "She Who Must be Obeyed" away for a

long weekend with strict instructions to leave the laptop begind 

Anyway will try tonight

Thanks Alot

BiscuitMany thanks Salmon Trout

Yes that works fine, thanks alot, just think it's a shame that the MOVE command doesn't have an option to generate a folder if it

doesn't exist.

Your EFFORTS much appreciatedd

Biscuit

23. Solve : Change To Greek Keyboard Layout?

Preffered Answer:

25 Interview Question Set For Microsoft DOS in Microsoft

Copyright © 2022

http

s://i

nter

view

ques

tions

.tute

ehub

.com

Hi,

I want to change the keyboard layout from US to GREEK style in the 16-bit DOS-Box (command.com) of Win XP.

The command CHCP 737 doesn't work, neither kb16 gk,737 for using the Greek Codepage 737.

Remark:

In Win 2000 it is posible to switch the input configuration using CTRL + Alt + F1 or Ctrl + Alt + F2, but not under Win XP's DOS-Box.

Any idea, how to USE Greek letters in the 16-bit DOS-Box for 16-bit programs?

Thanks!

24. Solve : Choosing Random Numbers Without Repeats.?

Preffered Answer:

How could you make a batch file choose random numbers (for example 1-20) without repeating each other? Also, how can it 'detect'

that it picked ALL of the numbers then go somewhere else (goto :blank)?

I know how to choose random numbers:

Code: [Select]echo off

:1

cls

set /a R=%random%%% 20 +1

echo %R%

pause >nul

goto 1

But theres some problems in this. It repeats numbers, and doesn't go anywhere if/when it detects all of the numbers have been

used (the two main points in the BEGINNING)

Please help   

Quote

It repeats numbers, and doesn't go anywhere if/when it detects all of the numbers have been used (the two main points in the

beginning)

It repeats numbers because past performance is no indicator of future results. Each resolution of random is an independent event

and has no "memory" of what numbers were chosen previously.

I'm not seeing in your code where it detects when all the numbers have been used. You will need to keep a history of numbers

displayed and if there is a duplicate, re-randomize until a non-duplicate is found.  You could use an array in Powershell to hold the

history or the dictionary object in VBScript.  Other script languages have similar features.

Good luck. 

Note: using pause > nul without any indication to the user of what to do, will not win you any gold stars. The way I'd do it in a more

capable language would be to create an array of all the items that can be selected, and when a random item is chosen, choose an

index into that array randomly, use the value in the index as the random value, and then remove the item from that list.

25 Interview Question Set For Microsoft DOS in Microsoft

Copyright © 2022

http

s://i

nter

view

ques

tions

.tute

ehub

.com

This makes choosing a random number linear with regards to how many items have been previously selected, whereas if you were

to store each selected item, you would have to go through all the stored items and make sure it's not the new choice; what this

would mean is that, if you had 100 values and you  had already chosen 99, whereas the method I propose would instantly give you

back that last number, the more "brute-force" approach would probably take a very long time to finally come up with the only

POSSIBLE solution. Code: [Select]echo off

setlocal enabledelayedexpansion

set maxnum=20

if exist AlreadyChosen.txt del AlreadyChosen.txt

:loop

set /a RandNum=%random%%%%maxnum%+1

set alreadychosen=0

if exist AlreadyChosen.txt for /f "delims=" %%A in (AlreadyChosen.txt) do (if "%%A"=="%RandNum%" set alreadychosen=1)

if %alreadychosen% equ 0 (>> AlreadyChosen.txt echo %RandNum%)

set NumbersStored=0

for /f "delims=" %%A in (AlreadyChosen.txt) do set /a NumbersStored=!NumbersStored!+1

if %NumbersStored% lss %maxnum% goto loop

echo Have now chosen every single number between 1 and %maxnum% once each.

times (3.0 GHz AMD Phenom II, 7200 rpm HDD)

Code: [Select]maxnum       seconds

10           0.09 sec

20           0.25 sec

100          6.35 sec

200          32.48 sec

500          201.51 sec

Quote from: Salmon Trout on December 02, 2010, 12:04:26 PM

Code: [Select]echo off

setlocal enabledelayedexpansion

set maxnum=20

if exist AlreadyChosen.txt del AlreadyChosen.txt

:loop

set /a RandNum=%random%%%%maxnum%+1

set alreadychosen=0

if exist AlreadyChosen.txt for /f "delims=" %%A in (AlreadyChosen.txt) do (if "%%A"=="%RandNum%" set alreadychosen=1)

if %alreadychosen% equ 0 (>> AlreadyChosen.txt echo %RandNum%)

set NumbersStored=0

for /f "delims=" %%A in (AlreadyChosen.txt) do set /a NumbersStored=!NumbersStored!+1

if %NumbersStored% lss %maxnum% goto loop

echo Have now chosen every single number between 1 and %maxnum% once each.

Wow that's almost exactly what i wanted/needed. Thanks a lot But one little tweak i hope you can do is not make a .txt file with the

numbers, but actually show them instead (on batch screen).

Also, if you could make it show on the batch screen, is there a way to put a pause between each number? For example it picks a

25 Interview Question Set For Microsoft DOS in Microsoft

Copyright © 2022

http

s://i

nter

view

ques

tions

.tute

ehub

.com

random number from 1-20 and shows it, and when you press any key it will show the next number and so on.I will do some more

tomorrow; it is 11 PM now and I am working tomorrow; look for a post in around 18 hours

Code: [Select]echo off

setlocal enabledelayedexpansion

set maxnum=20

if exist AlreadyChosen.txt del AlreadyChosen.txt

:loop

set /a RandNum=%random%%%%maxnum%+1

set alreadychosen=0

if exist AlreadyChosen.txt for /f "delims=" %%A in (AlreadyChosen.txt) do (if "%%A"=="%RandNum%" set alreadychosen=1)

if %alreadychosen% equ 0 (

>> AlreadyChosen.txt echo %RandNum%

echo %RandNum%

echo press a key for another number

pause>nul

)

set NumbersStored=0

for /f "delims=" %%A in (AlreadyChosen.txt) do set /a NumbersStored=!NumbersStored!+1

if %NumbersStored% lss %maxnum% goto loop

echo Have now chosen every single number between 1 and %maxnum% once each.

Thanks a lot! Works great!I have been playing around with this. I believe any non-random-access method will slow down

exponentially as the max number increases. This is what you might expect. With a sequential access method the more numbers you

have already chosen, the longer it will take on average to verify that each random number chosen is a new one. The method

repeatedly scanning a single text file is quite slow. Next I tried creating an empty string VARIABLE and appending each chosen

number to it, bracketing each one with separators e.g. 30 19 2 15 and using FIND separator%randnum%separator to decide if a

new random number was already chosen. This is dramatically slower than the previous method for smaller values of maxnum but

there is a point where it gets faster (on my system it is occurs somewhere between 250 - 500 with the disk I am using.) Finally I tried

creating a subfolder and creating a small file in it named for each number chosen, e.g.

echo.>tempfolder\%randnum%

Then you can exploit file system random access and use IF EXIST tempfolder\%randnum% to see if a new number has already

been chosen. This is much faster than either of the previous methods.

Time in seconds

Maxnum    textfile   string  filenames

 10        0.07       0.11     0.09

 50        1.01       5.32     0.35

100        4.18       9.88     0.73

250       26.65      38.07     1.80

500      145.46      86.79     4.34

[edit] I can't believe I have spent an hour on this! It underlines that for anything more than toy stuff, you need to learn a proper

programming language.

25 Interview Question Set For Microsoft DOS in Microsoft

Copyright © 2022

http

s://i

nter

view

ques

tions

.tute

ehub

.com

I found this in the snippet CLOSET. Originally written in VBScript using the dictionary object, this uses a compound naming

convention for the variables. Basically it is another approach to the solution.

The first part of the variable name is the word slot. The second portion is the random number generated as is the value of the

variable. This produces variables such as slot.20 with a value of 20 or slot.15 with a value of 15. Using such a scheme allows the

code to simply check if the variable is defined and eliminates the file system processing.

As previously pointed out, the code slows down as the pool of unused random numbers shrinks. I made the code generic by

allowing the user to enter the min and max numbers of the number range. I also eliminated the PROMPT to get the next number,

but the code is remarked out and can easily be reactivated.

Code: [Select]echo off

::

:: No error check that max num is greater than min num

::

setlocal

set /p intLowNumber=Enter Minimum Number:

set /p intHighNumber=Enter Maximum Number:

set /a intMin=%intLowNumber%

set /a intMax=%intHighNumber%

set /a count=%intLowNumber%

:loop

  if %count% GTR %intHighNumber% goto :eof

  set /a rnd=%random% %% (%intHighNumber% - %intLowNumber% + 1) + %intLowNumber%

  if not defined slot.%rnd% (

    set slot.%rnd%=%rnd%

    set /a count+=1

    echo %rnd%

    rem echo Press A Key For Next Number

    rem pause>nul

  )

  goto loop

 Sidewinder's method is fastest by far.

25. Solve : Move File From One Server To Another?

Preffered Answer: HELLO every oneI need help to UNDERSTAND the below code and what I should to for my requirement

I have a batch file which is being called from another script file, with some parameters

Let me show you my batch file code=========================ECHO ON

25 Interview Question Set For Microsoft DOS in Microsoft

Copyright © 2022

http

s://i

nter

view

ques

tions

.tute

ehub

.com

net use P: /DELETEnet use Q: /DELETE

net use P: %1 /USER:%4 %5 >> "C:\Test\Log Mover\Logs\sharelog.txt"net use Q: %2 >> "C:\Test\Log Mover\Logs\sharelog.txt"

attrib +R Q:\*.zipxcopy /Y /C /D:%3 P:\*.zip Q:\ >> "C:\Test\Log Mover\Logs\sharelog.txt"

attrib -R Q:\*.zip

net use P: /DELETEnet use Q: /DELETE==========================

where:: 1 is the src of the logs, or the web server:: 2 is the destination or local NAS:: 3 is a date like 3/02/2008 to go back and check for logs that got missed:: 4 is the username to use for the remote share, or 1:: 5 is the password to use for the remote share, or 1

My doubt are1> what is this code doing2> what does >> mean3>where did it get /Y and what is xcopy line doing

Plz let me know the answers.QuoteMy doubt are1> what is this code doing2> what does >> mean3>where did it get /Y and what is xcopy line doing

1>  move file from one server to another2> >> means to add the "output" to a file3> xcopy /?

25 Interview Question Set For Microsoft DOS in Microsoft

Copyright © 2022

http

s://i

nter

view

ques

tions

.tute

ehub

.com