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.

1501.

Solve : Boot CD DOS vs. DOS in Windows?

Answer»

Why do .bat files I have written work in Windows but not in DOS when I have booted from a boot CD?

How do I MAKE them run properly? Do I NEED new command interpreters on the CD?

I have full control over the boot cd (I can add/remove/alter files).

This is driving me insane!

Thanks,
-darrylPost an example of one that doesn't work in Dos...

BTW which version of Dos or what TYPE of bootCD is this ? ?Likely the PATH statement. Alter it so the directory CONTAINING the .bat files are on the path or enter the path on the command line. for example, if the .bat files are in c:\windows, they are automatically in the path under windows. From real DOS the command would be
c:\windows\yourfile.bat
You have to tell DOS where the files are located, even in windows if they are in a directory that is not on the PATH.The type of boot CD that I am using is a network boot CD. It is used to install the basic network drivers so that the machine can image over the network. I have several different types of computers and 6 different network CARDS in them (total across all machine types). As of now, every time I use this boot CD, i have to tell it which driver to load (because it is different depending on which machine I am using it in). What I want to do is have it automatically detect the type of machine so that I don't have to tell it (this gets tedious using 50+ machines...)

The nice thing is, all of these machines can be distinguished by their processor speed. I have a utility that returns the processor speed. What I am having a great deal of difficulty doing, however, is getting that returned value into a variable so that I can evaluate it to load the appropriate drivers.

The program runs like this:

C:\> processorspeed.exe
2600MHz CoreDuo

I need to get the "2600MHz CoreDuo" part into a variable, so that I can use if-then statements to get the CD to load the right drivers.

Any ideas?
Please?

Thanks all,
-darryl

1502.

Solve : press to bypass LAN check?

Answer»

Every time I reboot, I get this cheerful black screen that tells me to Press to bypass LAN check. What can I do to get rid of this?
IDEAS and solutions are more than welcome and very much appreciated.
THANK youI guess the easiest way to get rid of it would be to press  

You didn't mention an OS. Is this little black screen a command or cmd window? Do you have if fact any LAN software installed on your machine?

Boot startup programs can be started from several places. Win9x boxes use the autoexec.bat file, the registry, and the startup folder. WinNT boxes use the autoexec.nt, the registry and startup folder.

Try running msconfig from the Windows Run BOX, click the startup tab, and look for something related to a LAN.  If you find something unclick it and OK your way out.

Also check your startup folder (START==>programs==>startup) and see if any entries relate to your LAN.

Also edit whichever autoexec file you have and again check for any entries related to a LAN.

If you do find something and remove it, you'll need to reboot to see if you got the correct item.

Hope this helps. 8-)

Note: Unfortunately msconfig does not report all the startups from the registry. You may have installed some software that installed the LAN item deep in the registry. There are 3rd party programs for discovering this stuff, but lets start with the obvious.This is a setting in your BIOS, check your BIOS.Hi
Unfortunately there are no entries related to LAN. I am not confident changing things in BIOS as I have had one to  many crashes over the last few years. Is there no software like Baseline or Secunia etc that I can run that will either fix the error or show me step by step what to do?
Thank you once again
Christelsea
PS Is there a really good free antispam that I can run with adware and Norton?

1503.

Solve : To call a Batch file on remote system?

Answer»

Hi, I have a query regarding calling the batch file in the remote system.
I want to call a batch file in the remote system, using a batch file in another system.
I have created a batch file in the remote system(WINDOWS XP) shared drive to start the windows service by using NET START command,and saved it as "Test.bat". I have to call this "Test.bat " file from a batch file in another system(Windows XP).
I have USED the call command to call Test.bat. But its not WORKING. Can anyone help which command I have to use to call the batch file?Hi!

You might want to checkout my post with TOPIC

"how to execute cmd on LOCAL machine instead on Remote Machine "

1504.

Solve : Editing a file [automatically] through batch file??

Answer»

This is probably a very very noob question 
But is is possible to change / insert TEXT in a TXT file through a bat file?

This is then picked up by another program for processing.

I looked at the EDIT function but this opens up a notepad like window in the command screen.

danielplease give example of what you would like to do
I would like to have a file wich is re-written every time the BAT is started.

For example:
File --> C:\info.txt
inside is a line like --> 14-02-2008

Now when I run the BAT tomorrow it must be rewritten to 15-02-2008

( this is purely an example, my textline will be different.....)I understand. You will need the > symbol and the >> symbol.

This symbol > creates a file new each time, any old file with same name is deleted

echo %date% > c:\info.txt



These 2 symbols >> create a file only if it does not yet exist. If it already exists a new line is added at the end.

echo %date% >> c:\info.txt
How would you get the time too?For Time

Echo %time% >C:\info.txtThe "TYPE > my_text.txt" will pipe or redirect the output to my_text.txt, overwriting the original.
The "TYPE >> my_text.txt" will pipe or redirect the output to my_text.txt, appending the original. The original test will still be there, plus the new.

I don't think that either is what you want.

In order to modify the text file, it would be necessary to rewrite the whole file each time.
I've been working on a possible solution, but can't get it to work yet.It would be possible to do some kind of word-processing / text-editing type things to a file fairly simply, such as search & replace, change case, DELETION, insertion, etc.

Linux / Unix has had utilities such as grep and sed for a long time, and they are available for the Windows command line too.


Quote from: Dias de verano on February 16, 2008, 10:43:52 AM

It would be possible to do some kind of word-processing / text-editing type things to a file fairly simply, such as search & replace, change case, deletion, insertion, etc.

How would one go about deleting (not ignoring) the first line of a text file using DOS?Using the "skip" setting in the FOR command, copy the file to another temp one, skipping the first line. Then delete the original file, and rename the temp file with the original file name.

Here's what I got so far...and it's not working...Not sure what I'm doin wrong:

For /F "skip=1" %%x in ("i:\shared_retention\ccbatch\ccbatch.txt") do copy %%x "i:\shared_retention\ccbatch\ccbatch2.txt"

am I WAY off? Quote from: dvnmaya on March 03, 2008, 02:56:39 PM
Here's what I got so far...and it's not working...Not sure what I'm doin wrong:

For /F "skip=1" %%x in ("i:\shared_retention\ccbatch\ccbatch.txt") do copy %%x "i:\shared_retention\ccbatch\ccbatch2.txt"

am I way off?

Not far off really. You need ECHO, not COPY. The lines starting REM are REMarks
and do not affect the operation of the batch file and can be removed if you want,
as can the blank lines.

I have PLACED the SOURCE and destination file names into variables to make the
code a bit clearer but you can code them literally if you want, of course

This should work...

Code: [Select]
set file1="i:\shared_retention\ccbatch\ccbatch.txt"
set file2="i:\shared_retention\ccbatch\ccbatch2.txt"

REM if the target file already exists, delete it
if exist %file2% del %file2%

REM Now the >> redirection will create the file the first time it is used
REM to echo a line and append each line subsequently

For /F "skip=1" %%x in (%file1%) do echo %%x >> %file2%

1505.

Solve : Batch File Execution based on Modified Date?

Answer» HI there,

I am trying to create a batch file that will only run if a certain file has been modified. I was PLANNING on using something like windows task scheduler to execute that batch file every hour or so, but WOULD like the batch file to end if a certain file has not been modified based on current date.

Any ideas or suggestions would be great.

Thanks,What have you got so far CODE wise?

What do you mean "modified"? If the last-modified date/time changes?

The file date stamp is the the time / date of modification, and the %%~t FOR variable modifier will read it.

You could set the archive flag .... when it is updated it will be reset, you can then check this in your batch - no mucking around with date testing

This is how backup routines determine if a file needs archiving or not

Graham
1506.

Solve : Strip Trailing spaces?

Answer»

I've been lurking here for a while and have picked up some great tips, but I'm stuck on something and hoped someone could help.

Once a month I copy a file off our Unisys Clearpath Enterprise Server "aka" MAINFRAME and send the file off and retrieve a file in return.  The problem is that the file I send them cannot have trailing spaces and it does.  The solution cannot be solved server side as the program that creates the file does not have the functionality to strip the spaces.  The old file transfer utility we used had the option of stripping the spaces, but our current one does not.  I know that I can solve the problem by just opening the text file once it is copied and saving it again with a text editor that has the functionality to strip trailing spaces, but it would be nice if I could TAKE care of it within a  batch file as everything else within this PROCESS is currently done by batch file.


Here is a sampling of what the file contains:
$6277
VU080229CDARS
VU080229XXXXX 20                                     
VU080229SD1999HA                           
VU080229SD1999JD                                   
VU080229SD1999PF                             
VU080229SD1999UF                                                     
VU080229SD1999YG                                 
VU080229SD2990CU                             
VU080229SD2990EN
VU080229SD2990FV
VU080229SD2990HZ

So what I would like is possibly a For statement that would pipe each line of my file into another file without the trailing spaces, but some of the lines are going to have a space inbetween characters.  The output text I receive back looks like the following (it has other stuff ALSO, but due to sensitivity of the content I deleted it).

V U 080229 SD1999UF,E53
V U 080229 SD1999YG,E53
V U 080229 SD2990CU,E53
V U 080229 SD2990EN,E53
V U 080229 SD2990FV,E53
V U 080229 SD2990HZ,E53
V U 080229 SD2990KY,E53
V U 080229 SD2990QG,E53
V U 080229 SD2990SQ,E53

So the max length of my input is going to be 16 characters.  Is it possible to have a For statement that will take the first 16 characters of each line and then pipe it to another file?  The last line of the file I send is just an 'x' so that could tell it to stop. 

If anyone has any ideas I would be appreciative.  Thanks Quote from: shiftyness on March 03, 2008, 05:38:18 PM

Is it possible to have a For statement that will take the first 16 characters of each line and then pipe it to another file?
Yes.  The easiest way I can think of would be something like:
Code: [Select]echo off
setlocal enabledelayedexpansion
for /f "tokens=*" %%a in (sample1.txt) do (
  set line=%%a
  echo !line:~0,16!>>sample2.txt
  )This ASSUMES the original sampling file is sample1.txt and the file you get back is to be sample2.txt. You will also need to clear out the contents of sample2.txt between runs if you run multiple times in the same directory as it will keep appending to the end.
Or if you really wanted to shorten the FOR into one line (you still need the enabledelayedexpansion), you can try:
Code: [Select]setlocal enabledelayedexpansion
for /f "tokens=*" %%a in (sample1.txt) do (set line=%%a&echo !line:~0,16!>>sample2.txt)
1507.

Solve : Using Copy in Windows XP to back up Whole Hard Drive?

Answer»

What is the best way I can copy my whole Hard Drive using a copy command or XCOPY command to an external USB Hard Drive . I have Windows XP , 2nd version. And what is the command to do that?Why would you want to copy your ENTIRE hard drive like that?I was hoping to make it easier so I wouldn't need a third-party software backip my whole hard drive. So if my Internal HD crashes all I need to do is copy the whole hard drive from my external USB hard drive, back to my Internal HD.This strategy is doomed to FAILURE...Windows isn't designed to do this.
As a third party app i highly suggest Acronis True Image for your needs...
Version 10 which is more than ADEQUATE for your application is about 20 bucks shipped from newegg.com if your in the States.
Trust me there are NO reliable backup strategies using just Windows.

P.S. Also it is unwise to save a backup to an external HDD...they fail also. Better to burn it to CD/DVD which ATI allows you to do.I definitely go with what Patio said. You can use Acronis True Image to backup your hard drives. Ive used it thrice. What we have is Acronis 9. But, if you really do want to try to back up your entire hard drive, you can use this:
Code: [Select]xcopy C:\ E:\ /e /h /k /c /d /yThis assumes that your hard drive is C:, and your external USB is E: and that you want to back it up to the root of the drive.  This will not back every single file, but it should get all files that are not in use (files like pagefile.sys, registry hives, etc. won't be backed up with this method).  It is suitable for backing up your data files, documents, pictures, etc., but you won't be able to use it to restore your entire hard drive.

Here is what the switches do if you are interested:
/e: copy all subdirectories including empty
/h: copy hidden and system files also
/k: keep the hidden / system file attributes on the copied files
/c: continue copying if an error is encountered (like a file is in use)
/d: copy only newer / changed files
/y: overwrite existing files

Notes: the /d and /y aren't necessary if this is a 1-time copy, but if you run the command on a regular basis, they will significantly speed up the backup because xcopy will only copy files that have changed or don't EXIST on your destination.  Also, xcopy has limits on paths and file names and performing an xcopy on an entire hard drive will sometimes result in an "out of memory" error (usually in extremely long paths or filenames).  I get around this by using the robocopy program which is a free download from Microsoft.

If you want a full backup, I would go with something like Acronis as suggested by Patio ... although I do have to respectfully disagree with his opinion that backing up to CD/DVD is better than an external hard drive.  All storage media is prone to failure, and all storage media will fail eventually.  I PERSONALLY prefer an external drive over CD or DVD media.

1508.

Solve : dir piped to move command failure [solved]?

Answer»

A command window in WinXP Pro given the instructions:

dir D:\*somestring* /S | move C:\somedirectory

What would happen to the files found by dir in the D drive?

The idea was to find all files in D with "somestring" in the name and move them all collectively to the directory in C drive. The result was that the directory in C vanished (complete with all contents) to never-neverland. So, obviously this was not the correct way to pipe the results of the search to the move command.

What would be the RIGHT way?

It sounds like what you need is actually something like this in a batch file:
Code: [Select]for /f "tokens=*" %%a in ('dir D:\*somestring* /s /b') do move "%%a" C:\somedirectoryfor the same command directly in a command prompt, CHANGE the %%a to just %a Quote

for the same command directly in a command prompt, change the %%a to just %a
Thanks for the reply.
What are the percent signs telling the program to do?
Also, any idea what the command I used did with the directory that vanished? Is it forever gone? Quote from: dbam on MARCH 04, 2008, 10:24:23 PM
What are the percent signs telling the program to do?

To CREATE and use variables.

Quote
A command window in WinXP Pro given the instructions:

Code: [Select]dir D:\*somestring* /S | move C:\somedirectory
Quote
What would happen to the files found by dir in the D drive?

Alas, it moved "C:\somedirectory into my home directory lock, stock and barrel, complete with the *somestring* files that it found. My guess is that it didn't know where else to put it since I didn't specify.

Thanks Gary and Dias for the pointers and good help.
1509.

Solve : COM connection command?

Answer»

i know there is a command to ADJUST ur COM settings(MODE command) but i tried doing the "copy con(keyboard) com1" this lets me copy watever i typed on the keboard to the COM PORT i specify but i want to create a batch PROG SIMILAR to WinChat a batch prog that is a chatroom that to users can send and recieve typed words either by using there built in modem(over their phone line) or a direct connection(a connection using a serial cable to connect the two comps.)  but how do i create a batch file that can send and recieve commands simultaneously then display them?

1510.

Solve : run script in the batch file?

Answer»

Hi,

First of all, forgive me if i have posted this to the wrong place. I have an issue with the batch file.

I'm writing a SIMPLE batch file that would run the script file.

Here is the CODE
echo off
echo "Commencing mapping the network drive"
call %APPDATA%\mapdrive.vbs
pause
exit

Could anyone help me out on this?

Thank you in advanceIf your GOAL is to call a VBS file, you probably want something like:
Code: [SELECT]echo off
echo "Commencing mapping the network drive"
cscript "%APPDATA%\mapdrive.vbs"
pause
exit
If all the VBS does is map a network drive, you can do it in the batch file like:
Code: [Select]echo off
echo Commencing mapping the network drive
net use Z: \\Server\Share

1511.

Solve : Similarities to CTTY?

Answer»

Does anyone know if there is something similar to CTTY for Win XP?

PLEASE mail to:

[email protected] please specify in subject (DOS)

e-mail addy removed to prevent SPAMThe purpose of this forum is to share information with others, so any discussion should take place on the forum and not through your email.

I assume you want to redirect OUTPUT?  Where do you want to redirect?  I THINK the MODE command has some of the functionality.  Try
CODE: [Select]mode /?to see if it has what you want.  If it doesn't, then try giving us more information on what you are trying to accomplish and we have a better chance of being able to help you.

1512.

Solve : User prompt and folders...?

Answer»

I have a structure of folders that follows the below example:

Main
  |
   -------- Susan
  |              |
  |               -------- Folder1
  |              |
  |               -------- Folder2
  |
   -------- George
                 |
                  -------- Folder1
                 |
                  -------- Folder2

Each folder has a .TXT document that I need to then read from to get certain information from.  I want to create a Batch PROGRAM to prompt me (or the user) to flow through the folder structure, and when it gets to the last folder it'll pull the information from the .TXT file.

Example:

Prompt: 1-Sue, 2-George?  ...I input 2
Prompt: 1-Folder1, 2-Folder2? ...I input 1
the program then reads the .TXT file inside ..\Main\George\Folder1\text.txt

It's possible to have up to 3 folder tiers (..\Main\Folder1\Folder2\Folder3\text.txt), but I need the system to automatically pull up the next folder I have in the system and give me the choice to open from it.  Can SOMEONE help me create this batch file?  I'm not quite sure where to start from.

Thanks.PLEASE clarify a bit.... so do you want all the text documents to merge into one at main or do you want them all to be moved into a folder at main. I don't understand... please help
1. You are in the top folder you call "Main"

2. Echo "Txt files found"

3. use set /a to make a variable equal to 1

4. A FOR loop captures the output of dir /b /s *.txt & assigns each FILENAME in turn to the loop variable

5. In the loop:

    display the variable value and folder name 1 to a line
    add 1 to the variable after doing this

1 Susan\Folder1\textfile.txt
2 Susan\Folder1\Folder2\textfile.txt
3 George\Folder1\textfile.txt
4 George\Folder2\textfile.txt
5 George\Folder1\Folder2\Folder3\textfile.txt
 etc

6. Echo "type a number"

6. Use set /p to get the user's choice

Again,

7. use set /a to make a variable equal to 1

8. A FOR loop captures the output of dir /b /s *.txt & assigns each path + filename in turn to the loop variable

9. In the loop:
     
    add 1 to the variable each time around
   
10. When variable equals choice
      set a variable equal to current found path + filename
      quit the loop

11 You have the path to your desired file



5. Use set /p to ask the use for their choice

Another loop as 3 & 4 above

1513.

Solve : BAS, Trying to run game on C64, please - need help / file?

Answer»

Someone suggested to me, that they send me a BAS command file
(something that lets Win98 to run Basic, or commodore64 programs)

I have a few questions-

Where can I get it?
Can it fit on a 3 1/2in floppy? (Just over  a MB of space, 2.56Mb if compressed)
Can I save a "Basic" file simply by making a notepad file, click save as, and adding ".bas" extension. please help? thanks.

ps the code I'm trying to run looks like this, i was told it was BASIC:

Code: [Select]10 REM Arcade Explorers Game 3
20 REM Electric Hurricane
30 REM Lewis & Mcevoy (C)
40 REM cannon or blaster
50 BN$

and it would say BN$ equals something, etc. . .
It includes alot of "GOSUB" commands, and "If. .Then . . ." statements and a command I didn't recognize:

if CN=(I+CY) then blah blah(?) blah:RETURN

the :Return command, final question: What is the purpose of this command?

Please help me, and answer al these questions. . .And if it can fit on a 3 1/2inch floppy disk
then e-mail me the BAS Command File, (For Win98) to

[email PROTECTED] OR [email protected] (Gmail is better, i can get to it from school)

Thanks guys,
 Your bud- RJ

PPS--

I won't be able to resond to any messages until School starts (jan 07)
but don't let that stop u from posting / sending me the file asap (if possible)you really do not want to do this, the c64 is old old old, if you really want to learn basic, get a basic interpreter for windows - this forum has pointed out a few in the past

ok, if you really must, google for commodore 64 emulatorFrom personal experience ... Older basic programs run too fast on newer systems, since most programs were based around a 1 to 4 Mhz CPU, and your Windows 98 machine is likely to be at least 25 times faster than that.

You may have to add ROUTINES to eat up or adjust the execution rate to get it to work as you want it to like  adding a loop

10 for x =1 to 1000
20 y=x
30 next x

To get it to count to 1000 before going further. Way back in the day when I programmed using Tandy-Basic, GW-Basic, and QBasic, I generally had to add these loops to slow down the operation if the hardware was more advanced than the prior systems running the programs. Especially since many of my programs were ascii characters moving around on the screen which you controlled and gameplay can be sped up or slowed by use of clock cycle eating loops.

Like the prior post, there are MANY MANY free interpreters out there. I still use GW-Basic that came with my DOS 2.11 and QBasic from DOS 6.22 however. and to have some control over the execution I run it in a Virtual PC 2007 Virtual DOS environment. You can control the programs execution rate by editing the code to add these clock cycle eating loops or change the PID of Virtual PC to be lower PRIORITY or greater priority to get execution rates changed.

I myself tried the C64 emmulator a while back and GOT bored with it, since you cant slap your C64 cartridge into your PC and make it work without finding a ROM file that someone skoffed off a ROM reader and posted for play as a Binary File to be imported into the emmulator.

When programming in Basic, I'd stick with a interpreter that runs in Windows without the need for emmulation. Emmulators are buggy, like the PlayStation Emmulator that I have that allows for play of PS1 games through my PC!any idea where to get this "interpreter"?google is your best friend

follow this link http://www.google.com/search?client=opera&rls=en&q=commodore+64+emulator&sourceid=opera&ie=utf-8&oe=utf-8thanks guys, any idea where I can learn C++ (I'm not too instersted in "Security Apps for Institutions")
So I can make my own small programs, and where I can find a free, semi-decent Compiler? (That's easy to use?)I refer you to my previous answer (Google it)

However, Microsoft are making freely available their 'express' version of the DotNet suite - http://www.microsoft.com/express/2005/

They are also showcasing the 2008 version of the suite
Graham*censored* is suite?? express?? uhh I'll chec kit out I guessExpress is the light version, which is free. Suite is the whole package which you pay for.
But the Basic interpreter (compiler) in Visual Studio 2005 is RADICALLY different from the old DOS basic interpreters. I don't think VS is the way to go.
How about a C64 emulator?
thnx... know where I can learn Perl?

1514.

Solve : For Dias de verano: Can I extract a portion of a file name??

Answer»

Yesterday you came to my rescue and showed me how to extract the DATE and convert it into a different format.  Today I have a similar file re-naming issue that I'm hoping you can help me with.

Same scenario as yesterday:  a dozen small files from multiple directories get copied into a single directory and then compressed into a zip file.  Each of these files has the creation date in the file name, and I WOULD like to extract that string of characters from the first file and INSERT it in the zipfile name.

I found a batch file in another thread that will sort the files so the same file name will always be on top from one day to the next, and the file name format will always be the same, a four (4) character file name preceding the creation date (which will always be the previous business day) followed by the file extension, with the three parts being separated by two periods, as in name.yyyymmdd.extension.

So my question today is, can that yyyymmdd creation date be extracted and saved as a variable for use in renaming the zip file?

Again, thanks in advance for any assistance you may provide.How flattering to be asked by name! But what a heavy responsibility.

Quote

the file name format will always be the same, a four (4) character file name preceding the creation date (which will always be the previous business day) followed by the file extension, with the three parts being separated by two periods, as in name.yyyymmdd.extension.

Have you worked out how you are going to isolate the filename that is "on top"? Is the extension always the same?

Never mind, the extension doesn't matter. All you need to do is extract the 8 characters starting at the 6th position from the start.

To slice a string variable...

You need a percent sign, the variable name, a colon ( : ) and a tilde ( ~ ). a number, a comma, another number, and a final percent sign.

if %string% is the full string

%string:~a,b% is the substring which is b characters long starting at position a.
(Start from zero)

so if %string% is abcd.yyyymmdd

%string:~0,4% will produce abcd

%string:~5,4% will produce yyyy

%string:~5,8% will produce yyyymmdd


Considering everything I tried yesterday before asking for help, I'm feeling kind of foolish at how I missed the solution entirely. 

Here is the syntax that isolates the filename, which I found on this forum a few weeks ago...

 FOR /F  %%i IN ('dir /b /a-d /o-d') DO (
        set firstfile=%%i
        )

...and ADDING %firstfile:~5,8% after, per your directions, yields the characters I need to properly name my file.

Thanks again!!
1515.

Solve : Simple Batch File Help.?

Answer»

I want to load one program and have it wait for a confirmation to load the next program. i know absolutely nothing about dos at all

but here are my directorys i need them to be,
C:\pbsetup.EXE
E:\COD4\iw3mp.exe
I take it this is from win xp command prompt....


type 'start /?' and have a read. take specail attention to the /wait switch.

If you wanted to add errorlevel caputre to your BATCH, type 'if /?' at the command prompt.

You could do if /i %errorlevel% GTR 0 (goto fail) else goto next.


Just something to get you thinking................
 
Quote from: zviper on March 07, 2008, 01:59:11 AM

I want to load one program and have it wait for a confirmation to load the next program. i know absolutely nothing about dos at all

but here are my directorys i need them to be,
C:\pbsetup.exe
E:\COD4\iw3mp.exe


Did you mean you want the batch file to start pbsetup.exe and get the user to do some stuff and exit from that program (close it down) and then, and only then, start up iw3mp.exe?

If so you want to something like this

start /wait "" "C:\pbsetup.exe"

REM This line and the next 4 lines are optional
echo Finished PBSETUP
echo Ready to start IW3MP
echo Press a key when you are ready
PAUSE>nul

start /wait "" "E:\COD4\iw3mp.exe"

echo All finished




that kinda WORKED. its runs the first exe. then when it tries to run the second exe, my game errors out when i try and launch it.

is there a possibility that a SHORTCUT can be launched instead of the iw3mp.exe ?try it and find out.......i dont know anything about dos.... Quote from: zviper on March 07, 2008, 11:17:44 AM
i dont know anything about dos....

WELL, it's up to you to change that.
I'm asking for some help to make a simple batch file, the least you could do is point me to the right infoYou got the right info. A little suggestion: lose the attitude. If the batch file is that "simple", how come you haven't written it yourself already?


1516.

Solve : Inserting today's date in a filename via a batch file?

Answer»

I've created a simple batch file that copies a DOZEN small files from multiple directories into a single directory and then compresses them into a zip file.  I have to do this each day, then ftp the zip file to a co-worker in another facility. 

The first PART of the file name will always be the same - let's call it zipfile.zip - but I need to append the current date to the end of the filename in a YYYYMMDD format to keep the filenames unique.

Is there a way, within a batch file,  to extract the current date, convert it to yyyymmdd format, and then rename zipfile.zip to zipfileyyyymmdd.zip? 

Thanks in advance...
 What is your local date format, i.e. what do you see (copy and paste it) when you type

echo %date% (press enter)

at the prompt?

Wed 03/05/2008 Quote from: NyteOwl on MARCH 05, 2008, 10:36:14 AM

Wed 03/05/2008

OK so it's US date format

Quote
Is there a way, within a batch file,  to extract the current date, convert it to yyyymmdd format, and then rename zipfile.zip to zipfileyyyymmdd.zip?

set today=%date:~10,4%%date:~7,2%%date:~4,2%
ren zipfile.zip zipfile%today%.zip


 
I plugged this into my existing batch file, and it worked like a charm.

Thank you so much for the assist!!

Quote from: Dias de verano on March 05, 2008, 11:55:26 AM
set today=%date:~10,4%%date:~7,2%%date:~4,2%
ren zipfile.zip zipfile%today%.zip


Just noticed this morning that the above syntax re-formats the date as YYYYDDMM as opposed to yyyymmdd.  Simple fix, though.  Thanks again! You're right; I guess I missed it because I'm used to the European dd-mm-yyyy format. But you overcame that.
1517.

Solve : Problem w/ creating alias?

Answer»

When I try to create and ALIAS I get the error"is not recognized as an internal or external command, operable program or batch file. " What is the PROPER way to create as alias in CMD?What do you mean by 'alias' ?

GrahamIn Unix / Linux you can do e.g.

alias ll=ls -l

and afterwards when you type ll at the bash prompt it is as if you had typed ls -l

here is a list of some aliases I have on my SuSe box

Code: [Select]alias attrib='chmod'
alias chdir='cd'
alias copy='cp'
alias cp='cp -i'
alias d='dir'
alias del='rm'
alias deltree='rm -r'
alias dir='/bin/ls $LS_OPTIONS --format=vertical'
alias edit='pico'
alias ff='whereis'
alias ls='/bin/ls $LS_OPTIONS'
alias mem='top'
alias move='mv'
alias mv='mv -i'
alias pico='pico -w -z'
alias rm='rm -i'
alias search='grep'
alias v='vdir'
alias vdir='/bin/ls $LS_OPTIONS --format=long'
alias which='type -path'
alias *CENSORED*='watch -n 1 w -hs'
alias wth='ps -UXA | more'

The reason, airhud868, why you got the error message is that CMD does not have aliases 

You could use SET I suppose, e.g.

set mydir=dir /w /a-d /on

and then type

%mydir% at the prompt or have it in a batch file (provided you had set it as an environment variable first)

But you would be better off creating a batch file and putting it on your PATH

Moral: CMD is not Linux (or Unix)

1518.

Solve : dir command echo containing folder?

Answer»

Is there a way to use the MS-DOS dir command to echo back the containing folder?

So, if I run this: ( c:\dir /s|find "userenv" )

my search eventually locates the "userenv" FILE however I don't know which containing folder has this file. So the output looks like this: ( 03/05/2008  11:02 AM           387,856 userenv.log )

When I WOULD like to have output like this: ( C:\temp\subdirectory  userenv.log )use the /b switch which will show the full path

dir /s /b | find "userenv"

I'm curious. Why are you PIPING this to the find command?
I got exactly the same output (in the desired format) from: Code: [SELECT]dir C:\userenv* /s /b as I did from: Code: [Select]dir C:\ /s /b | find "userenv" and it's less keystrokes.

1519.

Solve : run batch file on start up?

Answer»

Hi, I'm semi NEW to Ms-Mos and need a little help. I am wondering if it is possible to make a batch file that will make the computer run a seperate batch file every time the computer starts up? Let's pretend the first batch file's name is "batch1.bat" and the second batch FILES name is "batch2.bat" did you mean real MS-DOS or WINDOWS command prompt? if Windows, which version?
To have something start up with Windows (I'm GUESSING you're in fact using Windows and not MS-DOS) simply move the file to the startup folder located in your programs MENU. So batch1 isn't really needed at all.Window's command prompt. I would like to make a batch file that automatically puts a file in there or where ever the file needs to go. Why is there a smiley at the end of your post?
so by putting a file in the start up directory windows will run that file every time the computer starts up???yes. (Or more precisely, every time you log in.)Thanks!!!

1520.

Solve : Batch files help!?

Answer»

I need some help with a batch file I need to write, I am TRYING to do the following. I need to find all the files in location A with a file size of 0KB and replace the text in those files with an ERROR message saying something like "error when saving", and to add a little more complexity I need to skip over .red files. Thanks for any helpWhat do you have so far?Good question, Gurugary.
just what I found from searching this site, I don't really understand it though and it is not doing all it needs to be.
FOR %%F IN (*.*)DO (
IF %%~zF LSS 1 DEL %%F
)

ThanksOK, well you have something.  But it looks like this CODE is meant to delete files, not change their contents.  Have your got your FOR loop working?  And INSTEAD of DEL, do do some research on console redirection and the '>' symbol.  You should be able to replace the DEL command with your redirection.  Once you have that working, then we can work on skipping .red files

1521.

Solve : Check Date Modified?

Answer»

Hi all,

I want to know if i can check the DATE MODIFIED of a CERTAIN file from X drive and transfer to U drive.

If the date modified for the file in U drive is updated then it will do nothing. But if its different from the one in X drive than it will copy the one in X drive to U drive.

Tried searching for it. But they all give me some weird links.

Can anyone help?
Thanks in advanceI know how to copy the files from one drive to another. but DONT know if i can check the date modified.. can anyone help.. thanksYou don't mention your OS but at the XP Command Prompt, or in a script, you could use DIR with the /TW parameter to display the date written (DIR PATH\FILENAME.EXT).   I cannot find that the "date modified" is available.  If you accept that the date written and date modified are the same then /TW will give you a start at what you want.

Then you could extract the date written for both files (on U and X drives) and compare them.  If the date written on the source file is later than that of the destination file you could then copy.

Good luck.pipipo:

Is it necessary to do this using just commands available within your os?  (assuming XP).

Or do you just want to get the job done?

I ask, because it seems like what you are describing is just what some backup software does.    If you could use one of the free ones out there,  you'd be set.


1522.

Solve : Shortcut.exe?

Answer»

I was woundering how to create a SHORTCUT using a DOS batch COMMAND line and I could'nt find the ANSWER on CH...

As I searched the net I found out it was possible with the EXTERNAL command SHORTCUT.EXE found here.

you first need to extract it with this command : echo y|envars -o shortcut.exe

then here are the switches to it :



The only problem with this is, I have yet to successfully create one...

1523.

Solve : How do I fdisk??

Answer»

I was wondering I'm new to this site I'm trying to fdisk my computer is there some step by step info to do this ALSO my floppy drive dont work do I need the floppy to do the fdisking? I have windows xp right now after I do the fdisk can I just install my windows xp CD will it load? From Our Archives...

NOTE: RUNNING FDisk will wipe all data on the drive so make sure you backup what you need.

You can also wipe the partition DIRECTLY from the XP CD in the beginning of the install as well.
Just insert the XP CD POWER down and re-boot. Follow the onscreen guides to deleting and re-creating the partition...

1524.

Solve : Printing from DOS to Tray 2??

Answer» HELLO all. I have been scanning thru the posts and have not seen any reference to Printing in DOS to tray 2 yet.

Is it possible?

KenTray 2 on what kind of printer?  My (very) limited experience suggests that selecting a tray is done at the PRINT driver LEVEL.  Even in the old days of using DOS, I don't remember a way to point a print job to a particular tray output.

This is, by no means, the last word on the subject!!  If the printer supports PCL5 then commands can be sent to select the tray. Many HP printers support this.


Sorry, it is an HP4000

Dias de verano, can you supply the DOS commands to do this please? I have never seen anything like this.

KenYes, this is interesting...They are called 'escape sequences'. This used to be the way printers were controlled. Dot matrix and laser printers especially used printer control languages such as ESC-P (Epson) and various flavours of PCL (HP and OTHERS). The HP4000 can use PCL5e I believe. Check a PCL5 reference manual for details of how to control the printer using Escape Sequences.

There are PCL5 drivers on the HP CDROM that came with the printer. If you do not have it, contact HP.




Escape Sequences for the HP4000 are here.

  I'd completely forgotten about escape sequences -- completely.

Let us know, KenL, how this works out for you.I looked up the escape sequences and this is not going to work for me. I would have to embed this into every report I produce and thus would require my client to print from tray 2 for every printer/report.

I need something I can trigger by the print statement or by setting up a separate QUEUE on the server which defaults to the second tray. As of right now I have told my client to purchase another printer.

I still want to figure this out. I have also looked at using START/MIN NOTEPAD /P filename.txt but that messes with the page length so my headings are not at the top of the page.

I have also looked into creating a PDF file. One I tried from SourceForge.net required installing all kinds of other software (python, etc) and didn't work so I gave up.
1525.

Solve : Help.....Anyone?

Answer»

I have a report which is on my c: drive and I want to create a batch file which will  take me to the LAST page of this report which contains the phrase Totals and display it.Not really ENOUGH details, but you might use the find command:

CODE: [Select]find /i "totals" c:\yourfilenamehere

This will find all occurrences of "Totals" so if you can make the search argument more UNIQUE, by all means do so.

 remember though that there may be many "Totals" phrases in the document. the only way to view it ENTIRELY is 2 use the type command.if you can download and install gawk from here:

Code: [Select]# save the below code as script.awk
/Totals/{ last=$0 }
END{
 print last
}
output:
Code: [Select]C:\test>more new.txt
line 1
Totals 1
line 3
Totals 2

C:\test>gawk -f script.awk new.txt
Totals 2

1526.

Solve : MS DOS 6.8?

Answer»

Dear All,

I need this DOS  ver 6.8 to run a old software. May I know where to download that DOS version.

Or PLEASE ANYONE can send me those DOS version files for me to create a STARTUP disk .  [email protected]

Thank you

email addy removed to prevent SPAMMS-DOS is not freeware so we cannot send you a copy or tell you where to download it. If you really need it you will have to buy it.
Try on eBay or Amazon.
But you may want to try alternative options, a DOS emulator like DOSBox for example.
Or if you need a complete operating system Caldera DOS may be an option.
http://esca.atomki.hu/paradise/dos/opendos-en.html
I'd like to know what the "old software" is, since the last OFFICIAL version of MS-DOS 6.x was version 6.22.

Maybe it's some unofficial gamer's hacked version, in which CASE you're on your own, buddy.

1527.

Solve : if exit..?

Answer»

how do i make it so that if the ms-dos is exit that it will then start a file or a code?
and for this code here i would like it for when it goes to equ 1 and equ 3 how do i make it so that they goto a differnt secton

set /a var=%random%%%4



if %var% equ 0 set one=I like it cause of that to.
if %var% equ 1 set one=eww, are you sure?
if %var% equ 2 set one=Wow, never thought of that.
if %var% equ 3 set one=Are you sure?
echo %one%the word 'sure' is spelt thus.
well if u want the code to exit to start another bat file then make another batch file, and then type the code like this on the first batch file
Code: [Select]start <name of batch prog>
exitand then for the batch code above if u want it to goto different sections try this
Code: [Select]set /a var=%random%%%4



if %var% equ 0 set one=I like it cause of that to.
if %var% equ 1 set one=eww, are you shurr?
if %var% equ 2 set one=Wow, never thought of that.
if %var% equ 3 set one=Are you shurr?
echo %one%
pause
goto %one%
then for the different sections make sure u type a colon before the label but there cant be any spaces in the label or else DOS will close the program. so try this to mark each section(this label will mark the "I like it cause of that to" section- :Ilike)
try the ":Ilike" label for that particular section make sure it has a colon and that there ARENT any spaces. Quote from: macdad- on March 20, 2008, 09:27:20 AM


Code: [Select]goto %one%

You can't do this. (EXPAND a variable to a label name & goto it)



ok...now try this
Code: [Select]set /a var=%random%%%4



if %var% equ 0 set one=I like it cause of that to.
if %var% equ 1 set one=eww, are you shurr?
if %var% equ 2 set one=Wow, never thought of that.
if %var% equ 3 set one=Are you shurr?
echo %one%
pause
label %one%
goto oneFrom testing, I discovered you can in fact expand a label name go to it:

Code: [Select]set  one=two
if errorlevel 0 goto %one%
goto :eof

:two
echo %one%

If you leave echo on you can see the expansion in real time. You cannot however expand a variable as part of a label:

Code: [Select]set  one=two
if errorlevel 0 goto %one%
goto :eof

:%one%
echo %one%

  Quote from: macdad- on March 20, 2008, 11:59:59 AM
label %one%

What does this line do?

PS Can we spell "sure" properly please?


Quote from: Sidewinder on March 20, 2008, 12:49:11 PM
From testing, I discovered you can in fact expand a label name go to it:

So you can, I now see. I was always taught that self-modifying code is a bad idea, however.

Quote
You cannot however expand a variable as part of a label:

I think that was what I was thinking of.
Quote
So you can, I now see. I was always taught that self-modifying code is a bad idea, however.

Amen Debugging such a beast can be a nightmare. Just because you can do something is no reason....

I'm still trying to figure out what the OP meant by if the ms-dos is exit And somebody else needs to look up the label command...
Quote
the word 'sure' is spelt thus.

Thus SPAKE Zarathrustra Quote from: Aegis on March 20, 2008, 02:48:16 PM
Quote
the word 'sure' is spelt thus.

Thus Spake Zarathrustra


Thus Spoke Z a r a t h u s t r a  (German: Also sprach Zarathustra, sometimes translated Thus Spake Zarathustra), subtitled A Book for All and None (Ein Buch für Alle und Keinen), is a work by German philosopher Friedrich Nietzsche, COMPOSED in four parts between 1883 and 1885. It famously declares that "God is dead", elaborates Nietzsche's conception of the will to power, and serves as an introduction to his doctrine of eternal return.

Described by Nietzsche himself as "the deepest ever written", the book is a dense and esoteric treatise on philosophy and morality, featuring as protagonist a fictionalized Zarathustra. The text encompasses passages of poetry and song, often mocking Judaeo-Christian morality and tradition.
well what i guess what im trina do is something like this .,.its not correct because i dont know what to do

if %var% equ 0 set one=I like it cause of that to.
if %var% equ 1 set one=eww, are you sure?
if %var% equ 2 set one=Wow, never thought of that.
if %var% equ 3 set one=Are you sure?
echo %one%
if if %var% equ 1 set one=eww, are you sure? goto h

:h
why do you think this?
set /p choice=



so like i want it that if the choice of if %var% equ 1 set one=eww, are you shurr? is picked i want that one to go to h and just that one.

how do i do that
if %var% equ 0 set one=I like it cause of that to.
if %var% equ 1 set one=eww, are you shurr?
if %var% equ 2 set one=Wow, never thought of that.
if %var% equ 3 set one=Are you shurr?
echo %one%
if if %var% equ 1 set one=eww, are you shurr? & goto h
goto skip

:h
why do you think this?
set /p choice=

:skip
correct
1528.

Solve : make the .bat save it's self?

Answer»

sorry I'm a bit of a newbie when  it comes to dos but Ive made a simple program to run a few things i want the .bat to save it's self to a specified location so it can be called is this possible THANK you.
       and so you don't get suspicious (i know it happens) i need it to save as my Friend wants a copy of the .bat
   once again thank you
                                     king kingbillIm not ENTIRELY sure what you want; if you have created a batch file, then by definition, it is saved.

If you want your friend to have a copy, then all you need do is GIVE it to him.

If you are emailing it to him, then you need to make clear to him where to save it (is it this that you wanted to automate ?)

Grahamyes it is i need it to auto save it's self to a locationI agree with gpl; it is not at all clear why you want to do this. Just tell your friend which location to save it to. And here's another question. Why can't "your friend" decide where to save it to? Why do you have to tell him?


sorry im not clear. and i dont need to tell my friend where to save it. maybe i should re phrase my question.Ok here goes, i want to make the .bat file rune every time the computer is started how do i do that?

hope thats better Quote from: kingkingbill on March 10, 2008, 12:27:48 PM

sorry im not clear. and i dont need to tell my friend where to save it. maybe i should re phrase my question.Ok here goes, i want to make the .bat file rune every time the computer is started how do i do that?

hope thats better

Not really; now we know you want to make a batch file which, when run, without the computer owner doing anything, saves itself to somewhere that it gets run every time the computer starts. You could have a perfectly harmless reason for wanting to do this, you could have a very bad reason. We don't know. I don't feel that it is a good idea to place details of how to do that on a forum like this.
i can asure you it is for a good reason i just want to start a few PROGRAMS such as fps creator on STARTUP and i want them to run every time. if you are not willing to tell me how to do this in public can you p.m me thank youIf thats all you want to do, why not just drag a few shortcuts to the startup folder ?
GrahamThere gpl told you
i want the programs to be run automaticly on startupAnd they will do so if you follow gpl's advice... Quote from: kingkingbill on March 10, 2008, 12:36:03 PM
i can asure you it is for a good reason i just want to start a few programs such as fps creator on startup and i want them to run every time. if you are not willing to tell me how to do this in public can you p.m me thank you

Oh right like I was born yesterday...  i seriosly do, it would help me a lot and save me time because i dont want have to open darkbasic,fpscreato,milkshape,3dsmax,notpad and other manulallyDarned if I can find it but this topic has done the rounds before tho' not from KKB.  Turned out that the .bat was to be installed on other computers to cause havoc when remotely called.

Nobody would advise then either.I agree with most on this. I cant see any valid reason why you'd want it to save it's self on a remote machine.

If this is just to help a mate out, make the batch on your machine, save it as a a txt file and email it to him, get him to change the file extention back to .bat and put in the startup folder.

Now I think of it, this could be done remotely without the remote users knowage but I'm not going to post that here......
1529.

Solve : About runing?

Answer»

Hi all , I typed in the run
Code: [Select]\\80.242.118.*\C [\code]

And I do not KNOW how to SET a password for a network , to ENTER .
I have a user pass. If you do not understand what i mean PLEASE let me know .

1530.

Solve : mode300 opposite?

Answer»

is there a command I can use to make the WINDOW NORMAL SIZE again after it is set to mode300?

1531.

Solve : Look at part of a variable...?

Answer»

I've got the following CODE:

   Set /P Input=     Selection:
   For /F %%a in ('dir /B /O /A:D *.*') Do (
      Echo %%a
      Pause
      )

Right now, it echos the folder name (in alphabetical order), pauses, and REPEATS echoing the next folder name in the list.  I want to be able to take the variable (%%a) and find out what the first 4 characters of the folder name so that I can compare it against what the user inputed.  From there, I can write the batch file to do what I need from the folder the user selected.  Is there a way to do this?

Thanks.There are probably a few ways to do this.

Code: [Select]echo off
set /p input=    Selection:
for /f "TOKENS=* delims=" %%a in ('dir /b /o /a:d ^| findstr /i /b /c:"%input%"') do (
echo %%a
)

Good luck. 

The compare is set up as case insensitive. Remove the /i switch from the findstr command if necessary.

slice string THUS

%var:~offset_from_start,number_of_characters%

The first character has an offset of zero

so if var=chicken

%var:~0,4%=chic

and

%var~4,3%=KEN



1532.

Solve : renamiing multiple files?

Answer»

I have about 1000 .bmp files that all have the prefix 'Copy of' in front of them.
What is the DOS command line to rename them deleting only the 'Copy of' ELEMENT?
Hope you can helpPost this message to a programing  language C forum . That would be easy for them .It's a BATCH problem pure and simple. Is the part after 'copy of' UNIQUE in each case?

provided you only have all "copy of" files and not their originals, here's a vbscript
Code: [Select]SET objFSO= CreateObject("Scripting.FileSystemObject")
Set colFolders = objFSO.GetFolder("C:\test")

For Each oFile In colFolders.Files   
    If InStr(1,oFile.Name,"Copy of",1) > 0 Then
    newName = Replace(oFile.Name, "Copy of ","")
    oFile.Name= newName
    WScript.Echo oFile.Name
    End If
Next

1533.

Solve : Strip the READ ONLY Attribute from mutiple files..???

Answer»

I KNOW how to STRIP the READ only attribute from a single file, but how would i strip the read only attribute from multiple file types in multiple sub-folders that are in one single folder..??Try:

CD FOLDERNAME
ATTRIB -R  *.*  /S

Good luck

1534.

Solve : hard drive password / HELP?

Answer»

I have a laptop that has a hard drive password, but don't what it is.. when the computer boots , it goes to a white screen asking for hard drive password.. how can I get PASS this password.. can someone help me!!!!!!!!!!!!!!!!!!!!!!!!!!!! pleaseYou'll need to get the password from the previous owner of the laptop...is there any way to bypass the password?  I bought it at a yard sale.....It may be possible to get past the password. (It depends on several things.)
We really need more information.

1. What Brand & Model is the laptop? (There may be a backdoor password.)
2. Does it have a cd-rom drive?
3. Does it have a floppy drive?
4. Do you have a boot floppy, or Boot CD? (A windows cd will do)
5. Try to boot with a windows cd(or boot floppy) and see if you get the same error.

I'm not sure what you mean by:
Quote from: ctmyers on March 19, 2008, 08:48:30 PM

hard drive password

6. What is the exact wording of the error message?


There is no backdoor METHOD for hard drive passwords.
If you got it at a yard sale chances are your cash outlay was not that high...i'd start looking at replacement hard drives or contact a repair facility.Why do people buy these used laptops? The one described at the start of this thread would not be much use even as a gift. One possible problem with used laptops bought from an untraceable stranger in a non-commercial setting is that he or she may or may not be the legal owner of the machine. Even if they are, they may be less than totally open about its condition. (!) I would certainly want to see it running and would also want to see BIOS and hard drive passwords shown to me and also used and verified in front of me before I parted with any cash. If not, I would consider it a scrap machine to use for parts only, and would value it according to that, and also consider its age and spec. (I wouldn't buy a used laptop like this anyway.) The legal owner should be aware of these issues and ready to address them for you. Otherwise all sorts of problems can arise.  Not much use to the OP I guess,  but worth bearing in mind.

The last person who asked me to unlock his newly "bought" used laptop (I didn't) is now in jail.

You can get some hard drives unlocked by PAYING a fee, $100 is a typical sum, to a data recovery service. The following is on a website I found.

Some laptops provide a utility to lock a hard disk with a password. These passwords are not the same as BIOS passwords. Moving a locked hard disk to another machine will not unlock it, since the hard disk password is stored in the hard disk firmware and moves with the hard disk. Also, adding a new (unlocked) hard disk to a locked machine may cause the new hard disk to become locked. Also, note that hard disk lock passwords cannot be removed by reformatting the disk, fdisk or any other software procedure (since the disk will not allow any reads or writes to the disk, it cannot be reformatted.)

You can test to determine if your hard disk is locked by attempting to access it in another laptop.




GREAT additional info there Dias....

I was too tired to swim thru my notes.
1535.

Solve : im stuck and need a solution :(?

Answer»

im about to MAKE a proxy pinger i want it to read from a text document and ping each line:

echo off
:q
for /f "tokens=* delims=" %%i in (proxy.txt) do %%i
ping %q% -n 3
goto q

im sure this doesnt work but i want some thing like it, that can read and ping proxys from a file, the proxys have there port numbers on so its not possible to ping an ipnumber with proxy following, i will giva an example:

proxy.txt CONTAINS following:
65.112.187.218:3128
64.76.58.132:3128
200.31.74.242:8080
200.96.157.66:3128
203.160.1.146:553
221.234.242.3:8080
200.167.148.68:8080
67.207.145.238:3128
12.149.212.1:80
200.219.152.6:8080
81.140.160.10:3128
83.229.21.4:8080
220.31.156.91:8080

and i want q.bat to ping the proxy.txt list example following:
ping 65.112.187.218
echo sent=3 recived=? speed=?
ping 64.76.58.132
echo sent=3 recived=? speed=?
ping 200.31.74.242
echo sent=3 recived=? speed=?
and so on following from the list...

its pretty hard to explain but i hope you will understand any one have a solution for this?The LOOP should look like this
Code: [Select]echo off
for /f "tokens=1,2,3,4 delims=." %%a in (proxy.txt) do (
     ping %%a.%%b.%%c.%%d -n 3
     )
Quote from: Dias de verano on March 21, 2008, 10:00:18 AM

The loop should look like this
Code: [Select]echo off
for /f "tokens=1,2,3,4 delims=." %%a in (proxy.txt) do (
     ping %%a.%%b.%%c.%%d -n 3
     )



thank you but the port numbers are still following... the port numbers have to be TAKEN off before able to be pinged.Sorry I LEFT out a colon in the delims section

Code: [Select]echo off
for /f "tokens=1,2,3,4 delims=.:" %%a in (proxy.txt) do (
     ping %%a.%%b.%%c.%%d -n 3
     )

1536.

Solve : Insert a blank line in a text file using echo command??

Answer»

Hey, I'm trying to create a batch file to INSERT text into a text file using the echo command.

ECHO newtext >> textfile.txt

But the text is always added STRAIGHT ONTO the end of the last line, whereas I would LIKE to have this text on a new line.

Is there any way to do this?

Thanks in advance echo. Hello >>"C:\path\to\file.txt"
echo.  >>"C:\path\to\file.txt"
echo. How are you? >>"C:\path\to\file.txt"

The period 'echo.' is used to add a blank line.Thanks a lot, SORTED it straight away No problem.

1537.

Solve : For loop command and user input...?

Answer»

Is there anyway of using the For-do loop command to continually loop to a character is inputed from the keyboard, and based on that input script to do other commands?  BASICALLY, Set /p FUNCTION allows me to input something, but then I'm needed to hit AFTERWARDS and I want to just hit the character and move on.

Thanks.If you have a Win9x machine you can use the CHOICE command. Check here for details.

If you have a WinNT machine you can download choice from here.

Going back to the future are we?

1538.

Solve : change xp user account type by only using cmd?

Answer»

is there any way from an admin ACCOUNT on an xp pro pc to only use cmd to change a users account type from limited to another admin when you know the PASSWORD for that limited user account.

I know its easier to just to do it from the "User Accounts" applet in the control panel but i want to do it only by using the CMD though..

so is this possible at all.
If so then how would i go about doing it then..??

thanx for anyones help.YES, it should be pretty easy.  I think a limited account is just an account that is not a member of the local administrators group.  Assuming that is the case, it should work by doing:
Code: [Select]net localgroup Administrators gumbaz /addJust change "gumbaz" to the account you want to promote.  If you want to take it back down, then try:
Code: [Select]net localgroup Administrators gumbaz /deletehey thanks, it worked...
now is there a way to CHECK to see what each users account type is via only CMD so it lists them out like:
Bob  -  Admin
Jane - Admin
Sam - LimitedI wrote a batch file a while back that does something very similar as part of its task.  Here is a modified version that is probably overkill for what you are looking for, but it should do what you want:
Code: [Select]echo off

setlocal
echo.
echo User accounts found:
echo --------------------
call :ProcessAccounts EchoUsers
goto :EOF

:ProcessAccounts
for /f "delims=" %%a in ('net user ^| find "     "') do call :ListAccountsSub "%%a" %~1
goto :EOF

:ListAccountsSub
rem Check for blank fields by testing for null string where spaces should be
set unam=%1
if "%unam:~21,2%"=="  " call :%2 "%unam:~1,20%"
if "%unam:~42,2%"=="  " call :%2 "%unam:~26,20%"
if "%unam:~71,2%"=="  " call :%2 "%unam:~51,20%"
goto :EOF

:EchoUsers
net localgroup Administrators | findstr /i /c:%~1>NUL
if not ERRORLEVEL 1 (set type=Admin  ) else set type=Limited
echo %1|findstr /I "Administrator ASPNET Guest HelpAssistant IUSR IWAM krbtgt Support_ tmpl">NUL
if errorlevel 1 (echo %~1 - %type%) else (echo %~1 - %type%  ** Probably a System Account)
goto:EOF
would you mid explaining a lil about what each part of that code does exactly please.??

Also is there a way to script some batch code to put all the non Admin users into the Admin group regardless of what name the user has, so like some type of variable that just looks and sees all the users available that are not admins and then changes all those limited accounts into admins...

is there anyway to do that..??No problem.  Here is the code with comments:
Code: [Select]echo off
rem Store the existing environment
setlocal
echo.
rem Echo header to the screen
echo User accounts found:
echo --------------------
rem Call the ProcessAccounts function
call :ProcessAccounts EchoUsers
rem After function is run goto the EndOfFile (exit the program in this case)
goto :EOF

:ProcessAccounts
rem Process each line of the "net user" command and pass the information to the LisAccountsSub function
for /f "delims=" %%a in ('net user ^| find "     "') do call :ListAccountsSub "%%a" %~1
rem After function is run, goto the EOF (go back to the calling function in this case)
goto :EOF

:ListAccountsSub
rem Check for blank fields by testing for null string where spaces should be
set unam=%1
rem The net user command lists the names in 3 columns.
rem If there are spaces at specified locations, then there should be a valid name before the spaces
if "%unam:~21,2%"=="  " call :%2 "%unam:~1,20%"
if "%unam:~42,2%"=="  " call :%2 "%unam:~26,20%"
if "%unam:~71,2%"=="  " call :%2 "%unam:~51,20%"
After the function is run, goto the EOF (go back to the calling function in this case)
goto :EOF

:EchoUsers
rem run the net localgroup Administrators command, and compare the results to the current user
net localgroup Administrators | findstr /i /c:%~1>NUL
rem If the findstr does not have an errorlevel of 1, then the name was found.
rem If the name was found, then that user is probably a member of the local Administrators group
rem Note that if there is a short name contained within a longer name that is also a user this may be a false positive
rem if the user is not a member of the Administrators group, they must be a "Limited" user
rem Set the TYPE variable to output later
if not errorlevel 1 (set type=Admin  ) else set type=Limited
rem if the username contains any of these names, then it is likely a system account not created by the user
echo %1|findstr /I "Administrator ASPNET Guest HelpAssistant IUSR IWAM krbtgt Support_ tmpl">NUL
rem Output the results of what we found for this user to the screen
if errorlevel 1 (echo %~1 - %type%) else (echo %~1 - %type%  ** Probably a System Account)
rem goto EOF, to continue the loop until we run out of information
goto:EOF
And, yes there is a way to put each user in the Administrators group ... but I wouldn't recommend this.  But if you REALLY want to do this, you could add a line like:
Code: [Select]if %type%==Limited net localgroup Administrators %1 /AddBut, again; I would recommend against doing this.sorry that code just seems a lil too advanced for me.. 

how would i code just a simple lil bat script to just convert all available accounts to Admin accounts with no confirmations or what not..

I'm sure its probably not recommended to do this, but its for testing purposes in a vmware environment though.

1539.

Solve : I'm stumpted.. why isn't this working??

Answer»

Here's my code below.  I've setup the batch file to read the directories in a folder, and then list them in ALPHABETICAL order with a number beside it so the user can then choose which folder they want to use.  The problem is that the counter (which numbers the folders) isn't progressing, and I can't figure out why!   


:ListFolders
SetLocal
Set Input=0
Set Count=1
Set Folder=%1
Echo Choose a Folder from Below:
For /F %%a in ('dir /b /o /a:d C:\MainFolder\%Folder%\*') Do (
   Echo %Count%  ==  %%a
   Set /a Count=Count+1
   )
Set /P Input=     SELECTION:


Is there something in the code I'm missing, or perhaps a global setting/variable that I don't have that I need?

Thanks. Quote from: Feidom on March 21, 2008, 03:02:43 PM

Is there something in the code I'm missing, or perhaps a global setting/variable that I don't have that I need?

See red items

:ListFolders
SetLocal enabledelayedexpansion
Set Input=0
Set Count=1
Set Folder=%1
Echo Choose a Folder from Below:
For /F %%a in ('dir /b /o /a:d C:\MainFolder\%Folder%\*') Do (
   Echo !Count!  ==  %%a
   Set /a Count=!Count!+1
   )
Set /P Input=     Selection:Just out of CURIOSITY, what does that line do exactly? Quote from: Feidom on March 21, 2008, 03:35:29 PM
Just out of curiosity, what does that line do exactly?

Normally, in a WINDOWS NT family batch file, ordinary variables (the ones with percent signs like this:  %variable%) are expanded just once, at run time. This includes variables inside loops. This means that a variable cannot be created or its value changed in a loop or a multiline IF STRUCTURE. To make that possible, Windows 2000 introduced a new feature - delayed expansion. To use this you need to do the following...

1. Enable delayed expansion by either
   
    (a) start a command shell using CMD /V:ON

    -- or --

    (b) include the line
         
         setlocal enabledelayedexpansion

         in a batch file before using delayed expansion

-- AND --

2. Use exclamation marks (!) instead of percent signs (%) around variables as in my suggested code above.


Type cmd /? at the prompt and/or Google for "delayed expansion" for more information, and very possibly a better explanation than I have given here.



1540.

Solve : Backing up files DOS based CNC machine?

Answer»

At work we have CNC milling machines from the late 80’s.  The machines OS runs on a version of DOS.
Recently we have had a few hard drive failures resulting in the loss of stored files that are used to run production. It is the MACHINE operator’s responsibility to back up their files. Let’s just say that some people ignore responsibility.

The CNC machine OS has a utility to back up all data form a directory on C: named PGMFILES (C:\PGMFILES) to the floppy disk drive A:\

Here is my problem; I can only fit 224 files on the floppy disk. The diskette is not full but I believe there is some sort of limit in the file allocation table allowing only 224 files. This might have something to do with the file names I’m not sure.  So when I try to back-up 1900 files it just stops at 224.  It does not ask me to insert a second floppy disk. It just quits.

 I tried to boot the machine into dos and copy the files from the C:\PGMFILES directory to A:\  It copied the first 224 files and then told me the disk was full. It did not ask me to insert another disk.

I tried to fill a floppy in windows XP with many small files and it only allowed me the same AMOUNT (224). Though, XP will PROMPT for a second disk.

What I need is some sort of utility for dos that I can boot form the floppy drive (or copy to the c drive) that will allow me to backup the data and prompt for a second, and third disk.

I know I could remove the HDD from the CNC and install it into a pc and copy all the data but this equipment is old and, it likes to break when you touch things inside the control cabinet.

Is there anything like this available?

If not, is it possible to right a batch file to prompt for a second disk?

Thanks, Great SITE!!
Quote

What I need is some sort of utility for dos that I can boot form the floppy drive (or copy to the c drive) that will allow me to backup the data and prompt for a second, and third disk.

Versions of DOS came with backup and restore utilities. Have you checked them out? If your DOS version is Microsoft, the backup utility would be named MSBACKUP.

 The root directory has a limit to the number of files it can store -- are you able to backup to a folder on the floppy (A:\Backup for example) ? There is not the same limit there

Or grab a dos based zip program (pkzip / pkunzip)

Graham Quote from: gpl on March 25, 2008, 08:46:36 AM
...
Or grab a dos based zip program (pkzip / pkunzip)

Side note for the op:
It's not as easy to find as it used to be.     Original self-expanding archive name is    pkz204g.exe   .   Easier to find if searching for that.

Here are some places to find it:
http://www.computercraft.com/docs/pkz204g.shtml
http://www.filewatcher.com/m/pkz204g.exe.202574.0.0.html

Maybe take a look at something like this?

http://usbflashstore.com/smarsecdigfl.html

Quote from: Sidewinder on March 25, 2008, 08:15:12 AM


Versions of DOS came with backup and restore utilities. Have you checked them out? If your DOS version is Microsoft, the backup utility would be named MSBACKUP.

 

Thanks for the response,after looking in the DOS directory on the C: drive there is msbackup.exe

I will try this later when the machine is not in use.

To everyone else that answered, thank you all very much. I will look into all of the options and see what works best.  I'm trying to make it easy for myself and the the other guys to back up regularly.

Hi all ,
I would you recommend you to use Norton Ghost and clone that old hard disk to new fresh one . I hope that this will help you .Thats a good suggestion but a company called EMI INC supplies a Disk on Module (DOM). It's a solid state disk drive that has the machine OS pre-installed.  All I have to do is make sue that the programs we use for production are backed up.  The machines are picky about things like the HDD SIZE and cylinder heads so the DOM is awesome for when one of our HDD goes out.  It's hard to be leave that some of theses hard drives on our machines are 15+ yrs old.

I tried the msbackup seems like that will work.  I also looked into pkzip, it looks like this will work as well. I also tried making a directory on the floppy and copying the files to that directory and that worked too. 

Thanks agian everyone for the help.
1541.

Solve : Does anyone have a DOS change script??

Answer»

Hello all, well I went and did it...I "UPGRADED" to Windows XP x64...and my trusty CHANGE.EXE program from Bill Guthrie (http://users.erols.com/waynesof/bruce.htm) no longer WORKS. Says it is from a different operating system. I have sent Bruce an email, but in the mean time;

Has anyone created a similar program in a BAT file? or does anyone have anyting that I can use to create one?
I would prefer to do it in a straight BAT format for EASIER maintenance.

KenThis is probably more down and dirty than your utility, but it works ok as a generic search and REPLACE:

Code: [Select]echo off
setlocal enabledelayedexpansion
set txtfile=c:\scripts\text.txt
set newfile=c:\scripts\text.chg

if exist "%newfile%" del /f /q "%newfile%"

set /p search=Search String=
set /p replace=Replace With=

for /f "tokens=*" %%a in (%txtfile%) do (
   set newline=%%a
   set newline=!newline:%search%=%replace%!
   echo !newline! >> %newfile%
)

You should have no trouble making modifications.

1542.

Solve : Script Run when process ends?

Answer»

OK I don't know if this is possible but I am looking to have a script that monitors a process so that when it ends it will shut the machine down.  How would I create this and is it even possible?What KIND of process?
Its just an application i have set to run at start up on my device.  Its just a run of the mill *.exe file.  If there is any more or more specific information NEEDED please let me know.

Thanks,

EDIT: I FORGOT to mention the exe file is for Internet Explorer.  I know this is an odd question but it will make a world of a difference if I can find a way to do this.an exe file for Internet Explorer? You need to explain more. Why so secretive?

does it show up in tasklist?

(open a command window, TYPE tasklist at the prompt, hit Enter and study the list that is generated.)


Sorry to seem so secretive its a combination of possible processes depending on what path I want to go down.  This is actually something I am working trying with VMware and my hardware device.  The process that I am leaning towards is Iexplore because I can USE that as a shell for my VMware software to run and when its done I want the actual hardware system to shut down.  I am also looking to possibly go Linux on teh base system also so if it would be easier to go with Linux I am up for that option to but would still need the same help.

Possible processes include:

iexplorer.exe
wswc.exe

Any help would be great

1543.

Solve : Need to pull info from a large number of text files in a directory?

Answer»

I need to pull info from a large number of textfiles in a directory and aggregate this to another textfile. The info needed is two lines (line 1 and line 9) in the textfile, and these lines are consistently lines 9 and 16 across all the textfiles.

I need this info from all the files. The textfiles however are unique to that folder structure e.g
1st textfile = U:\abailey\NetLogon.txt
2nd textfile = U:\ablay\NetLogon.txt
3rd textfile = U:\abreen\NetLogon.txt etc...

Can you please HELP me with this one, or even let me know if its possible to do, because I really want to get this now at this stage :-) Thanks!Yes it is possible to do.

Is the folder structure like this

Root folder of drive U\aname\Netlogon.txt

Also in your question, first of all you said

Quote

The info needed is two lines (line 1 and line 9) in the textfile,

Then you said

Quote
these lines are consistently lines 9 and 16 across all the textfiles.

Which is it?



                Dias, i think he wants to take the info from lines 1 and 9 in the text files then copy the info, and then paste the info to lines 9  and 16 on one txt file.dec27 i will find how to do that but in the mean while i need to know what operating sys u ar using so i can get the correct code. Quote from: macdad- on March 18, 2008, 05:25:03 PM
Dias, i think he wants to take the info from lines 1 and 9 in the text files then copy the info, and then paste the info to lines 9  and 16 on one txt file.

That's a very odd requirement indeed, if that is so.
try this.

Code: [Select] echo off
cls
md admin
copy U:\abailey\NetLogon.txt \admin
copy U:\ablay\NetLogon.txt \admin
copy U:\abreen\NetLogon.txt \admin
echo Login Information Archived
pause
exit
i tried doing wat u said by copying specific lines but it cant be done automaticly. the code above will copy the "NetLogon" files from each of the folders to a folder that will be created automaticly called "admin". make sure u copy the code above to notepad and save it as a bat file.
hope this works for u. Quote from: macdad- on March 19, 2008, 11:20:22 AM
i tried doing wat u said by copying specific lines but it cant be done automaticly.

Yes it can.
how? the only way i can think of copying specific lines is by using edlin but u can only do that manually.Set a counter variable equal to 1 using set /a

Read the text file line by line in a FOR loop, adding 1 to the variable each time with set /a

If the variable value is equal to the line number number desired, do something with that line.

Or you can use SED but that is not part of Windows so some PEOPLE MIGHT think it was cheating.


I am not trying to hijack this or anything but I am having the same problem but I am looking at only trying to find a certain lien that could be anywhere in the text file but I am looking through at this time about 4,000 files.  I am not ever sure where to start on the coding of this.  Is there a way to do this since It is a bit different than what the original poster is trying to do.This is how you get a selected line from a text file without using SED

Code: [Select]
echo off
setlocal enabledelayedexpansion

REM create test file

echo 1 Line one > test.txt
echo 2 Line two >> test.txt
echo 3 Line three >> test.txt
echo 4 Line four >> test.txt
echo 5 Line five >> test.txt
echo 6 Line six >> test.txt
echo 7 Line seven >> test.txt
echo 8 Line eight >> test.txt
echo 9 Line NINE >> test.txt
echo 10 Line ten >> test.txt
echo 11 Line eleven >> test.txt

REM show test file
echo.
echo Here is the test file:
echo.
type test.txt
echo.
set /p chosenline=Choose a line to display?
echo.
set /a line=1
for /f "delims==" %%L in (test.txt) do (
if !line!==%chosenline% echo %%L
set /a line=!line!+1
)
echo.

Quote from: guardian on March 19, 2008, 12:06:01 PM
I am not trying to hijack this or anything but I am having the same problem but I am looking at only trying to find a certain lien that could be anywhere in the text file but I am looking through at this time about 4,000 files.  I am not ever sure where to start on the coding of this.  Is there a way to do this since It is a bit different than what the original poster is trying to do.

Describe some features of the line you are looking for
but wont it be easier to just copy the files. Quote
but wont it be easier to just copy the files.

If you just want one line out of each file, why clutter up your disk space uselessly copying hundreds or thousands of files? When you still have to look through them to find the lines that you want?

Quote from: dec27 on March 18, 2008, 10:55:09 AM
I need to pull info from a large number of textfiles in a directory and aggregate this to another textfile. The info needed is two lines (line 1 and line 9) in the textfile, and these lines are consistently lines 9 and 16 across all the textfiles.

I need this info from all the files. The textfiles however are unique to that folder structure e.g
1st textfile = U:\abailey\NetLogon.txt
2nd textfile = U:\ablay\NetLogon.txt
3rd textfile = U:\abreen\NetLogon.txt etc...

Can you please help me with this one, or even let me know if its possible to do, because I really want to get this now at this stage :-) Thanks!
if you can  download and use gawk from here:

Code: [Select]#save the below script as script.awk
# assumes you only want to get line 1 and 5
{
  i=1
  while( ( getline line < $0 ) > 0 ) {   
    if (i==1 || i==5) print line > "newfile"
    i+=1
  }
}

output:
Code: [Select]C:\test>dir /B  /S NetLogon.txt | gawk -f script.awk
1544.

Solve : Block the port?

Answer»

Hi all,I was wonder , How I can block the computer port?
I WANT to block port 80 .


Is there any command for accessing the port .

Thank you for your effort of reading .You need a firewall to block ports.
There is no "dos command" that can do it if that is what you're looking for.

What version of Windows do you have installed and why do you want to block port 80?
And more importantly do you want to block access to port 80 on your computer or do you want to block your computer from accessing port 80 on other computers?
The difference being, blocking access to port 80 on other computers will prevent the computer from browsing most web pages while blocking port 80 on your computer will block access to any web server software you might have installed.Oh ,thank you for your replay .

Both is very useful .
But i need to block computer from access the port .what mean that i cant see web pages . And of course how to remove that .

Thank you for your life time .Like I said if you want to block a port you need a firewall.
If you're using Windows XP or Vista you already got one built in.
If not you will need to INSTALL one.I have Windows XP. Quote from: kv79 on March 24, 2008, 04:48:19 AM

Hi all,I was wonder , How I can block the computer port?
I want to block port 80 .

you know that port 80 is the port that you get your internet connection thourgh which is probably your ETHERNET port.I i know .I'm STILL no clear on why you want to block outbound access to port 80... but to each his own.

Actually on closer inspection you can't use the Windows Firewall to block port 80 because it offers no outbound protection.
You will need to install a firewall then.
Comodo is my personal choice.
http://www.personalfirewall.comodo.com/download_firewall.html

You should know though that simply blocking port 80 will is not an effective way to block access to web sites. Not all websites use port 80 and someone could still bypass the block by using a proxy on ANOTHER port. You can make the block more effective by blocking port 443 (HTTPS) and port 8080 (alternate http port) but the above still apply.

I think what he wants is to know how to unblock the port because he can't get on the web. He may think that the port is already blocked and he is trying to unblock it.

that makes since since some firewalls have a "Lock Internet Access" Feature on them, but if he's using the Win XP built-in firewall then he'll have to adjust the settings on it to Unlock his internet access.Thanks dude ,i will try it as soon I install it .I use a program called Internet Lock to block my ports.

However, it costs money.

You can search on google "Block Internet Freeware" or something for free programs which can block and unblock (password protect) your internet access. THere are many results.

Of course, make sure you download licensed freewares. Cracked Software is not encouraged.
1545.

Solve : Removing a directory(Folder) if it exists?

Answer»

Hello again, I am trying to remove a folder if it exists and I am getting an error.

The reason I am doing this is beause a user can clean up the folders outside of the application and I don't WANT to know if they have already.

What I have so far is this:

if exists %WORKDIR%\KEN\j1080 rmdir %WORKDIR%\KEN\j1080 /q

Where %WORKDIR% is already defined and tested
Where j1080 is the ACTUAL folder I want to delete and anything below that.

I keep getting the following message:
c:\progra~1\encore\temp\System\KEN\j1080 was unexpected at this time.

Ken
if EXIST %WORKDIR%\KEN\j1080 (rmdir %WORKDIR%\KEN\j1080 /q)

how does this work?
(no S at the end of exist and the do-if-true expression in parenthesis)Better, but got this message..

The directory is not empty.try the /s flag as well
/s   : Removes the specified directory and all subdirectories INCLUDING any FILES.

Code: [Select]if exist %WORKDIR%\KEN\j1080 (rmdir %WORKDIR%\KEN\j1080 /s /q)that worked, thanks

1546.

Solve : Reading the output file from Command Prompt window?

Answer»

RE: Using Dec-C++ COMPILER on Windows XP

I need help with configuring or setting up the OUTPUT directory so as I can READ the output file after compiling a program.

What happens is that after successfully compiling a project the output window does appear BRIEFLY but dissappears so I can't therefore see the results of the project I am busy with

How do I make the output window stay without dissappearing?

Thank you
in DOS its pause or pause >NUL but if you want to pause in C++ i think its getchar(); or sth

1547.

Solve : How to check a file status (open or closed) from batch command?

Answer»

I need to check for a file (.dat or .TXT) status and introduce delay if it is open. How to check file status (open or closed) from batch command.

THANKS for your help.Check out Microsofts SYSINTERNALS site for command line utilities to do this :
technet.microsoft.com/en-us/sysinternals/default.aspx

GrahamStill no luck.... PLEASE let me know if any other choice... Thanks

1548.

Solve : Advance For Loop?

Answer»

I am WORKING on a script to copy files to remote systems.  I am stuck where I check a text file to see if this system has had the folder copied or not.  If it has, then I need to skip the IF statements and just advance the loop to check for the next system....I have put in italics the portion I am having problems with...

echo off
for /f "tokens=*" %%i in (\\dclib3\tech\maintscript\copyscript\systems.txt) do (
        
      
      FINDSTR /C:%%i \\dclib3\tech\maintscript\copyscript\log\copyscript.txt
                IF %errorlevel%==0 then advance the loop to check for new system      
      echo %%i>>\\dclib3\tech\maintscript\copyscript\log\copyscript.txt

      IF EXIST \\%%i\C$\windows\nul (
      echo d|xcopy \\dclib3\tech\maintscript\MaintXP \\%%i\C$\ /Y /S /E
                echo Y|CACLS "\\%%i\C$\maintscript" /P everyone:F )

      IF EXIST \\%%i\C$\winnt\nul (
      echo d|xcopy \\dclib3\tech\maintscript\MaintXP \\%%i\C$\ /Y /S /E
      echo Y|CACLS "\\%%i\C$\maintscript" /P everyone:F )
                  
      )

Errorlevel cannot be checked as a numeric and the implied comparison is equal or greater than.

Code: [Select]echo off
for /f "tokens=*" %%i in (\\dclib3\tech\maintscript\copyscript\systems.txt) do (
     FINDSTR /C:%%i \\dclib3\tech\maintscript\copyscript\log\copyscript.txt
     IF errorlevel 1 (      
        echo %%i>>\\dclib3\tech\maintscript\copyscript\log\copyscript.txt
 
        IF EXIST \\%%i\C$\windows\nul (
          echo d|xcopy \\dclib3\tech\maintscript\MaintXP \\%%i\C$\ /Y /S /E
          echo Y|CACLS "\\%%i\C$\maintscript" /P everyone:F )
 
        IF EXIST \\%%i\C$\winnt\nul (
          echo d|xcopy \\dclib3\tech\maintscript\MaintXP \\%%i\C$\ /Y /S /E
          echo Y|CACLS "\\%%i\C$\maintscript" /P everyone:F )
        )        
     )

The theory here is that if errorlevel is 1 or greater (not found from the FINDSTR) then all your logic gets executed. If errorlevel is zero (found in the FINDSTR) then all your logic is skipped and the loop gets executed again with a new variable value. I tested this for syntax; I'll leave it to you for the logic portion.


PS. Generally I don't encourage the use of administrative shares (C$) due to  potential security issues. But hey, that's just me.What about more complex logic?

ASSUME that MyFile.txt is a list formatted as follows:
SourceDrive:\SourcePath SourceFileName TargetDrive:\TargetPath

Example:
C:\Temp File1.txt C:\Target1
C:\Foo File2.txt C:\Target2
etc.

Let's say I want to validate each element, and skip to the next iteration of the loop if any of that validation fails.

Code: [Select]ECHO OFF
FOR /F "tokens=1-3" %%a IN (MyFile.txt) DO (

    SET SourceDir=%%a
    SET SourceFile=%%b
    SET TargetDir=%%c

:ValidateSourceDir
    IF NOT EXIST !SourceDir! (
        ECHO Invalid Source Directory !SourceDir!
        REM Loop to the next iteration
    ) ELSE (
      ECHO Source Directory !SourceDir! Validated
    )

:ValidateSourceFile
    IF NOT EXIST !SourceDir!\!SourceFile! (
        ECHO Invalid Source File !SourceDir!\!SourceFile!
        REM Loop to the next iteration
    ) ELSE (
      ECHO Source File !SourceDir!\!SourceFile! Validated
    )

:ValidateTargetDir
    IF NOT EXIST !TargetDir! (
        ECHO Invalid Target Directory !TargetDir!
        REM Loop to the next iteration
    ) ELSE (
      ECHO Target Directory !TargetDir! Validated
    )

:NowDoSomeOtherStuff
    XCOPY !SourceDir!\!SourceFile! !TargetDir!

)

The :Labels are there simply for readability.  Constructing this with nested, all-or-nothing execution is ugly, and a pain, especially as additional logic is needed.

The following looks like it should do the trick, but it fails with, "The syntax of the command is incorrect.":

Code: [Select]ECHO OFF
FOR /F "tokens=1-3" %%a IN (MyFile.txt) DO (

    SET SourceDir=%%a
    SET SourceFile=%%b
    SET TargetDir=%%c

:ValidateSourceDir
    IF NOT EXIST !SourceDir! (
        ECHO Invalid Source Directory !SourceDir!
        REM Loop to the next iteration
        GOTO NextLoop

    ) ELSE (
      ECHO Source Directory !SourceDir! Validated
    )

:ValidateSourceFile
    IF NOT EXIST !SourceDir!\!SourceFile! (
        ECHO Invalid Source File !SourceDir!\!SourceFile!
        REM Loop to the next iteration
        GOTO NextLoop
    ) ELSE (
      ECHO Source File !SourceDir!\!SourceFile! Validated
    )

:ValidateTargetDir
    IF NOT EXIST !TargetDir! (
        ECHO Invalid Target Directory !TargetDir!
        REM Loop to the next iteration
        GOTO NextLoop
    ) ELSE (
      ECHO Target Directory !TargetDir! Validated
    )

:NowDoSomeOtherStuff
    XCOPY !SourceDir!\!SourceFile! !TargetDir!

:NextLoop

)

I do not get the "incorrect syntax" error if I add some place-holder statement after the :NextLoop tag, like this...
Code: [Select]:NextLoop
ECHO. > NUL

...BUT, if any iteration fails -- for example, with "Invalid Source File C:\Temp\NoSuchFile.txt," the loop terminates.

How can I loop to the next iteration of a FOR loop?

btw, I have been a fan of this site for a long time, and this is my first post!  SORRY about resurrecting an old post, but that serves two purposes: It shows that I've searched for a solution first, and it best illustrates the problem.  Thank you for your (past and future) assistance!  I hope I can contribute.

EDIT: I know, I can validate path and file name in one step, with "IF EXIST !SourceDir!\!SourceFile!," but I wanted to illustrate a multi-stage validation process.
I suspect that the goto instructions are preempting the return address of the for loop. By fixing the syntax error, I created my own until I moved the :NextLoop outside the for loop which of course changed the entire logic of your file.

Going back to my KISS roots, I give you this for your consideration:

Code: [Select]ECHO OFF
FOR /F "tokens=1-3" %%a IN (MyFile.txt) DO (
SET SourceDir=%%a
    SET SourceFile=%%b
    SET TargetDir=%%c
    set valid=Y

:ValidateSourceDir
    IF NOT EXIST !SourceDir! (
        ECHO Invalid Source Directory !SourceDir!
        set valid=N
)
:ValidateSourceFile   
    IF NOT EXIST !SourceDir!\!SourceFile! (
        ECHO Invalid Source File !SourceDir!\!SourceFile!
        set valid=N
)
:ValidateTargetDir
    IF NOT EXIST !TargetDir! (
        ECHO Invalid Target Directory !TargetDir!
        set valid=N
    )
   
if valid==Y XCOPY !SourceDir!\!SourceFile! !TargetDir!
)   

Your processor is probably fast enough not to notice the extra microseconds needed to process all the CONDITIONS before deciding to run XCOPY


 KISS indeed.  MUCH appreciated!

1549.

Solve : Accented character de batch files?

Answer»

I'm using a Windows XP SP2
The Regional and Language Options are set for Portuguese (Brazil)
MANY folders and file names are written in Portuguese.
When using the Command Prompt I type in Portuguese and command works fine.

But when processing the same command through a batch file the characters are changed (not ACCEPTED) and it does not work!
Is the any solution similar as quotation marks (") for special characters?
what code page are you using (type chcp at the prompt to find out)
ACTIVE Code Page: 850Code page 850 is standard US English. Perhaps if you change the code page to 1252 Portuguese (Portugal / Brazil)...

type this at the prompt

chcp 1252



The Code page 1252 works when the the folder or file's name is not between QUOTES, used for special characters like space.

Any other suggestion?

1550.

Solve : Strike Commander in DOS?

Answer»

hi

I have my strike commander game from ages back which i thought ill give another try being such a wonderful game. but nowadays DOS just acts up and needs more and more memory to run the game.

Problem is my MS-DOS version is [5.1.2600] and when i press MEM /c i get the following results:

1048576 -- total contiguous extended memory
0 bytes available contiguous extended memory
941056 bytes available XMS memory
MS-DOS resident in High Memory Area

and when i try to run the game from DOS, it says expanded/extended memory on this computer is insufficient to continue the installation process. 1953k is needed.

And then I tried DOSBOX as well. There the message I GOT was "not enough DOS emory detected. 586k are needed to play Strike Commander. Only 425k was found"

Can someone please help me run this game ? ! ?

Thanks
I don't know if this will help but you could try a few of these settings...

http://www.microsoft.com/windowsxp/using/helpandsupport/learnmore/appcompat.mspx

tried that. didn't work.what Operating system you have?windows xp pro service pack 2Can you try to open like this .


right click on your exe file of the game .

and chose tab compatibility


and run it in win 95 mode . no that's a very common way of opening old files...i tried that also

however, u must realise that i am not trying to open the game from windows...this is a DOS game and i am gonna have to try opening it from either MS-DOS [5.1.2600] or DOSBOX 0.72

besides I dont even know where I can DOWNLOAD MS-DOS 6.0 from ? I downloaded 6.22 but that's only an upgrade and isnt of much help.Did you try to USE a boot disk from some kind of windows  and then from that start up you game . ?sadly i do not have a floppy drive ...are u referring to to a windows xp boot cd...but that WOULD take me right into the installation process and not DOS right ?  How exactly do you have DOS installed on this machine ? ?resident DOS [5.1.2600]

by using the "Run" > "cmd"  command