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.

2851.

Solve : So im making a game...?

Answer»

Quote

it won't always be positive either.

Because there was an ERROR. Which is what you're testing for.0 means no error. any other values generally means an error. which means that (2000/XP/Vista) programs returning a negative number will be flagged as successful, since they are not greater then zero. so basically, the condition should be:

Code: [Select]if not errorlevel EQU 0 goto :fail

You mean if not .The original code I gave (if errorlevel 1 goto fail) is backwards compatible to old versions of DOS and works over 99% of the time in my experience. But the discussion is correct that it won't work with CMD and programs that return negative errorlevels. But just to correct a few things:
1) CHECKING for errorlevel 1 is fine, because that will return true if the errorlevel is 1 or 2 or 3 or 4, etc. (anything HIGHER than 0).
2) The "correct" way with CMD needs to address ERRORLEVEL as an environment variable, so it needs % around it, like:
Code: [Select]IF %ERRORLEVEL% NEQ 0 goto failQuote from: GURUGARY on February 14, 2009, 09:24:49 PM
The original code I gave (if errorlevel 1 goto fail) is backwards compatible to old versions of DOS and works over 99% of the time in my experience.

exactly. == with ERRORLEVEL will be execute the command if the value is greater then or equal to the value- additionally the GTR then and so forth are not available in pure DOS which kind of precludes their USE in that context.


your correction re Errorlevel as a variable is also 100% accurate as well. Quote from: GuruGary on February 14, 2009, 09:24:49 PM
Code: [Select]IF %ERRORLEVEL% NEQ 0 goto fail

So this is the best way to do it, rite?
thanks again.Yes. Do it that way.
2852.

Solve : Batch File for changing text?

Answer»

I NEED to create a batch FILE that will change the time in numerous text files. The time needs to be changed to 10:00. However, all the original times are DIFFERENT in the text files. Here's an example:

change events.txt "11:00 SETSUBMENUITEM 100 22 1651 0" "10:00 SETSUBMENUITEM 100 22 1650 0"

Instead of entering 11:00, I need to enter something that will cover all times. I know the date can be entered as %yy%%mm%%dd% but I'm not sure about the time.

2853.

Solve : outlook 2007 connecting to exchange problem?

Answer»

Hi Guys, Please could you help out with an outlook problem I am having.

Running Outlook 2007 on an XP Pro laptop. connecting to Exchange server via LAN. The account has been set up with cache exchange mode enabled. I have however disabled the shared FOLDERS option in the cache settings.

The problem is that at the bottom right hand side exchange is showing as "not Connected". I have checked and it is not set to "work OFFLINE"

Please could anyone with ideas or advise please help.

ThanksI don't think this is the right forum for this question ... but:
Assuming the LAN the laptop is on is the same LAN and subnet the server is on, VERIFY the server name, username and PASSWORD for the account settings (when you click "CHECK name" it should underline the information and not give any errors) . Also verify there are no firewall settings on either end that would prevent communication. If it still doesn't work, check the Application event logs.

2854.

Solve : Menu?

Answer»

and Larssie, BATKIT only makes the kind of menus like in that colortone example.

but to be honest you cant make those high-end menus like in Edit, like BFC said.
but he wants to make it in CMD(or DOS).

so yea Larssie, sorry but making menus like Edit for a Batch program are just not possible.Making menus with VB in the console WINDOW would be a major PITA, but it's easy as pie to add a menu to a form.

Batch's only real screen output is "echo" when in order to create a menu of that sort you need routines and so forth to access the character/color attribute matrix in video memory.*smacks forhead*

i forgot about this batch power tool: http://ecost.drn.digitalriver.com/product.php%5Bid%5D40560%5Bcid%5D20%5BSiteID%5Dsimtel.net

bat menu works like a up and down menu controlled by keyboard.
and returns which option was selected with ERRORLEVEL

[attachment deleted by admin]

2855.

Solve : freaking dos!!!!!!!!!!!!!?

Answer»

if your refering to me now. The NET was down for a while and I dont have it setup at my new LOCATION. Yes that is correct but I tried to change directories my FATHER says I had to run f-disk since there was an os but I figure it WOULD dual boot then or something. I dont know patio thanks for the insight that may help. I have books that are useing older versions that PROBABLY why.

2856.

Solve : Need help for my Autoexec.bat file for a HDD boot partition?

Answer»

I have a 128 Mb pen drive that natively boots MS-DOS 7.10 (from a Windows 98 disk).
Quote

I have a 128 Mb pen drive that natively boots MS-DOS 7.10 (from a Windows 98 disk).

Hey, that may be what he needs.
And other curious minds would like to know.
How do you get MS-DOS 7 onto a USB thing and have it boot.Quote from: Geek-9pm on February 14, 2009, 03:00:28 PM
Quote
I have a 128 Mb pen drive that natively boots MS-DOS 7.10 (from a Windows 98 disk).

Hey, that may be what he needs.
And other curious minds would like to know.
How do you get MS-DOS 7 onto a USB thing and have it boot.

I USED the HP USB Boot Utility. It's all here

http://www.bootdisk.com/pendrive.htm

Let's hope his NetBook supports booting from USB devices.
So far it doesn't sound like it.I am pretty sure it supports booting to USB devices.Quote from: GURUGARY on February 15, 2009, 09:04:50 AM
I am pretty sure it supports booting to USB devices.

Source ? ?Quote from: patio on February 15, 2009, 03:48:33 PM
Source ? ?
Experience. It has been at least 2 years since I have seen a new laptop that does not support booting to USB devices.

But here is a link that further supports my guess: http://www.ubuntumini.com/2008/10/installing-ubuntu-on-dell-inspiron-mini.html
It includes a video of the BIOS screen changing the boot options, but here text of "Step 2":
Quote
Step 2. Set your Mini 9 to boot from optical drive or USB

At the Dell splash screen (the Dell logo that appears when you turn your Mini on) press 2.
This will take you into the Mini's BIOS, from there go to the BOOT tab.
Use F6 and F7 (Fn H and J respectively on the mini) to move your intended boot device up and down the list.
The optical media drive or USB drive should be a the top of this list.
Got it.

Wonder why this is such a struggle then...Quote from: patio on February 16, 2009, 07:16:11 AM
Got it.

Wonder why this is such a struggle then...

probably trying to use DOS 6?Should still be a piece of cake...
Use Dias' guide to create a bootable flash drive...boot to the flash and RUN the OS install.
2857.

Solve : Help me with a batch file?

Answer»

Quote from: BC_Programmer on February 16, 2009, 09:08:41 AM

If he's examining windows versions, there is a chance he wants the batch to run on windows 98, in which case SET /P is not available.

You right! In other word : I'm attempting to make my batch the more compatible possible If you are making your script backwards compatible with Win9x, then be sure to modify your IPCONFIG commands because the Win9x version of IPCONFIG is very different from the Windows 2000 / Windows XP version of IPCONFIG
Code: [Select]C:\Win98>ipconfig /?
Windows 98 IP Configuration
Command line OPTIONS:
/All - Display DETAILED information.
/Batch [file] - Write to file or ./WINIPCFG.OUT
/renew_all - Renew all adapters.
/release_all - Release all adapters.
/renew N - Renew adapter N.
/release N - Release adapter N.
Code: [Select]C:\WindowsXP>ipconfig /?
USAGE:
ipconfig [/? | /all | /renew [adapter] | /release [adapter] |
/flushdns | /displaydns | /registerdns |
/showclassid adapter |
/setclassid adapter [classid] ]

where
adapter Connection NAME
(wildcard characters * and ? allowed, see examples)

Options:
/? Display this help message
/all Display full configuration information.
/release Release the IP address for the specified adapter.
/renew Renew the IP address for the specified adapter.
/flushdns Purges the DNS Resolver cache.
/registerdns Refreshes all DHCP leases and re-registers DNS names
/displaydns Display the contents of the DNS Resolver Cache.
/showclassid Displays all the dhcp class IDs allowed for adapter.
/setclassid Modifies the dhcp class id.

The default is to display only the IP address, subnet MASK and
default GATEWAY for each adapter bound to TCP/IP.

For Release and Renew, if no adapter name is specified, then the IP address
leases for all adapters bound to TCP/IP will be released or renewed.

For Setclassid, if no ClassId is specified, then the ClassId is removed.

Examples:
> ipconfig ... Show information.
> ipconfig /all ... Show detailed information
> ipconfig /renew ... renew all adapters
> ipconfig /renew EL* ... renew any connection that has its
name starting with EL
> ipconfig /release *Con* ... release all matching connections,
eg. "Local Area Connection 1" or
"Local Area Connection 2"Thx for the notice GuruGary I will make some modification to my script.
2858.

Solve : Can Virtual PC 2007 run MS-DOS??

Answer»

Can Virtual PC 2007 run MS-DOS?

This is something many want to know. The MS web site does not give a direct answer to the question.

Can I use it to play old DOS games?
Before I try it I would like to know what other people have done with it.
You can install MS-DOS as a guest OS using Virtual PC 2007. "Although Virtual PC 2007 doesn't officially support MS-DOS, it will work.", it says here... (Also tells how to free up DOS MEMORY for games)

http://www.maximumpc.com/article/back_to_the_future_with_virtual_pc_2007


heh, when I want to play DOS games, I just whip out my old TRUSTY thinkpad. Well, I don't actually have to take it out from anywhere, when not in use it makes a great end table.Quote

when not in use it makes a great end table

BC, how tall are you? ok, a short end table. and it only WORKS when I'm lying down.


better then putting DRINKS on the floor though, I suppose.Quote from: Dias de verano on February 14, 2009, 02:02:57 AM
You can install MS-DOS as a guest OS using Virtual PC 2007. "Although Virtual PC 2007 doesn't officially support MS-DOS, it will work.", it says here... (Also tells how to free up DOS memory for games)

http://www.maximumpc.com/article/back_to_the_future_with_virtual_pc_2007



Quote from: zuhiab on February 16, 2009, 02:43:38 AM
Quote from: Dias de verano on February 14, 2009, 02:02:57 AM
You can install MS-DOS as a guest OS using Virtual PC 2007. "Although Virtual PC 2007 doesn't officially support MS-DOS, it will work.", it says here... (Also tells how to free up DOS memory for games)

http://www.maximumpc.com/article/back_to_the_future_with_virtual_pc_2007



Why the little quote fest ? ?If you just want to run dos game, try dosbox Is the easies way to play you old game. But I manage to run dos 7 on a vmware with windows 3.1 . So i guess is possible to run dos or ms-dos in virtual pc.Quote from: patio on February 16, 2009, 07:11:27 AM
Why the little quote fest ? ?
He started it. Tanks. iIam trying to install virtual PC on my new dell Optipex. SFF
(New to me anyway)
I am NOT get the thing to work. Or if it is working, I don't know what it is doing.
I do not know what it wants. It seems to be asking me yo use my existing OS. If I did that, what is the point? I am missing something.

I am getting virtual headache. I need some vertical Gin.

On this particular machine there is no easy way to connect a second hard drive. So I grues I will have to try the Virtual PC on a machine that has more options.You shouldn't need a second hard drive for Virtual PC. Once Virtual PC is installed, CREATE a new Virtual Machine with a Virtual Hard Drive, and then start it. Use either the "CD" or "Floppy" (menu at the top) to capture the device (or use virtual image like an ISO or IMG) to install the OS.
2859.

Solve : Search and Copy a particular File?

Answer»

Hi all,

I have two folders A & B. I want to SEARCH for a PARTICULAR file from Folder A in Folder B, if is present, copy that file from Folder B to Folder C. If it is not Present copy that file from Folder A to Folder D.

Please help me in searching for the files...
I...SMELL something fishy. What would be the use of that, can't you just right click > make new folder?FOUR folders:

A

B

C

D

if a file from folder A exists in B, copy it from folder B to C. otherwise copy it from folder A to D.


Sounds to me like you want the end result to be:

Folder C: Contains all files from B that don't exist in A.
Folder D: Contain All files in A that also exist in B.


I see nothing fishy about this myself. As such:


Code: [Select]set A="C:\FolderA"
set B="C:\FolderB"
set C="C:\FolderC"
set D="C:\FolderD"

for %%P in (%A%\*.*) do if exist %B%\%%P copy %%P %C%
for %%P in (%A%\*.*) do if not exist %B%\%%P copy %A% %D%




It could be made much better, by one of the other more NT command proficient members, but it should do what you need. Just remember to change the folder names at the top of the code to the APPROPRIATE paths.

2860.

Solve : Quick question: How to make .bat files write txts with seperated lines??

Answer»

Hello. For example, I have this code:

Code: [Select]echo Some bump variable is: %somedumpvariable% >somedumptextfile.txt
But how do I have it write seperate lines? Like:

Some bump variable is:
%somedumpvariable%

or something like that.

Note: I need it to work on Windows XP SP3.To write SEPARATE lines you would have to do:

Code: [Select]echo Some bump variable is: > somedumptextfile.txt
echo %somedumpvariable% >> somedumptextfile.txt



When you have >> it adds information to an existing file where as
> creates a new file. But I think you already knew that. THANK you, that worked fine Quote from: BatchFileCommand on February 17, 2009, 06:20:37 AM

To write separate lines you would have to do:

Code: [Select]echo Some bump variable is: > somedumptextfile.txt
echo %somedumpvariable% >> somedumptextfile.txt



When you have >> it adds information to an existing file where as
> creates a new file. But I think you already knew that.

I disagree, >> can make files too. But, that's right.Quote from: BatchRocks on February 17, 2009, 08:59:45 AM
Quote from: BatchFileCommand on February 17, 2009, 06:20:37 AM
To write separate lines you would have to do:

Code: [Select]echo Some bump variable is: > somedumptextfile.txt
echo %somedumpvariable% >> somedumptextfile.txt



When you have >> it adds information to an existing file where as
> creates a new file. But I think you already knew that.

I disagree, >> can make files too. But, that's right.

Actually, BFC is correct. > will ALWAYS create a new file- if a file with that NAME EXISTS it is truncated to 0 bytes. >> will always append to the file if it exists, creating a new one of necessary.Sorry, apologies.on the other hand as you say >> will create a file as necessary. But in this CASE that file might balloon to huge sizes, depending of course on how often this batch is run.
2861.

Solve : Calling a batch file from another batch file?

Answer»

devcom, I have tried the new codes but not thing happen when it reach the set TIME. I am not sure what is preventing the batch files from running. My PLAN B is to stop the driver, because the original problem was the application will not run after I start it the second time. It show me the error message "driver already in use". So maybe if there is a way for me to stop the driver then hopefully I can start the application again without having to restart the laptop. Is there a way to do this?
If not already, as the last executable statement of each of your 3 called batch files Copy.bat, RenameFileToDate.bat and reboot.bat enter the command "exit".

Myself I would also ALLOW more time between the execution of each of the individual 3 batch files.
Maybe as a test you would care to say use 3 minutes or more before executing each batch file.

I have given your problem a little more thought.
Should you execute the following commands you will discover that the time is diplayed as Hours:Minutes:Seconds .

set cTime=%time:~0,-3%
echo '%cTime%'
pause

Your if statements are only testing for the Hours:Minutes.
Therefore your “If” statements contained WITHIN your MS-DOS batch file may not work.
I have also looked at your boolgeon statements and amended them as follows;

echo on
break on
set cTime=%time:~0,-3%
echo '%cTime%'
if '%cTime%' gtr '10:08:00' goto End
if '%cTime%' leq '10:06:00' call Copy.bat
if '%cTime%' leq '10:07:00' call \Hard FAULT Captures\RenameFileToDate.bat
if '%cTime%' leq '10:08:00' call C:\WINDOWS\reboot.bat
:End
@echo.
pause
exit

2862.

Solve : What's the point of remarks??

Answer»

ASM is source code, machine code very very complex yet very very powerful its not an exeacuteable like EXE.
I need a batch to asm converter. (make it free if possible). I want to be able to send it to my friends so they can edit some of the code too ( yeah I use remarks ).BFC,

Batch and ASM are completely different and there isnt any converter for this kinda stuff. read about ASM here
That would be cool if there was one. But yeah, it's complicated. But there are even more complicated.Quote from: BatchFileCommand on January 19, 2009, 08:47:56 AM

Code: [Select]The REALLY good ones turn it into asm

Is that even more complicated then EXE ?!?

To you it would be, yes.
Actually, I looked it up more. Pretty comparable . Dias, you won't be able to go everywhere being the
"wise guy" you claim everybody else to be.When there is a great need, somebody will do it. If a compile of a batch file is really needed, it will be done. Somehow. But it is seldom done. Here is why.

In very complex operations the higher level of code is in a form the people can modify and use right away. The Edit, Compile, Link, Debug, Verify, Deploy and Revise business can take too long in a real-time process where a revision in the logic, settings or performance has to bee done quickly.

IT administrators often use batch files, because batch files are quicker in the over-all process. It is not so much have many milliseconds it takes the batch to run. It is the time it takes to get it up and running from the point where a new task is needed until the user has in on her computer.Quote from: BatchFileCommand on January 19, 2009, 12:24:48 PM
Actually, I looked it up more. Pretty comparable . Dias, you won't be able to go everywhere being the
"wise guy" you claim everybody else to be.

BFC,

your getting a bit to big for your britches; he's been here longer so he's more experienced than you.Everybody has a "batch to ASM converter". Here's a picture of one

I believe there was a Batch to ASM conversion program at some point- but it only worked with Pure DOS (no NT commands).


Quote from: BatchFileCommand on January 19, 2009, 12:24:48 PM
Actually, I looked it up more. Pretty comparable .

what? an straight machine code executable comparable to ASSEMBLY? I suppose somebody could say that... until they realize that it's a bit more difficult to memorize and interpret the meaning of a set of hexadecimal bytes then it is to read a assembly display of those same set of bytes.



Quote from: Dias de verano on January 19, 2009, 03:31:46 PM
Everybody has a "batch to ASM converter". Here's a picture of one

<image>

Except some people are missing the ASM module completely.Wait a minute, you people are doing all the work for me. You say that it's harder to convert batch to asm ( a much easier language then exe) But then you say that it's easier to convert batch to exe. There's no logic in that. When you say "experience", there are two and more meanings.
1. you're a smart-*censored* who knows everything
2. you're a real helpful person who knows everybody.
3. you're a lazy "thing" that has been in the forum for years and posts stuff like, cool, and i like that.Quote from: BatchFileCommand on January 19, 2009, 07:38:45 PM
Wait a minute, you people are doing all the work for me. You say that it's harder to convert batch to asm ( a much easier language then exe) But then you say that it's easier to convert batch to exe. There's no logic in that. When you say "experience", there are two and more meanings.
1. you're a smart-*censored* who knows everything
2. you're a real helpful person who knows everybody.
3. you're a lazy "thing" that has been in the forum for years and posts stuff like, cool, and i like that.

you obviously don't understand jack-*censored* about what we're saying.

It's easier to convert to EXE because one could create a Stub executable in C or C++ for example that loads batch code that is appended to the executable. the C program, upon being run, loads the batch code from the end of itself (argv[0], of course), saves it in a temporary file, shells the batch file, deletes the temporary file, and closes.

EXE is machine code. it translates DIRECTLY into assembly. That's why it's called "dissasembly" not "decompiling" to ASM source. The comments are gone, which are kind of important to understanding anything that is happening in a ASM program. Which ironically answers your topics question.

conversely- you don't "Compile" an ASM program but rather "assemble" it, which is a fairly simple task at a basic level- strip out comments and right out each ASM instruction as the directly CORRESPONDING piece of machine code. ASM is just a symbolic way of looking at the machine code.

This is why, with most "batch compiling" systems (which, as stated before simply prepend some cheap C program to the front of the batch code and call it a day) you can simply open the executable and copy the code- comments and all. More "sophisiticated" batch compiling programs try to further obfuscate the code by performing EXE compression on the resulting executable, appended batch code and all. Of course, this prepends ANOTHER executable to the front of the current one, meaning that the decompression routine needs to save a temporary file containing the original executable, which can be opened and the batch code once again copied out as if the compression algorithm wasn't there (and in fact it's quite transparent)Quote
you obviously don't understand
jack- about what we're saying.

It would be easier if you could make it clear what you are saying.

Source code translators are available. But they are not used by the average person because they represent a huge amount of research for a taks that a small number of system designers need. Like mega bucks of code that has to be ported onto another system. Some of the major programs we have today stated out as translations of programs written for other CPUs and systems. Then there were later re written in better quality code. If the original code was in C, the process did not need much in the way of an automatic translation. Bur if the program was written in PL/1 or FORTRAN or COBOL, it could be a major job porting it to another platform.
Munch of the early work on small personal computers had to be done in Assembler because good C compiles were no available at first. In fact, they were very bad. A early language from Intel was called PL/M and was used to speed up the process and put some structure into our code. And you have to pay big bucks to get a copy.
Noways you can get free development tools from Microsoft for your favorite language. (Sorry, no Pascal.) Visual stdio versions of BASIC, C, C++ and J++ plus a Web Builder.

But a visual ASM? Foo! That is hard to do. You hive to use MASM32, which is a real pain. look here:
http://www.masm32.com/
porting from one architecture to another is only VAGUELY RELATED to the idea of converting from one language to another,but they definitely fall into the same domain.

batch, obviously presents a trouble spot since all the various constructs and possible switches and so forth will need to be handled properly; and even so you gain nothing but code obfuscation anyway, since any language it translates too will need to shell to dos to perform the commands such as FIND and MORE and so forth.


Quote from: macdad- on January 19, 2009, 09:20:58 AM
ASM is source code, machine code very very complex yet very very powerful its not an exeacuteable like EXE.


close !

ASM is simply a symbolic form of machine code, and as such it would be foolish to voluntarily select machine code over ASM for programming- as it isn't any more powerful, and much harder to read or interpret; besides- in order to do anything with machine code, one must know (in a way) ASM.

As for the second part- not all Executables are machine code, but they almost always have some machine code to get started- for example, some Microsoft C compilers allow the source to be compiled to P-code. the program itself starts with machine code- and the only machine code present is the P-code interpreter. It was similar to the way Java does it, except the program contained the entire JVM for the platform.

thats true...
ASM would be the more "brushed up" version of Machine code yet ASM is not interchangable with all computers since all computers dont have the same proccessor. which makes it easier to program in higher lvl languages, such as VB and C, they are independent from the proccessor and ASM which makes them interchangeable.
2863.

Solve : Adding text to a file??

Answer»

Is there a code to add text to a file? Liiiike...

Code: [Select]@Echo off
:Loop
echo. |date |time |find "current" >> Cats.txt

then add a new line, like...

Code: [Select]@Echo off
:Loop
echo. |date |time |find "current" >> Cats.txt
echo. |date |time |find "current" >> Dogs.txt
?


And, Is there a way to make this search the whole computer for the file, not just the current..."Folder" or desktop?
Code: [Select]Copyright 2008 BatchRocks
@Echo off
Title Renaming!
:Main
set /p "DOC=[ Enter the file name ] :"
set /p "ext=[ Enter the extension (.xml, .doc, ect.) ] :"
echo.
set /p "ndoc=[ Enter new file name ] :"
set /p "NEXT=[ Enter new extension (Or keep old) ] :"
goto Y1
:Y1
cls
Title Renaming!
echo Is this what you want?
echo %doc%%ext% to %ndoc%%next%?
echo.
set /p "ans=[ Y / y or N / n] :"
if "%ans%"=="Y" goto Y
if "%ans%"=="y" goto Y
if "%ans%"=="N" goto N
if "%ans%"=="n" goto N
pause
:Y
cls
ren "%doc%""%ext%" "%ndoc%""%next%"
goto R
:R
cls
echo Want to redo?
set /p "ans1=[ Y / y or N / n] :"
if "%ans1%"=="Y" goto Main
if "%ans1%"=="y" goto Main
if "%ans1%"=="N" goto N
if "%ans1%"=="n" goto N
:N
cls
echo Have a good time!
pause>nul
exit
You can use it if you want .

BRQuote

@Echo off
:Loop
echo. |date |time |find "current" >> Cats.txt
echo. |date |time |find "current" >> Dogs.txt

What results are you expecting? Why are you piping the output of the date command into the time command? You might try doing one thing at a time.

Code: [Select]echo. | date | find "current" >> Cats.txt
echo. | time | find "current" >> Cats.txt

Quote
And, Is there a way to make this search the whole computer for the file, not just the current..."Folder" or desktop?

You computer specs list Win98/ME but I thought set /p was not available until WinNT or even Win2000. In any case I don't see any searching in your posted code.

Constructive criticism:

Code like this should be bulletproof:

Code: [Select]set /p "ans=[ Y / y or N / n] :"
if "%ans%"=="Y" goto Y
if "%ans%"=="y" goto Y
if "%ans%"=="N" goto N
if "%ans%"=="n" goto N
pause

Never assume the user will input one of the suggested options. If they fall into the pause, you might want to re-ask the prompt:

Code: [Select]:redo
set /p "ans=[ Y / y or N / n] :"
if "%ans%"=="Y" goto Y
if "%ans%"=="y" goto Y
if "%ans%"=="N" goto N
if "%ans%"=="n" goto N
goto redo

or you could try this to, both do the same, but this is smaller

Code: [Select]:redo
set /p "ans=[ Y / y or N / n] :"
if /I "%ans%"=="Y" goto Y
if /I "%ans%"=="N" goto N
goto redo
Quote
Copyright 2008 BatchRocks

seriously...??


maybe this would be better:

Code: [Select]@echo off
:R
cls
set /p OR=what would you like to rename?
if "%OR%"=="" exit
set /p nom=rename to what?
ren %OR% "%nom%"
if not %ERRORLEVEL%==0 pause && goto R
goto R
You don't have to seperate the extension from the file name, you can rename both at the same time. Also you can rename anything from wherever you are at the time, just input the path when inputting the file name. Also to escape from this just press enter when asked what you want to rename.

FBBR if you wanted it to be closed source then how about BAT2EXE?Quote from: macdad- on January 17, 2009, 06:44:36 AM
BR if you wanted it to be closed source then how about BAT2EXE?

If someone WANTS to see the source, then can get a decompiler(haven't found one yet). CONVERTING it to exe doesn't make it impregnable.thats true.
wonder about COM
EXE2COM since COM is basiclly abandon-extension and is not used as a program file anymore.Quote from: macdad- on January 17, 2009, 09:25:57 AM
thats true.
wonder about COM
EXE2COM since COM is basiclly abandon-extension and is not used as a program file anymore.

Is there EXE2COM, if you have one, please post a link to where I can get it.its pretty old but COULDNT find a good link for it.Ok...but even then, wouldn't someone with enough patience just REVERT it to bat again? Like the BAT2EXE/EXE2BAT things?you don't need a decompiler. somebody posted (quite annoyingly) a simple solution to somebody's problem once, but claimed it was "too complicated" and they "compiled" it. so I ran the program (which had a "pause" in the batch, luckily, and used process explorer. the actual program EXE had spawned a temporary process residing in my temp folder. I opened in notepad... ctrl+pagedown, and boom. the entire batch file sitting there; which I copied and pasted for the fellow who was requesting help.


the problem is, there is no "compiler" for batch- they are just obfuscators.



EXE2COM only works for programs compiled into the "tiny" memory model- not sure if any of the obfuscators do that. And... it doesn't work for win32 executables either.





2864.

Solve : Help to get position of @ character in a string....?

Answer»

Can anyone help me find the position of the @ CHARACTER in the following filename string

set [emailprotected] Title.mp4

I really need to get this working ASAP

CheersCode: [Select]set extract=%filename:1~30%
is that wat your after, please explain more
,Nick(macdad-)Quote

I really need to get this working ASAP

We don't generally guarantee same day service like a laundry, but I was out for a STROLL and stumbled upon this post.

Code: [Select]@ECHO off
set [emailprotected] Title.mp4
set POS=0

:start
call set chr=%%filename:~%pos%,1%%
set /a pos+=1
if %chr%[emailprotected] echo Position=%pos% & exit /b
goto start

We just answered a similar QUESTION. If you're in a hurry, it's better to search the forum.

2865.

Solve : Cartwheel or Blinking Text?

Answer»

Anyone know if there is an easy way to show either a cartwheel such as a stationary but transitioning ( / - \ | / - \ | ) in a DOS Shell Window or blinking text like <> in a batch file.

MANY... Years ago I USED GW-Basic and use the BLINK Color attribute to show blinking text and do the cartwheel with a print statement with Clear Screen to show say 10 flashes of / then 10 flashes of - then 10 flashes of \ then 10 of | and back around in a for loop. The process that it was EXECUTING was also WITHIN that for loop so it added to the time that it took to execute the process, but it worked. And since the process didnt take that long to execute anyways it wasnt painful to the user. This was however to add this bell and whistle sort of speak a way to lag down the program, but the end users loved seeing that cartwheel to know it was doing something at the sacrifice of having to wait longer to get the end result ( they didnt know that...ha ha )

Anyways in batch I was wondering if anyone found a neat way to make a cartwheel or blinking text within a loop so that another process the pure reason for the batch is able to execute and the cartwheel or blinking text is able to FUNCTION in harmony in the same batch.

I did make a way for this to happen in windows by a macro that triggered the batch the work to be done and then the visual effect batch which tested the state of the batch doing to work to TEST a file for a value of 1. If the value read in was still set to 1 in the token.txt file then the cartwheel started again until the value read in from token.txt was 0 changed by the batch getting to the end of its process and writing 0 to the token.txt file. And because this visual effect was triggered after the batch it was located on top of the true batch process window, to the user they were able to see that something was happening and the true process was underneith that DOS shell window.

Anyone know of a way to do it in native DOS or a single DOS Shell Window?I'd suggest ANSI commands, but they don't work with the NT shell.


you could, however, echo out a backspace character and write the next piece of the loop. I've gotten it working in some of my C programs.

Backspace is character code 8Quote from: BC_Programmer on January 16, 2009, 10:30:20 PM

I'd suggest ANSI commands, but they don't work with the NT shell.


you could, however, echo out a backspace character and write the next piece of the loop. I've gotten it working in some of my C programs.

Backspace is character code 8

You can do backspaces with gnuecho which comes in the GNU Core Utils For Windows.
Cool...thanks everyone for info
2866.

Solve : file extension mso , help?

Answer»

i asked this question before in a different form but to-night i think i have found something which may be the answer on an e-mail , so the question is

i get a few e-mails with pictures ( not personnal ones ) but the pictures do not open on the mail , so on one e- mail i got this ( editdata.mso (61b) )

i clicked it and went to windows live search and it came up with , file extension cannot open driver or file errors

i do not know which site to go to for a safe FIX , can you help with my prolem PLEASE
, harry

PS, sorry if i posted this in the wrong forumdo i NEED to up-date windows drivers or others if i do i would need help for that pleaseThis is DEFINATLY in the wrong forum.

If you go on google and search .mso drivers look for a LINK to microsoft.com, you might find something...Just checking, before you do ANYTHING with a file like that, make sure its from a trusted source...mso is an in-line E-mail attachment... there would be no reason to open it EXCEPT within the E-mail that it accompanies; and even so only with outlook. Since you can see the attachment, your not using outlook (which is a good thing, IMO) and thus you have no reason to open the file.

hi bc and helpmeh , i do not use outlook but this is the first e-mail i have seen with this attachment on it , do i need to update or download something so that i can open the photos in the e-mail or will i not be able to fix itDo you HAVE outlook? Because if you do, you will need to update it. (But this is still in the wrong thread ).i have never used outlook and for some reason i dont think i will i use yahoo .co.uk

i know its the wrong thread , but , i dont know how to move it or to wereMicrosoft > Microsoft Windows

Or possibly

Software > Internet Browsers

Go with Windows first, then if they say wrong forum there, go to internet.Software.

2867.

Solve : Use an Environment Variable inside another??

Answer»

Win XP Home.

Is it possible to use an environment variable inside ANOTHER environment variable? I'm trying to find the length of an environment variable (just experimenting) without success so far. I can do this by creating a file containing the env var then extracting the file (variable) length but is there another way using batch scripting?

So far my code attempt is:

Code: [Select]@echo off
setlocal enabledelayedexpansion
cls

set var=variable#
set pos=1
set max=1

:start
if "%var:~%pos%,1%"=="#" (
echo Varlen=%max% & exit /b
) ELSE (
set /a max +=1
)
set /a pos +=1
goto start

But this "%var:~%pos%,1%" doesn't seem to extract the value of %pos%, using pos itself. Tried escaping the % but that doesn't seem to work either.

ThanksYou don't need setlocal in this context and I streamlined some of the other code. I took it on faith that # was a delimiter and not part of the variable.

Code: [Select]@echo off
set var=variable#
set pos=0

:start
call set chr=%%var:~%pos%,1%%
if %chr%==# echo Varlen = %pos% & exit /b
set /a pos+=1
goto start

Good luck.

Thanks a bunch. My claim to fame can be that I got at least 4 lines correct

Now all I have to do is understand the Call COMMAND line you posted.

Seems I've got into a bad habit of always using setlocal allowdelayedexpansion in every batch script

Thanks again..Quote from: Sidewinder on January 16, 2009, 06:49:01 PM

I took it on faith that # was a delimiter and not part of the variable.

... you kind of have to do that, don't you? So you can't measure the length of a string that contains the delimiter character.

Set a counter to 0. Starting at the first character, create a substring which is composed of the CHARACTERS from the counter position to either the end of the string or 8192 characters along, whichever is the lower. (8192 is the max string length in XP or later cmd. Win2K & NT4 is 2047). Add 1 to the counter. Repeat until the substring is the empty string ("") which MEANS you have run out of characters, i.e. you have reached the end of the string. The counter value is the string length.

You have to use call to set the substring because you need to do the variable substitution in a child process.

Although this method does not use an added delimiter character which must be absent from the supplied string, it will still break if the supplied string contains control characters especially &, but then so will the previous code. That's a fact of batch life.

Code: [Select]@echo off
set string=Seems I've got into a bad habit
set stringlen=0
:loop
call set sstring=%%string:~%stringlen%,8192%%
if "%sstring%"=="" goto done
set /a stringlen+=1
goto loop
:done
echo string length=%stringlen%
Thanks for that Dias - nice explanation - more for me to puzzle over wow. getting the length of a string is a troublesome task in batch.Quote from: BC_Programmer on January 17, 2009, 02:45:11 AM
wow. getting the length of a string is a troublesome task in batch.

When you start hitting such problems in batch, often it's a sign that you need to be using another language.Quote from: Dias de verano on January 17, 2009, 04:39:15 AM
Quote from: BC_Programmer on January 17, 2009, 02:45:11 AM
wow. getting the length of a string is a troublesome task in batch.

When you start hitting such problems in batch, often it's a sign that you need to be using another language.

Like VBScript. Len() Function to the rescue! Quote from: BC_Programmer on January 17, 2009, 04:59:16 AM
Like VBScript. Len() Function to the rescue!

exactly

Code: [Select]@echo off
set string=Mary had a little lamb
echo Wscript.echo (Len(WScript.Arguments(0)))>stringlength.vbs
for /f %%L in ('cscript //nologo stringlength.vbs "%string%"') do set /a slen=%%L
del stringlength.vbs
echo String length is %slen%
Quote from: Dias de verano on January 17, 2009, 04:39:15 AM
Quote from: BC_Programmer on January 17, 2009, 02:45:11 AM
wow. getting the length of a string is a troublesome task in batch.

When you start hitting such problems in batch, often it's a sign that you need to be using another language.

Hmmm - there's a none too subtle hint
2868.

Solve : Newbie Question about cd?

Answer»

Hi,
I am using cd to change to my destination DIRECTORY. I think it is not successful, since the path shown before prompt does not change. For example,

"C:\DOCUMENTS and Settings\lehe>cd D:\New FOLDER

C:\Documents and Settings\lehe>"

If I do dir, it still shows the files under "C:\Documents and Settings\lehe". How can I move to the path where I want to be"
Thanks for help!you need to change the drive using this command Code: [Select]D: then Code: [Select]cd "D:\new folder"
FBlehe - WELCOME to the CH forums.

You could also use CD /D D:\NEW FOLDER

-or-

You could use PUSHD D:\NEW FOLDER
then POPD to return to the default directory you were in before using PUSHD.

Enter CD/? or PUSHD/? or POPD/? at the command prompt for more info.

Upper case is used for emphasis only.

Good luck

2869.

Solve : Rename a file per content?

Answer»

I have multiple files in a folder and each one needs to be opened; read the first line and determine one of several files to append the entire contents of the opened file to.
Example:
77521.txt
:JobShop22:
Text1
Text2
Text3

77522.txt
:JobShop48:
Text1
Text2
Text3


77523.txt
:JobShop22:
TextA
TextB
TextC


If first line == ":JobShop22:" then append to file Job22Output.txt
If first line == ":JobShop66:" then append to file Job66Output.txt
If first line == ":JobShop48:" then append to file Job48Output.txt

RESULTS:
Job22Output.txt
:JobShop22:
Text1
Text2
Text3
:JobShop22:
TextA
TextB
TextC



Job48Output.txt
:JobShop48:
Text1
Text2
Text3

I hope this makes sense!
Any help on this would be greatly appreaciated.



Anyone??? EDIT: Nevermind.This ASKS for user input, then sets %file% as the first line of %filevar% and it will append the full contents of %filevar% to the TXT file, depending on what the first line is.

@echo off
:loop
set /p filevar=FILE NAME INCLUDING PATH:
set /p file=<"%filevar%"
if %file% == :JobShop22: type "%filevar%" >> Job22Output.txt & goto win
if %file% == :JobShop66: type "%filevar%" >> Job66Output.txt & goto win
if %file% == :JobShop48: type "%filevar%" >> Job48Output.txt & goto win
Echo Error! File does not contain SPECIFIED strings in the first line!
pause
goto :loop
:win
Echo ALL DONE!
pauseThank you!
That part is exactly what I needed.
What do I need to do to make it read multiple files from a folder without the user input?That is FAIRLY simple as well, but the code gets MUCH longer depending on how many files you want.

Basically, delete Code: [Select]set /p filevar=FILE NAME INCLUDING PATH:
And replace Code: [Select]set /p file=<"%filevar%"With Code: [Select]set /p file=<"YOUR FILE NAME HERE"
Then, copy it over and over, replacing "goto win" with "goto WIN2" the second time, and ":win" with ":win2" the second time(and so on and so forth). Just do a bit of nitpicking with the script and it will work as many times as you want.

2870.

Solve : Delete file and reg key, after killing a task...?

Answer»

Quote from: BC_Programmer on JANUARY 17, 2009, 02:39:29 AM

then those 2 shouldn't be being helped by you.
I will TRY to do that from now on...
2871.

Solve : batch file not taking parameter properly?

Answer»

I am passing one parameter to batch file which is date time in following format.
EventParam="01/08/09,02:38:42PM-01/08/09,02:38:58PM"
System.Diagnostics.Process.Start("D:\param.bat",EventParam)
When I am CALLING batch file with process.start it takes the EventParam argument as "01/08/09" only. It doesn't tale the whole string. I guess this problem is because of commas in between . Any solution to this?



Code: [Select]
@echo off

echo %1

cscript C:\Windows\system32\eventquery.vbs /s RemoteMachineIP /u DomainName\userName /p Password /fi "Type eq Error" /fi "Datetime eq %1" /l "onlineavl services" >> Eventlogs.log

Yes.
What is the EXACT code you use?
Use the code button on the tool bar above so we can see
all spacing and layout just as it is in the bat file. My batch file is

@echo off

echo %1

cscript C:\Windows\system32\eventquery.vbs /s remoteMachineIP /u NW\username /p password /fi "Type eq Error" /fi "Datetime eq %1" /l "onlineavl services" >> Eventlogs.logHave you tested the script?
You have @echo off
This is a poor preactice if you have not yetproven the file works.
Also, can you break this into smaller steps?
And do you test the %1 parameter to see if it is a valid VALUE?
Instead of USING >> to a file, did you first confirm that the script was working?
Batch files, or any kind of programming becomes easier
if you can break it down into smaller bits.
If possible, test each part by itself. Then you can see where the problem is.

Hint: try putting the complex string parameter into a file and ave the program
read the parameter from the file. But not from of the command line.

The command interpreter treys to parse things on the command line and may not pass the entire string to the program as the first parameter. The way to avoid this is to have a program parse the string with no help of the command interpreter. Put the string in a file.

Yes, there are other was to fix the problem.
My pint of view is just make it simple and it will WORK.the script is included with Windows, so one can assume that that works.

However... what is up with this particular part:



Quote


cscript C:\Windows\system32\eventquery.vbs /s remoteMachineIP /u NW\username /p password /fi "Type eq Error" /fi "Datetime eq %1" /l "onlineavl services" >> Eventlogs.log

Some of the parameters passed to the script appear to be the same PROVIDED with the documentation as placeholders for actual values.

If it's the local machine, this should work sufficiently:


Code: [Select]eventquery.vbs /fi "Type eq Error" /fi "Datetime eq %1" /l "onlineavl services" >> Eventlogs.log

if it isn't the local machine, and/or it requires a password, you'll need to change the placeholder text.
2872.

Solve : Switches - Removing Programs?

Answer»

I found the following syntax to REMOVE a program.

"C:\WINDOWS\SomePath\xxxIM.exe" /remove "C:\WINDOWS\SomePath\IM_20080-40301-1100-200\xxxim\xxxIM_installed.xml"

Are there any other switches that can be used here?

For example; running SILENTLY without user input and accepting defaults

Thanks,

BradYou mean switches for the (oddly named) xxxIM.exe? That path sure looks odd! I doubt if anyone knows. Why don't you try

"C:\WINDOWS\SomePath\xxxIM.exe" /?

Yes, switches or parameters.

I just modified the path so SOMETHING generic since the actual program path/NAME didn't seem to be that relevant. The "xxxIM.exe" is an Installation Manager.

I tried your idea; it ignored the help switch and ran the installation manager.

The point I was trying to make is that there is not a standard set of switches that all programs (and commands) have. It depends on what switches the writer of the program DECIDED to build into it. You asked what other switches are available in some disguised program whose name we do not know. The answer is, therefore, "nobody can tell".
Okay, I didn't know that. The program is SolidWorks and the IM is sldIM.exe. I assume not many people would know details about this software on this forum, that is why I made the path and name more generic or disguised.

Thanks.

2873.

Solve : grouping text in a single line while doing for statement?

Answer»

ok. i have a problem.

this is a simple BAT file that lists a subdirs and MAKES a summary of them
looking for .sql, berime.txt, menu.txt and ##FS sub dir

program returns

Code: [Select]VER: HF_20081222B
******************************************
2008-12-24_MIHAJ_HON_#2
2008-12-30_MIHAJ_HON_#1
2008-12-30_SRECKO_PROJ_3_FAKULTETE
SQL
2008-12-30A_NG_MAT_3_JPLPT
2008-12-31A_ALVO_FIN_#2
SQL
2009-01-05A_ALVO_FIN_#3
2009-01-08A_SRECKO_PRE_FAKT_#3
2009-01-12_MIHAJ_KAD_#3_FE
2009-01-13A_SRECKO_MP_ZRC_#2
2009-01-13B_NG_FIN_#3_FE
2009-01-14A_IGOR
SQL
2009-01-15A_MIHAJ_KPS_#1
SQL
FS
2009-01-15D_MIHAJ_OD_#2
MENU
2009-01-16A_NG_FIN_#3
SQL
2009-01-16B_NG_FS_#3
FS
!!without BERIME.TXT!!

i WOULD like it to RETURN

Code: [Select]VER: HF_20081222B
******************************************
2008-12-24_MIHAJ_HON_#2
2008-12-30_MIHAJ_HON_#1
2008-12-30_SRECKO_PROJ_3_FAKULTETE SQL
2008-12-30A_NG_MAT_3_JPLPT
2008-12-31A_ALVO_FIN_#2 SQL
2009-01-05A_ALVO_FIN_#3
2009-01-08A_SRECKO_PRE_FAKT_#3
2009-01-12_MIHAJ_KAD_#3_FE
2009-01-13A_SRECKO_MP_ZRC_#2
2009-01-13B_NG_FIN_#3_FE
2009-01-14A_IGOR SQL
2009-01-15A_MIHAJ_KPS_#1 SQL FS
2009-01-15B_MIHAJ_KAD_#3
2009-01-15C_MIHAJ_OD_#1
2009-01-15D_MIHAJ_OD_#2 MENU
2009-01-16A_NG_FIN_#3 SQL
2009-01-16B_NG_FS_#3 FS !!without BERIME.TXT!!

so can i merge in a string a couple of lines before writing output file?


program looks like
Code: [Select]
@echo off
cls
for %%i in (".") do (
set pot_NV=%%~fsi
set dats_ime=%%~ni
)

if not exist %pot_NV%\##FS. (
mkdir %pot_NV%\##FS
)
set prip_fs=%pot_NV%\##FS

set dat_ime=%pot_NV%\%dats_ime%.log
echo VER: %dats_ime% >%dat_ime%
echo ****************************************** >>%dat_ime%

for /F %%j in ('dir *. /a:d /b /o:n') do (
if not %%~nj==##FS (
echo:%%~nj >>%dat_ime%

if exist %%~fsj\*.sql (
echo: SQL >>%dat_ime%
)

if exist %%~fsj\##FS. (
echo: FS >>%dat_ime%
xcopy %%~fsj\##FS\*.* %prip_fs% /E /Y >nul
)

if exist %%~fsj\menu.txt (
echo: MENU >>%dat_ime%
)

if not exist %%~fsj\berime.txt (
echo: !!without BERIME.TXT!! >>%dat_ime%
)
)
)

2874.

Solve : Accommodating the White Spaces in a DOS command?

Answer»

hey friends, i want to know how to add white spaces in a DOS command.
e.g. i have a folder named 'my documents' &AMP; another one named 'my archives'. now, if i want to copy some FILES from 'my documents' to 'my archives' using any DOS command, like 'copy' or 'xcopy', the syntax will be:
copy c:\my documents\*.* d:\my archives (Using copy) OR
xcopy c:\my documents\ d:\my archives (Using Xcopy).

The system throws the error: Invalid number of the parameters

Is there any WAY to do this, apart from renaming the concerned folders(that is very frustrating, i tell u)?

Did you try this?
Code: [Select]xcopy "c:\my documents\" "d:\my archives"
But why no do it in windows?Quote from: md_ahirrao on January 15, 2009, 11:46:37 PM

hey friends, i want to know how to add white spaces in a DOS command.
e.g. i have a folder named 'my documents' & another one named 'my archives'. now, if i want to copy some files from 'my documents' to 'my archives' using any DOS command, like 'copy' or 'xcopy', the syntax will be:
copy c:\my documents\*.* d:\my archives (Using copy) OR
xcopy c:\my documents\ d:\my archives (Using Xcopy).

The system throws the error: Invalid number of the parameters

Is there any way to do this, apart from renaming the concerned folders(that is very frustrating, i tell u)?



yes. put quotes around the names.

Code: [Select]copy "c:\my documents\*.*" "d:\my archives"
xcopy "c:\my documents\" "d:\my archives"

but why not just use explorer to copy.


EDIT: LOL.... beat me to it...thanks BC_programmer.
thanks Geek-9pm
it worked
2875.

Solve : Echo complex variable?

Answer»

Code: [Select]@echo off
setlocal enabledelayedexpansion

call SET %cd%.var=!%%cd%.var%!works

echo !%cd%.var!
I'm trying to echo the variable that was set in the fourth LINE of code. The output should simply read "works". I've checked and the variable is being set correctly. I just cant SEEM to echo it properly. Any ideas?

Thanks all.I think it is not going to work that WAY because the %cd% variable is going to have the colon CHARACTER ( which the SET command will try to use for string substitution. It looks like you are trying to set a variable for the current directory you are in? If so, you can modify your code to not include the ':' character ... something like
Code: [Select]@echo off
setlocal enabledelayedexpansion

call set %cd:~3%.var=!%%cd%.var%!works

echo !%cd:~3%.var!Quote from: GuruGary on January 15, 2009, 09:03:17 PM

It looks like you are trying to set a variable for the current directory you are in?

Exactly.

Quote from: GuruGary on January 15, 2009, 09:03:17 PM
I think it is not going to work that way because the %cd% variable is going to have the colon character ( which the SET command will try to use for string substitution.

With the output I was receiving, that makes perfect sense.

Your code works fantastically for my situation. Thank you for helping, I really appreciate it.
2876.

Solve : CHOICE .V. SET /P?

Answer»

Quote from: BatchFileCommand on JANUARY 15, 2009, 05:03:44 PM

I LOOKED up Industrial Lathe

So then you were the one UNFAMILIAR with what an industrial lathe was.

Quote from: BatchFileCommand on January 13, 2009, 05:17:34 PM
If you don't KNOW what a industrial lathe is...
2877.

Solve : pause / wait?

Answer»

Quote

im reinventing the wheel

How do you suppose to do that.Quote from: BatchFileCommand on JANUARY 12, 2009, 04:34:22 PM
Quote
im reinventing the wheel

How do you suppose to do that.

because it's been done before. i'll see if i cant whip up something, this time it will have a more throurgh debugging to avoid another bug REPORT Quote
this time it will have a more throurgh debugging to avoid another bug report

I've tried it with pure batch files (78 kb!) I've tried. Even with measly 4 kb, there's always going to spell errors or some kind of problem with administrator access etc. you TALKING about FINFO?Quote from: BatchFileCommand on January 13, 2009, 04:58:04 PM
Quote
this time it will have a more throurgh debugging to avoid another bug report

I've tried it with pure batch files (78 kb!) I've tried. Even with measly 4 kb, there's always going to spell errors or some kind of problem with administrator access etc.


If you use a compiled language like VB.NET,VB6, VCPP, or various others... you cannot even compile the program if it has misspellings. Unless of course the typo is still a valid symbol.Quote


If you use a compiled language like VB.NET,VB6, VCPP, or various others... you cannot even compile the program if it has misspellings. Unless of course the typo is still a valid symbol.

That is one thing I don't like about that though.
Quote from: BatchFileCommand on January 14, 2009, 04:43:23 PM
Quote


If you use a compiled language like VB.NET,VB6, VCPP, or various others... you cannot even compile the program if it has misspellings. Unless of course the typo is still a valid symbol.

That is one thing I don't like about that though.


yeah, it's MUCH better if it crashes with a syntax error on the victim... I mean, clients machine. much more professional.

if there are parts of the program that are only executed in extreme conditions, and there is an syntax error... you wouldn't even know until those "extreme conditions" are satisfied. and with 72 PAGES of batch code, there will be a LOT of unexplored code paths just waiting to throw a interpreter error.thats why its smart to seperate the batch programs.
2878.

Solve : Run a program before shutting computer down??

Answer»

I would like to write a batch file that runs an application before shutting the COMPUTER down. The application would take about a minute to complete, then computer can shut itself down.

thanksShutdown command in the .bat file? The code is relatively easy to make:

Code: [Select]@echo off
start application
ping localhost 240 >nul
shutdown /s

That should start the application, and then give it enough time to complete then it will shutdown.Quote from: BatchFileCommand on January 12, 2009, 06:28:49 AM

The code is relatively easy to make:

Code: [Select]@echo off
start application
ping localhost 240 >nul
shutdown /s

That should start the application, and then give it enough time to complete then it will shutdown.

That would bring an error(you wouldn't see it because there is no PAUSE). Shutdown /s doesn't exist, it's -s .Quote
Shutdown /s doesn't exist

That's because you use xp. I use vista. Quote from: BatchFileCommand on January 12, 2009, 04:28:47 PM
Quote
Shutdown /s doesn't exist

That's because you use xp. I use vista.

and so will everybody that ever uses your program, I take it.If I had a program that was worth giving out to people, I always make an xp version. Locbtran didn't specify EXACTLY what OS he had, so to make sure, you could have had 2 seperate code boxes, one which states it's for vista, the other for XP...(Or any other OS).I have also used a program called Xecutor but it costs money for commercial use. Free for private use.

http://english.xecutor.de/It's like my program hyperfolder with a few goodies . I could make a program even better in 15 days.It isn't hard to just make this VBS


Quote from: Sidewinder on DECEMBER 27, 2008, 10:06:47 AM
Quote
Can VBScript shut down a PC?

Yes. This little snippet will shutdown the local computer.

Code: [Select]strComputer = "."
Set objWMIService = GetObject_
("winmgmts:{impersonationLevel=impersonate,(Shutdown)}\\" & _
strComputer & "\root\cimv2")

Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")

For Each objOperatingSystem in colOperatingSystems
objOperatingSystem.Win32Shutdown(1)
Next

Quote
Can it shut down all PCs on a LAN?

Only if the PC's are part of a domain. This little snippet will shutdown 3 computers on the network.

Code: [Select]arrComputer = Array("Computer1", "Computer2", "Computer3")

For Each strComputer In arrComputer
Set objWMIService = GetObject _
("winmgmts:{impersonationLevel=impersonate,(Shutdown)}\\" & _
strComputer & "\root\cimv2")

Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")

For Each objOperatingSystem in colOperatingSystems
objOperatingSystem.Win32Shutdown(1)
Next
Next

If none of these are helpful, check out PsTools, specifically PsExec. VBScript can launch a new process with the Run method.

Good luck.



and then use it in a batch file- run the program, then run the script.Quote from: BC_Programmer on January 13, 2009, 06:14:35 PM
It isn't hard to just make this VBS


Quote from: Sidewinder on December 27, 2008, 10:06:47 AM
Quote
Can VBScript shut down a PC?

Yes. This little snippet will shutdown the local computer.

Code: [Select]strComputer = "."
Set objWMIService = GetObject_
("winmgmts:{impersonationLevel=impersonate,(Shutdown)}\\" & _
strComputer & "\root\cimv2")

Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")

For Each objOperatingSystem in colOperatingSystems
objOperatingSystem.Win32Shutdown(1)
Next

Quote
Can it shut down all PCs on a LAN?

Only if the PC's are part of a domain. This little snippet will shutdown 3 computers on the network.

Code: [Select]arrComputer = Array("Computer1", "Computer2", "Computer3")

For Each strComputer In arrComputer
Set objWMIService = GetObject _
("winmgmts:{impersonationLevel=impersonate,(Shutdown)}\\" & _
strComputer & "\root\cimv2")

Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")

For Each objOperatingSystem in colOperatingSystems
objOperatingSystem.Win32Shutdown(1)
Next
Next

If none of these are helpful, check out PsTools, specifically PsExec. VBScript can launch a new process with the Run method.

Good luck.



and then use it in a batch file- run the program, then run the script.

This is how I incorporate VBS into a batch file.

echo 'visual basic script' >> script.vbs

I need to do this for every SINGLE line of code.
Is there a quicker way of doing this?

thank youQuote
This is how I incorporate VBS into a batch file.

echo 'visual basic script' >> script.vbs

I need to do this for every single line of code.
Is there a quicker way of doing this?

I've seen this technique posted on the boards and I'm puzzled why anyone would do this. Using batch code to output a VBScript seems overly complex when the script has characters that are specially used by the batch interpreter. All those pesky escape characters.

Why not write the code in an editor, save the script with a vbs extension and then call the script from the batch file?

Code: [Select]call cscript drive:\path\scriptname.vbs



By creating a separate file for the VBScript, you can call the script from multiple batch files without having to reinvent the wheel.

Good luck.

2879.

Solve : Need help with housekeeping of files?

Answer»

Hi,

How can I do some housekeeping of files. Evertime I copy a new set of files to a SERVER, I backup the old files to a log folder with today's date. I just want to maintain the most recent 5 log folders.

I have attached an image with this post. It shows my directory structure. What I want to do is maintain the 5 most recent folders.

Any IDEAS??

[attachment deleted by admin]You have two different naming conventions in the high level folder. This snippet shows method as opposed to a written in granite solution. Currently the snippet sorts the folders by descending date, then KEEPS the most current five.

Code: [Select]@echo off
for /f "skip=5 tokens=* delims=" %%i in ('dir \\dnroot\data\equities\prime\ecm\backup /a:d /b /o:-d') do (
echo %%i
)

The snippet will list the folders to be deleted. When you are satisfied with the results, change echo to rd /s /q.

Quote

You have two different naming conventions in the high level folder.

Yeah, I need to modify that. EVENTUALLY, It will only have one naming convention.

But yet again, this is exactly what I wanted. works perfect.

Everytime I have posted a question, your answer has been perfect, bang on target. You are a guru of batch programming. I am sure you have acquired this knowledge due to years of experience with Batch scripting.

I would like to learn batch scripting in detail. Most of the things are quite easy, except for complicated for loops. Could you suggest me some BOOK. Also some best practices, things that should not be missed when coding a Batch program.

Maybe Admin's could start a new topic that could be helpful to all..

Thanks once again Sidewinder.. You Rock!!! Back in the day when DOS was an operating system and not some misquoted acronym, both the IBM and Microsoft DOS actually came with manuals. Really!

Nowadays, you buy a Windows operating system and Microsoft kicks you in the *censored* and wishes you good luck. Really!

This article may be what you're looking for. Be sure to check out the epilog for that wish of good luck.



2880.

Solve : commands are disabled...!!!!?

Answer»

whenever i type any command such as help in my dos prompt , i get the following message...Quote

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

Seems as if some or more commands are disabled...how can i re-enable them....

plzzz...do help.....
my operating system is WINDOWS xp and dos version is 5.1.2600Check your path. Type path at the command prompt then hit ENTER. Check to see if c:\windows\system32 is listed.

You may have run a program that overrode the system path. Sometimes closing the command prompt and re-opening it will clear the problem.

It intrigues me, what could override the path to system32 . When changing the path it's better to concatenate whatever directory onto the EXISTING path.

Code: [Select]SET path=%path%;c:\user

If a batch file attempts something like this:

Code: [Select]set path=c:\user

the path remains in effect until the command window is closed. Batch code cannot make permanent changes to environment variables, so the NEXT time a command window is opened, the system environment is re-established to the default values.



PS. Not saying this is the OP problem. Only a possibility.
2881.

Solve : REG ADD question. I'm stumped.?

Answer»

Hello,

I am trying to create a new DWORD value and I'm having some trouble.

Here is the value I'm trying to create:

Windows Registry Editor Version 5.00

REG ADD HKLM\SYSTEM\CurrentControlSet\Control\FileSystem /v NtfsMemoryUsage /t REG_DWORD /d 00000002


When I put this in a .reg file and execute it, it says the reg has succesfully been entered into the registry but when I go to check for it its not there. However, when I put that line into a batch file and run it, it does show up in the registry. Why is that, and how can I enter this new DWORD via a .reg instead of .bat? Not sure why this isn't working but I know you guys will.

Thanks for any help,

That doesn't look like a reg file to me

Quote

REGEDIT4
BLANK LINE GOES HERE
[HKEY_HIVE\KEY\KEY] @="keyvalue"
BLANK LINE GOES HERE
Dias, I'm not sure what you mean... what I have above is not a valid registry file when saved as .reg?

Could you break it down for me a good bit more because I'm unsure where to start from what you posted. Pardon me as I am only a novice.

This is how I interpreted your post for me to start... but this didn't add anything to the registry, so I take it this is not what you want me to try:

REGEDIT4

[HKLM\SYSTEM\CurrentControlSet\Control\FileSystem] @="NtfsMemoryUsage"


I'm using xp home if that matters.
I could not get the file starting REGEDIT4 to work!

However, Microsoft has a page of useful help at this address

http://support.microsoft.com/kb/310516

Which you could have found easily using Google!

(Have you heard of Google?)


Quote
A .reg file has the following syntax:

RegistryEditorVersion
Blank line
[RegistryPath1]
"DataItemName1"="DataType1:DataValue1"
"DataItemName2"="DataType2:DataValue2"
Blank line
[RegistryPath2]
"DataItemName3"="DataType3:DataValue3"

Quote
RegistryEditorVersion is either "Windows Registry Editor Version 5.00" for Windows 2000, Windows XP, and Windows Server 2003, or "REGEDIT4" for Windows 98 and Windows NT 4.0. The "REGEDIT4" header also works on Windows 2000-based, Windows XP-based, and Windows Server 2003-based computers.

Quote
Blank line is a blank line. This identifies the start of a new registry path. Each key or subkey is a new registry path. If you have several keys in your .reg file, blank lines can help you to examine and to troubleshoot the contents.

Quote
RegistryPathx is the path of the subkey that holds the first value you are importing. Enclose the path in square brackets, and separate each level of the hierarchy by a backslash. For EXAMPLE:
[HKEY_LOCAL_ MACHINE\SOFTWARE\Policies\Microsoft\Windows\System]

Quote
DataItemNamex is the name of the data item that you want to import. If a data item in your file does not exist in the registry, the .reg file adds it (with the value of the data item). If a data item does exist, the value in your .reg file overwrites the existing value. Quotation marks enclose the name of the data item. An EQUAL sign (=) immediately follows the name of the data item.

Quote
DataTypex is the data type for the registry value and immediately follows the equal sign. For all the data types other than REG_SZ (a string value), a colon immediately follows the data type. If the data type is REG_SZ , do not include the data type value or colon. In this case, Regedit.exe assumes REG_SZ for the data type.


It appears that you are trying to modify ntfs performance by using a registry tweak. You need to be aware that the tweak you propose to use will only have any useful effect if you have 2 GB or more of RAM. If you have LESS, ntfs performance will be badly REDUCED!

However, this would be the reg file format:

dword values:
00000001 normal (default) setting
00000002 enhanced (performance) setting if you have > 2 GB RAM


Code: [Select]Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem]
"NtfsMemoryUsage"=dword:00000002
Of course I have heard of google, Dias and despite what you think I was using it a lot before I resorted to coming here. I didn't come here to get someone else to do all the work for me. Here's what happend... I had success modifying existing dword values and when I needed to create one that wasn't already there I *censored*umed I had to use completely different syntax. I had just figured it out before you layed into me.

Thanks for the help Dias... you are kind of on EDGE but your knowledge is extensive and appreciated.

Happy New Year.

You are right; I had no need to patronise you. I apologise. Blame it on last night's Argentinian Malbec.No problem.
2882.

Solve : Finding text in files?

Answer»

The DOS DIR command is great, but it does have its limitations. I'm trying to find a particular word as it occurs in all files. and re-direct the results of the search to a text FILE. I'd also like to be able to exclude some folders (like that with my saved email) which are just going to complicate things.

I'm using WIN2000, and I know I can use its search function, but that won't allow me to re-direct the results, nor will it let me specify what I'd like to exclude.

Any ideas?

Tom

This little snippet may help:

Code: [Select]@echo off
setlocal enabledelayedexpansion
::
:: Exclude array
::
set array.1="drive:\path1"
set array.2="drive:\path2"


for /f "tokens=* delims=" %%f in ('dir c:\ /a:d /s /b') do (
for /l %%i in (1, 1, 2) do (
set count=0
find /i "!array.%%i!" %%f
if not errorlevel 1 call set /a count+=1
)
if !count! GTR 0 (
for /f "tokens=* delims=" %%d in ('dir /a:-d /b %%f\%%d ^| find /i "arg") do (
if not errorlevel 1 echo ....
)
)
)

Notes:

1. the highlighted NUMBER in this line: for /l %%i in (1, 1, 2) do (
must match the number of items in the exclude array.

2. replace the highlighted arg in this line:
for /f "tokens=* delims=" %%d in ('dir /a:-d /b %%f\%%d ^| find /i "arg") do (

3. Replace the dots with redirection of the information you want saved to the text file (ex. echo %%f\%%d >> text.txt)

Disclaimer: This snippet has not been tested, so drive carefully Thanks for the fast response. That sure looks like it will work. I won't have time to try it for a couple of days, but I'll report the results.
TomI was able to get back to my computer earlier than I expected, and I tried the suggested snippet. Sadly, without luck. I obviously have done something wrong.

I created a file called "Findword.Bat" and ran it. Here is the file, as written:
_______________________________________ ____________________
:: @echo off
setlocal enabledelayedexpansion
::
:: Exclude array
::

set array.1="c:\Paprport"
set array.2="C:\Windows"

for /f "tokens=* delims=" %%f in ('dir c:\ /a:d /s /b') do (
for /l %%i in (1, 1, 2) do (
set count=0
find /i "!array.%%i!" %%f
if not errorlevel 1 call set /a count+=1
)
if !count! GTR 0 (
for /f "tokens=* delims=" %%d in ('dir /a:-d /b %%f\%%d ^| find /i "standard") do (

if not errorlevel 1 echo >> FOUNDIT.TXT
)
)
)
_______________________________________ ___________

On my hard drive , I have 2 directories named "Paprport" and "Windows" which I was trying to exclude. The is a file in the C:\ folder containing the text "standard".
I hoped that the program would ignore the 2 folders specified; find the file containing the word "standard", and put the name of that file, and its location into a file called "Founditit.TXT". This didn't happen.
When run the SCREEN showed line after line reading "Access Denied" and the name of a directory (not only the directories specified in the array, but others as well).
What have I done wrong, or failed to do right?
Tom
Quote

I obviously have done something wrong

I told you to drive carefully.

Actually you did nothing wrong, it was all my doing. I keep getting carried away, forgetting that batch code is not a programming language. So for my next trick, I went all procedural, which should make it easier to read, if nothing else.

Code: [Select]@echo off
setlocal enabledelayedexpansion
::
:: Exclude array
::
set array.1=c:\Paprport
set array.2=c:\windows


for /f "tokens=* delims=" %%f in ('dir c:\ /a:d /s /b') do (
set count=0
for /l %%i in (1,1,2) do (
if /i !array.%%i! EQU %%f set /a count+=1
)
if !count! EQU 0 call :search %%f
)
goto :eof

:search
for /f "tokens=* delims=" %%d in ('dir %1 /a:-d /b') do (
find /i "standard" %%f\%%d > nul
if not errorlevel 1 echo %%f\%%d >> FOUNDIT.TXT
)


This code has been tested and appears to meet all your specs.

Good luck. Quote from: Sidewinder on December 22, 2008, 03:57:21 PM
Quote
I obviously have done something wrong

I told you to drive carefully.

Actually you did nothing wrong, it was all my doing. I keep getting carried away, forgetting that batch code is not a programming language. So for my next trick, I went all procedural, which should make it easier to read, if nothing else.

This code has been tested and appears to meet all your specs.

Good luck.

I tried (actually am trying now) your new code, and it seems to be working. It's slow, but I expected that (Good;Fast:Cheap: You can only have 2 of them).

Thanks so much for your help. And a Merry Christmas (or whatever you prefer) to you.
TomThe code finished running, and it looks like it's back to square 1 now. The program found instances of the text I was looking for, and put the name of the file in the new file I wanted it to. Unfortunately, the instances it found were in a sub-directory of a directory I told it to exclude. It did not find the word in a file in the root directory I ran it from.

When run with the /s switch omitted, nothing was found, and no new file was created. It indicated while running that access was denied to the directories I wanted excluded, however.

The above was run on a machine using WIN2000. When I tried to run it on a machine with WIN98SE, it wouldn't run at all. It reported problems with the syntax.

If I wasn't so stubborn, I'd give up, but there's an answer lurking there somewhere.
TomWhile I was hunting down my Santa Claus outfit, I found a script in the snippet closet. With a tweak here and a tweak there, we could be talking about a serious script:

Code: [Select]On Error Resume Next
Const ForReading = 1

xDir = Array("c:\Paprport", "C:\Windows") 'Exclude array

Set fso = CreateObject("Scripting.FileSystemObject")
Set LogFile = fso.CreateTextFile("c:\temp\foundit.txt", True)

Set dc = fso.Drives
For each ds in dc
Select Case ds.Driveletter
Case "C" 'drive to search
Set RootDir = fso.GetFolder(ds & "\") 'directory to start search
GetTheFolders(RootDir)
End Select
Next
LogFile.Close

Function GetTheFolders(Folder)
For Each Subfolder in Folder.SubFolders
blnExclude = False
For Each item In xDir
If InStr(1, SubFolder.Path, item, 1) > 0 Then blnExclude = True
Next

If blnExclude = False Then
GetTheFiles(Subfolder.Path)
GetTheFolders Subfolder
End If
Next
End Function

Function GetTheFiles(FileFolder)
Set f = fso.GetFolder(FileFolder)
Set fc = f.Files
For Each fs in fc
If fso.GetExtensionName(fs) = "txt" Then 'Extension to look at
Set k = fso.OpenTextFile(fs, ForReading)
strFile = k.ReadAll
k.Close
If InStr(1, strFile, "standard", 1) > 0 Then
LogFile.WriteLine fs
End If
End If
Next
End Function

Yes I know, this is not batch code. Save the script with a vbs extension and run from the command prompt as cscript scriptname.vbs

The script will scan the C drive looking for txt files. The drive can be changed and we can add more extensions, but there really is no point in checking exe files for a string.

Happy Christmas to you and a Merry New Year. Quote from: Sidewinder on December 23, 2008, 04:48:49 PM
While I was hunting down my Santa Claus outfit, I found a script in the snippet closet. With a tweak here and a tweak there, we could be talking about a serious script:

Yes I know, this is not batch code. Save the script with a vbs extension and run from the command prompt as cscript scriptname.vbs

The script will scan the C drive looking for txt files. The drive can be changed and we can add more extensions, but there really is no point in checking exe files for a string.

Happy Christmas to you and a Merry New Year.

Thanks for the code. It looks like it would find a string in a TXT file, but only there. What I was trying to do is find a particular string in files of any type, and to exclude directories where the string I was looking for couldn't possibly be found; and then to put the results into a file.

(A word of explanation for my wanting to do a thing like that might be helpful here. It's for my wife, who is looking for something she stored on her computer, but can't remember the name of the file, nor where she put it; only what it was about.)

Windows does the first PART of what I want to do with its Search (Find) function, but won't do the 2nd part. Nor will it put the results into a file.

The previous code you sent looked like it would remedy those deficiencies, but it didn't work. I'd like to find out why it wouldn't do what it should have done.

I'll understand if you throw up your hands at this point. I know I would if I were in your place. I'll keep plugging away at it, though. I hate not being able to figure things out.

As I often say: I wish I understood all I know about computers.
Tom
Quote
The previous code you sent looked like it would remedy those deficiencies, but it didn't work. I'd like to find out why it wouldn't do what it should have done.

Which previous code? The VBScript worked fine when it was tested. The previous batch code had it's own set of problems. Anyway I find it easier use a tool that has the functionality I need to reach a solution. Personally I find batch code underpowered and logically exhausting.

Quote
Thanks for the code. It looks like it would find a string in a file.TXT file, but only there. What I was trying to do is find a particular string in files of any type, and to exclude directories where the string I was looking for couldn't possibly be found; and then to put the results into a file.

The excluded directories are in the xDIR array and the file names that contained the search argument were logged to the foundit.txt. I used the temp directory on my system for the log file, you may not have that directory on your system. We can change it to a directory you do have.

As mentioned, we can add extensions to include or create extensions to exclude. Did you run the VBScript? Can you document any specific problems?



Quote from: Sidewinder on December 24, 2008, 08:51:25 AM
Quote
The previous code you sent looked like it would remedy those deficiencies, but it didn't work. I'd like to find out why it wouldn't do what it should have done.

Which previous code? The VBScript worked fine when it was tested. . Did you run the VBScript? Can you document any specific problems?


The previous code I referred to was the last batch code you sent. I ran the VBScript code you sent, and didn't get any results.
I can't document any specific problems, since the code ran silently, showing nothing on the screen, All I know is that no file called "Foundit.txt" was created, even though I had specifically created a TXT file in the Root directory containing the string I was searching for.

I'm not familiar with scripts, so I can't manipulate the code you sent in order to make the results appear on the screen; nor can I, for instance, eliminate sub-directories.

It looks like I'm going to have to learn scripting, though, since your code, even though it didn't produce results, ran a lot FASTER than if it were a batch file.

I do appreciate your efforts, and am sure that the failure to produce results lies with me, not you.
TomQuote
All I know is that no file called "Foundit.txt" was created, even though I had specifically created a TXT file in the Root directory containing the string I was searching for.

Perfect! Well, you can always have the search script search for it's output file.

Code: [Select]On Error Resume Next
Const ForReading = 1

xDir = Array("c:\Paprport", "C:\Windows") 'Exclude array

Set fso = CreateObject("Scripting.FileSystemObject")
Set LogFile = fso.CreateTextFile("c:\temp\foundit.txt", True)

Set dc = fso.Drives
For each ds in dc
Select Case ds.Driveletter
Case "C" 'drive to search
Set RootDir = fso.GetFolder(ds & "\") 'directory to start search
GetTheFolders(RootDir)
End Select
Next
LogFile.Close

Function GetTheFolders(Folder)
For Each Subfolder in Folder.SubFolders
blnExclude = False
For Each item In xDir
If InStr(1, SubFolder.Path, item, 1) > 0 Then blnExclude = True
Next

If blnExclude = False Then
GetTheFiles(Subfolder.Path)
GetTheFolders Subfolder
End If
Next
End Function

Function GetTheFiles(FileFolder)
Set f = fso.GetFolder(FileFolder)
Set fc = f.Files
For Each fs in fc
If fso.GetExtensionName(fs) = "txt" Then 'Extension to look at
Set k = fso.OpenTextFile(fs, ForReading)
strFile = k.ReadAll
k.Close
If InStr(1, strFile, "standard", 1) > 0 Then
'LogFile.WriteLine fs
wscript.echo fs
End If
End If
Next
End Function

As before, save the script with a vbs extension and run from the command prompt as cscript scriptname.vbs

Quote
I'm not familiar with scripts, so I can't manipulate the code you sent in order to make the results appear on the screen; nor can I, for instance, eliminate sub-directories.

I modified the script to display the results on the console. It was the sub-directories that gave me problems with the original batch file. With any luck, those problems have been eliminated with the VBScript. Note: c:\windows is excluded from the search, along with all it's sub-directories. Let me know if this is incorrect.

Quote
It looks like I'm going to have to learn scripting, though, since your code, even though it didn't produce results, ran a lot faster than if it were a batch file.

Did you use Windows Search to look for the foundit.txt file (ironic, huh)? It should be in c:\temp. I can't be certain if the CreateTextFile method would create the directory if it was not found.

I'm not suggesting it (I've been putting off downloading to my system), but Windows Desktop Search can be scripted through the Search object. Windows Update has been bugging me for moths to download it. Might be time to check it out.

I think next Christmas I'll do without the Santa outfit. Sorry, the new code didn't work, either. As before, nothing showed on the console while it ran. A file called "Foundit.TXT" was created, but it had no contents.
TomSUCCESS!!
The latest code you sent did work after all. The fault, as I suspected, was mine. The word I had chosen to search for didn't exist in a TXT file, and therefore couldn't be found. When I substituted a word which did exist, the program ran and produced the appropriate result.

Thanks.

Now I have to figure out how to search in files with other extensions, or perhaps learn to exclude those extensions which won't contain the string (like EXE or COM files, or image files)

'll keep plugging away at it.
TomQuote
SUCCESS!!

Glad it worked.

Quote
Now I have to figure out how to search in files with other extensions, or perhaps learn to exclude those extensions which won't contain the string (like EXE or COM files, or image files)

Try creating an array of the extensions like the excluded directories.

arrExt = Array("exe", "com", "jpg", "bmp", "png")....add as many as you need, each extension quoted with a comma separator

Code: [Select]Function GetTheFiles(FileFolder)
Set f = fso.GetFolder(FileFolder)
Set fc = f.Files
For Each fs in fc
blnExclude = False
For Each ext In arrExt
If LCase(fso.GetExtensionName(fs)) = ext Then
blnExclude = True
End If
Next

If blnExclude = False Then
Set k = fso.OpenTextFile(fs, ForReading)
strFile = k.ReadAll
k.Close
If InStr(1, strFile, "standard", 1) > 0 Then
'LogFile.WriteLine fs
wscript.echo fs
End If
End If
Next
End Function

Good luck and Happy New Year!

Considering all the file extensions on a PC, this could get interesting.
2883.

Solve : Automate changes - SortIDs?

Answer»

This is for work and the code is taken from this site I just tried tweaking and I'm not getting very far.

Code: [Select]@echo on
setlocal enabledelayedexpansion

set log=C:\Vision\batlog
set ivdir=C:\Vision
set ivlogin=c:\Vision\etc\ivlogin.cfg

set workfolder=C:\Vision\batwork\
md %workfolder%

cd /d %workfolder%

Rem Change ##### to the new SortPatternID
Set newID=#####

set holder1=ivlogin1.cfg
set holder2=ivlogin2.cfg

set outputfile=IDChg.cfg


MD %log%


Echo-------------------Create log %Date% ^& %time%--------------------->%log%\PattIDChg.log
Echo Created to automate Sort Pattern ID changes>>%log%\PattIDChg.log



Echo ----------Save for backup---------->>%log%\PattIDChg.log
type %ivlogin%>>%log%\PattIDChg.log
Echo ----------------------------------->>%log%\PattIDChg.log


Rem - Pull out anything that is not using the BAT directory, saving to add back to %ivlogin%
Rem ^*Reminder, have to figure how to remove -----------and directory name from this file

rem Find /I "0;bat\" %ivlogin%>>%holder1%
Find /I /V "0;bat\" %ivlogin%>>%holder2%


for /f "delims=" %%L in (%ivlogin%) do (
set cline=%%L
if "!cline:~0,1!"=="0;bat\" (
set /a lc=1
set hline=!cline!
set nuline=
set /a lc=!lc!+1
)
if !lc! GTR 0 (
if !lc! LSS 3 (
set nuline=!nuline!!cline!
)
)
set /a lc=!lc!+1
if !lc! GTR 3 echo !hline!!nuline! >> %holder1%

)



if exist %outputfile% del %outputfile%

echo for /f "tokens=1-5 delims=;" %%A in (%holder1%) do (

for /f "tokens=1,2,3,4,5 delims=;" %%A in (%holder1%) do (


echo %%A;%%B;%%C;%%D;%newid%>>%outputfile%

)
pause

The IVLOGIN File
Code: [Select]0;bat\Sortmvx.bat;MVX - Vision X;;
0;bat\sortsndp.bat;Branch Capture; ;84111
0;bat\sortsndp.bat;Branch Capture; ;82111
0;bat\sortsndp.bat;Branch Capture; ;86111
0;bat\sortsndp.bat;Branch Capture; ;88112
0;etc\xfer.cfg;File Transmissions;;
0;etc\reports.cfg;Reports;;
0;etc\config.cfg;Configuration;;
0;command\prntstmt.bat;Print Image Statements;;
0;command\dream.bat;DREAM Demo;;
0;bin\sps.exe;Sort Pattern Studio;;
0;command\fedecl.bat;Reconcile ECL File;;

0;etc\sorters.cfg;*DR Mode*;;
Problem with above file, they are not all going to look like this, it might be something more simple like this ...
Code: [Select]0;bat\sortsndp.bat;Branch Capture; ;86888
0;etc\reports.cfg;Reports;;
Then I have another problem, inside the same IVLOGIN.cfg file I might have ##### = 88888 on one line and that might need to change to 11111, then on another line I might have ##### = 86888 and that needs to CHANGED to 11112 or something like that, I was thinking I might be able to use the Find command to pull out line with this number then do a change and put it back, or maybe I could do something with tokens to check part of the number and then change it, guess I'm really just in need of some advice, if I can get help with the top part of the code, the Intial change I can probably use IFs and Errorlevels for the rest. Thanks for your help. Modified the code a little, but still confused on how to make it work right.

IVLOGIN2.cfg is a holder file for everything that doesn't start with "0;\bat"

IVLOGIN1.cfg contains this after running ...
Code: [Select]0;bat\sortsndp.bat;Branch Capture11; ;841110;bat\sortsndp.bat;Branch Capture223; ;82111
0;bat\sortsndp.bat;Branch Capture11; ;841110;bat\sortsndp.bat;Branch Capture223; ;82111
0;bat\sortsndp.bat;Branch Capture11; ;841110;bat\sortsndp.bat;Branch Capture223; ;82111
0;bat\sortsndp.bat;Branch Capture11; ;841110;bat\sortsndp.bat;Branch Capture223; ;82111
0;bat\sortsndp.bat;Branch Capture11; ;841110;bat\sortsndp.bat;Branch Capture223; ;82111
0;bat\sortsndp.bat;Branch Capture11; ;841110;bat\sortsndp.bat;Branch Capture223; ;82111
0;bat\sortsndp.bat;Branch Capture11; ;841110;bat\sortsndp.bat;Branch Capture223; ;82111
0;bat\sortsndp.bat;Branch Capture11; ;841110;bat\sortsndp.bat;Branch Capture223; ;82111
0;bat\sortsndp.bat;Branch Capture11; ;841110;bat\sortsndp.bat;Branch Capture223; ;82111
0;bat\sortsndp.bat;Branch Capture11; ;841110;bat\sortsndp.bat;Branch Capture223; ;82111
IDchg.cfg - almost seems like it working, but what I don't get is it is using the same line of code over and over again from the original IVLOGIN.cfg file. Not sure what i'm doing wrong in the for loop to cause this.

Code: [Select]0;bat\sortsndp.bat;Branch Capture11; ;#####
0;bat\sortsndp.bat;Branch Capture11; ;#####
0;bat\sortsndp.bat;Branch Capture11; ;#####
0;bat\sortsndp.bat;Branch Capture11; ;#####
0;bat\sortsndp.bat;Branch Capture11; ;#####
0;bat\sortsndp.bat;Branch Capture11; ;#####
0;bat\sortsndp.bat;Branch Capture11; ;#####
0;bat\sortsndp.bat;Branch Capture11; ;#####
0;bat\sortsndp.bat;Branch Capture11; ;#####
0;bat\sortsndp.bat;Branch Capture11; ;#####
Made this change to the original IVLOGIN.cfg to help troubleshoot myself ...
Code: [Select]0;bat\sortmvx.bat;MVX - Vision X;;
0;bat\sortsndp.bat;Branch Capture11; ;84111
0;bat\sortsndp.bat;Branch Capture223; ;82111
0;bat\sortsndp.bat;Branch Capture343; ;86111
0;bat\sortsndp.bat;Branch Capture4343; ;88112
0;etc\xfer.cfg;File Transmissions;;
0;etc\reports.cfg;Reports;;
0;etc\config.cfg;Configuration;;
0;command\prntstmt.bat;Print Image Statements;;
0;command\dream.bat;DREAM Demo;;
0;bin\sps.exe;Sort Pattern Studio;;
0;command\fedecl.bat;Reconcile ECL File;;

0;etc\sorters.cfg;*DR Mode*;;
Code: [Select]@echo on
rem setlocal enabledelayedexpansion

set log=C:\Vision\batlog
set ivdir=C:\Vision
set ivlogin=c:\Vision\etc\ivlogin.cfg

set workfolder=C:\Vision\batwork\
md %workfolder%

cd /d %workfolder%

Rem Change ##### to the new SortPatternID
Set newID=#####

set holder1=ivlogin1.cfg
set holder2=ivlogin2.cfg

set outputfile=IDChg.cfg


MD %log%


Echo-------------------Create log %Date% ^& %time%--------------------->%log%\PattIDChg.log
Echo Created to automate Sort Pattern ID changes>>%log%\PattIDChg.log



Echo ----------Save for backup---------->>%log%\PattIDChg.log
type %ivlogin%>>%log%\PattIDChg.log
Echo ----------------------------------->>%log%\PattIDChg.log


if exist %outputfile% del %outputfile%


for /f "tokens=1,2,3,4,5 delims=;" %%A in (%ivlogin%) do (
set var=%%E
Echo A:%%A , B:%%B , C:%%C , D:%%D , E:%%E - Var:%var% ^& ERRORLEVEL:%Errorlevel%>>%log%\PattIDChg.log

If "%%E"=="" (
Rem If / I %var% GTR 0 (
echo %%A;%%B;%%C;%%D;>>%outputfile%
) ELSE (

echo %%A;%%B;%%C;%%D;%newid%>>%outputfile%
)

)
pause
Made some major changes which woot!!! seem to work. So anyone have another idea of getting this to work differently or how to configure if I have newid1 & newid2? Sorry to bump again, just really happy I got this far. Sorry if I piss anyone off by posting again, but I think I got a bit further ... Though now I'm having an issue with the last part of my code Code: [Select]ELSE (
echo %%A;%%B;%%C;%%D;%%E>>%outputfile%
I want this bit of code to basically say if none of the other IF statements MATCH then keep the line and Echo it according.

Here is my final modification for now as I've been trying to get it to work the way I want it to for the last 2 hours or so. I still have Error Checking to do and a bit more code, but getting this part done and making it work is the only way I'm going to get anywhere. Thanks for the help.

Code: [Select]@echo on
rem setlocal enabledelayedexpansion

set log=C:\Vision\batlog
set ivdir=C:\Vision
set ivlogin=c:\Vision\etc\ivlogin.cfg

set workfolder=C:\Vision\batwork\
md %workfolder%

cd /d %workfolder%

Rem Change ##### to the Curr/New SortPatternID

Set CurrIDP=88888
Set newIDP=11111
Set CurrIDD=77777
Set newIDD=22222
Set CurrIDO=66666
Set newIDO=33333

set outputfile=IDChg.cfg


MD %log%


Echo -------------------Create log %Date% ^& %time%--------------------->%log%\PattIDChg.log
Echo Created to automate Sort Pattern ID changes>>%log%\PattIDChg.log



Echo ----------Save for backup---------->>%log%\PattIDChg.log
type %ivlogin%>>%log%\PattIDChg.log
Echo ----------------------------------->>%log%\PattIDChg.log


if exist %outputfile% del %outputfile%

Echo.>>%log%\PattIDChg.log
Echo Below ^Echo statements might help with troubleshooting ... >>%log%\PattIDChg.log
for /f "tokens=1,2,3,4,5 delims=;" %%A in (%ivlogin%) do (

Echo A:%%A , B:%%B , C:%%C , D:%%D , E:%%E ^& errorlevel:%Errorlevel%>>%log%\PattIDChg.log

If "%%E"=="" (
echo %%A;%%B;%%C;%%D;>>%outputfile%
) ELSE (
If "%%E"=="%CurrIDP%" echo %%A;%%B;%%C;%%D;%newIDP%>>%outputfile%
If "%%E"=="%CurrIDD%" echo %%A;%%B;%%C;%%D;%newIDD%>>%outputfile%
If "%%E"=="%CurrIDO%" echo %%A;%%B;%%C;%%D;%newIDO%>>%outputfile%
)

ELSE (
echo %%A;%%B;%%C;%%D;%%E>>%outputfile%
)
pauseCode: [Select] If "%%E"=="" (
echo %%A;%%B;%%C;%%D;>>%outputfile%
) ELSE (
If "%%E"=="%CurrIDP%" echo %%A;%%B;%%C;%%D;%newIDP%>>%outputfile%
If "%%E"=="%CurrIDD%" echo %%A;%%B;%%C;%%D;%newIDD%>>%outputfile%
If "%%E"=="%CurrIDO%" echo %%A;%%B;%%C;%%D;%newIDO%>>%outputfile%
)

ELSE (
echo %%A;%%B;%%C;%%D;%%E>>%outputfile%
)
why is Code: [Select] echo %%A;%%B;%%C;%%D;%%E>>%outputfile%
in twice?

having two ELSE's won't work i think.

FBThanks for the reply ...

Code: [Select]echo %%A;%%B;%%C;%%D;%%E>>%outputfile%Isn't in twice, it is different on the other line it echos....
Code: [Select]echo %%A;%%B;%%C;%%D;>>%outputfile%
Do you know of another way if a double ELSE isn't possible, which makes sense since it doesn't work. Reason for Code: [Select]echo %%A;%%B;%%C;%%D;%%E>>%outputfile% is Anything that doesn't match one of the other statements then plug it back to the file, in other words I don't want to lose something that is custom in the configuration file. how exactly would a double-else work to begin with? The condition is either true, or the condition is false.

I can't evem figure out exactly what you are trying to accomplish with more then one Else, here.


you have,

If "%%E"==""
(... executed when %%E is empty.
)
ELSE (
(
..executed when %%E contains anything.
)

ELSE(
what conditions do you want this one to execute under?
)
Quote

ELSE(
what conditions do you want this one to execute under?
)

The First ELSE STATEMENT is used when it determines that the 5th token has a value and the IF statements are in place to take one ID # and change it to something else.

The final ELSE which can't work ... I need a way to Echo the line even if it doesn't match part of the other criteria so I don't remove something that maybe needed as part of the configuration. Ahhh, I see now;

you have this part of code in the first else:

Code: [Select]If "%%E"=="%CurrIDP%" echo %%A;%%B;%%C;%%D;%newIDP%>>%outputfile%
If "%%E"=="%CurrIDD%" echo %%A;%%B;%%C;%%D;%newIDD%>>%outputfile%
If "%%E"=="%CurrIDO%" echo %%A;%%B;%%C;%%D;%newIDO%>>%outputfile%

and the last else was intended for if none of these conditions are true.
(because, as you said, you want to write something even if none of these do.


I thought about it for a little bit, and came up with a workable solution:


Code: [Select]set %hasoutput%=NO
If "%%E"=="%CurrIDP%" (
echo %%A;%%B;%%C;%%D;%newIDP%>>%outputfile%
set %hasoutput%=YES
}
If "%%E"=="%CurrIDD%" (
echo %%A;%%B;%%C;%%D;%newIDD%>>%outputfile%
set %hasoutput%=YES
)
If "%%E"=="%CurrIDO%" (
echo %%A;%%B;%%C;%%D;%newIDO%>>%outputfile%
set %hasoutput%=YES
)
if "%hasoutput%"=="NO" then echo %%A;%%B;%%C;%%D;%%E>>%outputfile%

and remove the third else that you have there.This is what I came up with ... Thanks BC_Programmer ... Got it working.

Code: [Select]for /f "tokens=1,2,3,4,5 delims=;" %%A in (%ivlogin%) do (
set hasoutput=NO

Echo A:%%A , B:%%B , C:%%C , D:%%D , E:%%E ^& errorlevel:%Errorlevel%>>%log%\PattIDChg.log


If "%%E"=="" (
echo %%A;%%B;%%C;%%D;>>%outputfile%
) ELSE (

If "%%E"=="%CurrIDP%" set hasoutput=YES & echo %%A;%%B;%%C;%%D;%newIDP%>>%outputfile%

If "%%E"=="%CurrIDD%" set hasoutput=YES & echo %%A;%%B;%%C;%%D;%newIDD%>>%outputfile%

If "%%E"=="%CurrIDO%" set hasoutput=YES & echo %%A;%%B;%%C;%%D;%newIDO%>>%outputfile%

If "%hasoutput%"=="NO" echo %%A;%%B;%%C;%%D;%%E>>%outputfile%
)
)
pause
2884.

Solve : Please, What does the @ do in the following example??

Answer»

Thanks in advance!
Please,
what does the @ do in the following example?

@echo Free Pascal Compiler test...
@echo For error MESSAGES, see fpctest.err.
@echo off
@if "%1"=="" goto usage
@if not exist %1. goto invpath
@del fpctest.err
@make file=%2 fpc=%1 -fMakefile.fpc
@type fpctest.err
@goto exit
:invpath
@echo invalid path "%1"
@goto exit
:usage
@echo usage: fpctest ^ ^
:exit

Thanks!
...Vernon
winXP, FreePascal/LazarusA @ at the start of a line prevents the line from being echoed when the batch is executed. You can achieve the same result by having this line as the first line of a batch file. Then you don't need the '@'s at the start of each line.

Code: [Select]@echo off
I don't know why the writer of that batch you posted chose to do it like that.

Ah, yes.
Thanks!

fav songs:
http://www.youtube.com/watch?v=NYWuNh22KO4
http://www.youtube.com/watch?v=7We1mex6OeMQuote from: vmars on January 14, 2009, 03:39:56 PM

fav songs:
http://www.youtube.com/watch?v=NYWuNh22KO4
http://www.youtube.com/watch?v=7We1mex6OeM

that's your reward Dias.

I'm to scared to click the links myself.
My favourite song would be the "ewe overture" or "symphony of the Billy-Goats".
I prefer the pictures though.Quote from: BC_Programmer on January 14, 2009, 04:04:15 PM
Quote from: vmars on January 14, 2009, 03:39:56 PM
fav songs:
http://www.youtube.com/watch?v=NYWuNh22KO4
http://www.youtube.com/watch?v=7We1mex6OeM

that's your reward Dias.

I'm to scared to click the links myself.
My favourite song would be the "ewe overture" or "symphony of the Billy-Goats".
I prefer the pictures though.

Cruel. I don't like those songs. I like Queen, Green Day, and Tim Powter.When you start talking with US "old-schoolers" you will hear some funny stories.

I was working for ITT Servcom in the early 80's and I was in a bank presidents office one day when I noticed a bright colored DOS menu on his computer screen.
I asked "How do you do that" and for the next hour, I sat there getting my first formal training in DOS batch file and menu creation, from a Bank President.

A PRACTICAL use of the @ sign would be to blank out just one line, in a batch file where all the other lines are being echoed to the screen.

When you start a batch file with Echo OFF, you put the @ sign at the start of the line so the command Echo Off won't be echo'ed to the screen.

I was taught to put:
@Echo Off
cls

at the beginning of every batch file. I do that to this very day.
It clears the screen ( CLS ) and keeps it clean while the batch file runs, unless you instruct it to echo certain lines to the screen.

For batch file testing, you MAY want to disable the @Echo Off command during the testing procedure. Then you can see if there are any error messages to your commands.

To disable any line, just put two colons ( :: ) at the beginning of the line and DOS will totally ignore that line. If you use REM, then DOS will continue to read the entire line, even though it will not (usually) execute it. There are a few instances where the line or part of it MAY be executed, that's why I never use REM, but always the double colon. Now it's just a habit.

Also, the batch file runs faster if DOS doesn't have to read the remark lines.

Cheers Mates, keep up the good work!

The Shadow Quote from: BatchFileCommand on January 14, 2009, 04:40:53 PM
Quote from: BC_Programmer on January 14, 2009, 04:04:15 PM
Quote from: vmars on January 14, 2009, 03:39:56 PM
fav songs:
http://www.youtube.com/watch?v=NYWuNh22KO4
http://www.youtube.com/watch?v=7We1mex6OeM

that's your reward Dias.

I'm to scared to click the links myself.
My favourite song would be the "ewe overture" or "symphony of the Billy-Goats".
I prefer the pictures though.

Cruel. I don't like those songs. I like Queen, Green Day, and Tim Powter.

I was of course joking

Queen is my all time favourite band.Quote from: TheShadow on January 14, 2009, 05:07:59 PM
To disable any line, just put two colons ( :: ) at the beginning of the line and DOS will totally ignore that line. If you use REM, then DOS will continue to read the entire line, even though it will not (usually) execute it. There are a few instances where the line or part of it MAY be executed, that's why I never use REM, but always the double colon. Now it's just a habit.

I'm an old schooler myself, and I might just add that the undocumented unofficial use of a broken LABEL ( as a comment will break inside a FOR loop, which is why I never use it.
2885.

Solve : What Command that promt to Fill In Text?

Answer»

Hi All,

Can you help me how to make a command that can promt & ask to fill in something TEXT. Then that text will be added in the text data file.

Thanks

e-BamSorry, but I don't really understand the question.

So you want a batch file that will ask for text, and when you press Enter it is saved in a text file?1st of all, thanks guys reply my question...

That say I click a batch file, then the dos will promt:

"Please Key In The Invoice No. : "

After you key in the number that say 1234, then this number will be added to the text file.

So,
1. How to make that question appear & functional?
2. How to insert the '1234' to the text file?

Thanks, Your help much2 appreacited.

e-Bam

Here's a code that will do just what you are asking for.

Quote

:start
set /p variable=Please Key In The INvoice No.
echo "%variable%" > some_file
pause>nul
goto start
Thanks dude, I appreaciate that..

I will try to use it..

e-BamThanks guys (BatchFileCommand).. Its working..

e-bamContinue from the last question. Now the situation is;

You have 1 text file called “data.txt” in 1 folder named “SOURCE”.

The data.txt has a numbers of characters as per below:

Bam;060180;engineer
John;050881;executive
Salem;151281;hackers
:
:

When you click the batch file, you will be asking to insert the invoice no. as per yesterday discussion.

The question is, how to make output data.txt file as per below?

Invoice No: 1234
Bam;060180;engineer
John;050881;executive
Salem;151281;hackers
:
:

Please advice..So, you want it to display Quote
Invoice Number:
followed by the invoice number? Simple!

Where it says Quote
echo "%variable%" > some_file
replace that with
Code: [Select]echo Invoice No: "%variable%" > some_file
If you want it to display Invoice No at the begining, that gets a bit tricky...But it's still possible!

Code: [Select]Echo Invoice No: "%variable%" > some_other_file
type data.txt >> some_other_file
type some_other_file > data.txt
del some_other_file
There, that will do it. Here is a step-by-step explanation of the script:
1. Sends "Invoice No: %variable%" to some_other_file which is important.
2. Sends the FULL contents of data.txt to the end of some_other_file.
3. Sends the full contents of some_other_file (part 1 + 2) to data.txt and overrides anything that was previously in data.txt
4. Deletes some_other_file.

Understand? I've understand whats u means. Thanks a lot.

BTW, yesterday I've BUILD up the command like this:

Code: [Select]SET /P VARIABLE=Please Key In DD No. and NAME:
ECHO "%VARIABLE%" > C:\HLA\PAGECOUNT\DDNO\DDNo.txt
PAUSE

REM --- Merge the DDNo.txt with Data file
COPY "C:\HLA\PAGECOUNT\DDNO\DDNo.txt"+"C:\HLA\PAGECOUNT\PDFPROCESS\NGC_DAILY.txt" "C:\HLA\PAGECOUNT\PDFPROCESS\SUBMERGING\NGC_DAILY.txt
I use MERGING command where, I create 1 file DDNo, then merge with the data text. Then its work.

How bout if u want to insert the text line in the middle of data text?

e-Bam
2886.

Solve : what are tokens??

Answer»

as said in subject what are tokensUsed with the For /F command, perhaps others. Tokens are segments of text that are separated by delimiters.

For example, if we had the following string of text: Dog,Cat,Mouse

Token 1 would be Dog
Token 2 would be Cat
Token 3 would be Mouse
If the delimiter was a comma(,)

I THINK that's an okay explanation?Quote from: gregory on January 11, 2009, 07:35:35 AM

I think that's an okay explanation?

I think it was a very good one.


whats the /f comand (im stupid)Quote from: steven32collins on January 14, 2009, 05:32:44 AM
whats the /f comand (im stupid)

and lazy.

Type for /? at the prompt.
what does "/?" do? (I'm STUPIDER)


This thread is just getting funny'er and funny'er!!

Not all, but many DOS commands have options, called switches. They "Switch" the WAY the program works.
Lets take a really simple one,,, DIR for Directory.
If you'll type "Dir /?" at a command prompt, it will give you a listing of all the switches that can be used with the Directory command.
/a show ALL files
/w show a WIDE directory
/p show the directory, one page at a time.

There are more, but that should give you an idea.

Type any DOS command and follow it with a space and a /? and it will respond by printing on the screen a listing of all the switches that apply to that command.

What " /f " means, depends on what command precedes it.
It doesn't necessarily MEAN the same thing for every command.

Everything ever printed about DOS, is available somewhere on the internet.
Search, search, search and then Read, Read, Read.

Some of us have been learning and re-learning this stuff for nearly thirty years.
You won't likely get it all over night.

A few years ago, many new DOS commands were added and some of the old ones were greatly enhanced. I'm "Old School" and still don't know all the new stuff. I've probably not learned any new DOS commands since the DOS 6.22 days.

My use of DOS today, is PRETTY much limited to simple Batch files and menus.

Cheers Mates! Keep up the good work!

The Shadow

aww, shadow, you came and spoiled all the fun

and isn't /a used for "attributes"? and then if you don't give it further qualification it will show all files?
2887.

Solve : Copy command - SUB tag??

Answer»

I'm using use the DOS 'copy' statement to link three parts of an xml file together. However the completed file has an additional 'SUB' tag at the end that I didn't expect:


http://www.somewhere">
1258,1101,1199,1507,813
1294,1118,1245,1580,820

SUB

(Note: the tag is usually white text in a little black box but it doesn't show up as text if you copy and paste it. Instead it just looks LIKE a thick black line or a little box > . I can see it SAYS SUB when I view the code with a proper text editor)

This SUB tag isn't in any of the three files to start with so it must be related to the copy command somehow. The annoying thing is that it stops the code working. If I delete it manually every thing then works fine. Any idea how to get RID of it automatically through the x command or merge the files WITHOUT it getting there in the first place? Try using the type command:

Code: [Select]type file1.xml > final.xml
type file2.xml >> final.xml
type file3.xml >> final.xmlwas the /b switch used with the copy command?rogerss, please give full details of how you are attempting to use the COPY command to link 3 xml files together.

I'm driving DOS through SAS using the x command. The SAS code is actually generating around 700 xml data files from the ORIGINAL data. The 'Append' solution using the type command instaed of Copying works absolutely perfectly. Thanks Dias. Star player!

2888.

Solve : help! my MS-DOS is not working! SHUTDOWN ERROR!?

Answer»

HELP!!

I'm new here.. whenever I try to run the MS-DOS there is an System error and my PC suddenly shuts down.. i can't read the error..

HELP PLS!! Are you running windows ( which version ) and the dos command shell, or native MS-DOS (which version )...Also what do you have for hardware specs.Windows XP SP2, i don't know the version of my MS-DOS

PIV 2.8ghz
512 ddr2 RAM
40GB HD
hmmm... is it necessary to put all?? help pls.. i think you are talking about CMD right ? If so, maybe it got infected by some virus ?Suggestion I have is to copy cmd.exe from another same Version Windows OS such as HOME or PRO from c:\windows\system32 to your system at the same location if it will allow it and not blat about resource in use.

If resource in use blat and NTFS last 2 options without full rebuild are:

1.) To boot from Live Linux CD like KNOPPIX and use Linux to fix Windows by being able to read/write exclusively to NTFS without file in use blat.

2.) Mount this hard drive as slave with another drive built as master. Boot off of master drive and then copy CMD.EXE to the slave at that drive letter:\windows\system32
((( Warning if this is viral there is a slight chance that it could spread by this method to your Master Drive )))

***If CMD.EXE was not copyright I would link it for you for the version you need, but due to the fact that it is protected by copyright you will need to grab a copy of it through other means, such as another computer you have or a friends system.



i nid to copy the cmd.exe only?? from other OS??yah! i think it was infected by some virus..In the virus section, there are PEOPLE who expertise in getting rid of files, do what they say, because they know more about that topic than 20 average people.

I've seen a topic for a REMOVED virus, the starter had to download over 10 programs just to see what virus they're infected with, then it was fairly simple to remove it...They know what programs work and what don't.and.. of it does turn out to be a corrupted EXE, they 'll guide through the use of SFC rather then a straight copy to prevent windows file protection from maybe restoring the corrupted file.Quote from: BC_Programmer on January 13, 2009, 06:18:15 PM

and.. of it does turn out to be a corrupted EXE, they 'll guide through the use of SFC rather then a straight copy to prevent windows file protection from maybe restoring the corrupted file.
Exactly.
2889.

Solve : How to send bat session to file??

Answer»

Please,
1) How to send bat session to log file, for review?
2) How do I keep 'CMD line PROMPT window' open. Usually as soon as *.bat is done the command window closes.
3) How can *.bat prompt user for input?
Thanks!
...VernonI'm going to answer #3 because it's pretty simple!

Set /p variable=

That will prompt a use to enter a variable, say they enter Bob.

Then you can do this.

Echo %variable%

And it will say Bob. If they enter Cheese, then it will say Cheese.

Understand?I will add to that. You can put anything where he put variable and %variable%, You should always put quotes AROUND "%variables%" incase the user puts something in that has spaces.Problem 2.

I answer this with a question, do you want to start the command prompt as if you type CMD in the run bar, or do you want to keep you batch file open?

Add all the codes to the END of your script.
For the first option:

Code: [SELECT]start cmd
For the latter option, there are 2 sub-options.

a. Keep it open untill the user presses a button:
Code: [Select]pause
b. Keep it open for a certain amount of time:
Code: [Select]ping localhost -n %seconds% -w 1000 > nulReplace %seconds% with however long in seconds you want.

There, I hope these solve your problem.

2890.

Solve : For token(I think)...?

Answer»

I'm very new to the whole FOR command, everything in the help just blows me away...

I'm trying to help my friend out by using DOS, and he has asked me to do something completely out of my knowlage.

With the FOR command, I've seen people set a variable as a section of text, using spaces or commas as delimiters(I hope I spelled that right)...What I need to do is:
1. Set a variable for each line of text. (Eg %L1% %L2% etc.)
2. If there are more than 30 lines, delete the FIRST line every time a new one is added (refresh every 2 seconds using ping and goto)


If possible, share a code, and help me understand how the code works, so in the future I won't have to ask again.

Thanks in advance!Well I will be the first to say something. But no way can I be last. I have used DOS for more years that I care to admit. I still do not understand the FOR command. It is really a LOOP structure, but called it FOR instead.

Anyway, here on this site there is a rather long explanation of how it works.

FOR %variable IN (set) DO command [command-parameters]

What you need to know is that variable is a single letter with the % in front of it. Inside a batch file it has TWO of them thar tingabops. Each time through the loop, the variable with have a another value. It is TAKE from the list of names found by the SET whatcha ma callit. Lets say you used joy*.HTM thne you would have a list of all HTM files thatstart with the letters J O Y in the current FOLDER. The DO command then does something for every files that was in the list. But not needing to modify each file in the list. Just do something. Like count, beep, waste time, show a message. Whatever.
Batch files are batch files. Which means the do not pay attention to external events,not can the over ride external things. The batch file has its own world. It can not modify a file somebody else is using. The batch file can modify things only when nobody else is doing something with them. This is one big DRAWBACK of using DOS in a GUI (Windows) system.
Now then, are you sure that the FOR command will do what you want?
I mean, is it more important to understand the FOR command, or is it m,ore important to do a certain thing that improves the computer presentation.
Quote from: Geek-9pm on January 13, 2009, 03:54:36 PM

I mean, is it more important to understand the FOR command, or is it m,ore important to do a certain thing that improves the computer presentation.


Priority:
1. Getting the job done
2. Understanding it more, so I won't be so dependant.

I promised my friend that I would do it, but as I said in the first post, I just don't know.
2891.

Solve : Token replacement/removal within delimited string?

Answer»

Is token replacement/removal within a delimited string possible within a batch file?

If I had a comma delimited string: a,b,c,D,e,f,g

Could I tell a batch file to replace, for example, D with h, leaving the REST of the string alone?

ThanksI suppose no one here has ever had a need for this. It is perfectly possible. You can easily use FOR to read the comma delimited string, and then write out the tokens again, substituting another substring for the 4th token.What I was hoping to avoid was having to deconstruct the string and rebuild it every time. The thought was maybe someone knew of a logical process or some command which could be used to rewrite a specific token in the string, sort of the opposite of what the For /F would do when it reads a specific token. Looking back on my initial post, I was vague, and I apologize. I'm just going to have to write a deconstruct/reconstruct process, which will work, albeit lengthy. Suppose I was just being lazy, hoping for an easier way.

Thanks again.Quote from: gregory on January 13, 2009, 02:44:55 AM

What I was hoping to avoid was having to deconstruct the string and rebuild it every time.

Why? This is the kind of task that computers are good at.
Quote from: Dias de verano on January 13, 2009, 02:50:43 AM

Why? This is the kind of task that computers are good at.


Because I have to write the code for it to work. half of everything is work.Quote from: BC_Programmer on January 13, 2009, 03:10:53 AM
half of everything is work.

What's the other half?Quote from: gregory on January 13, 2009, 03:13:43 AM
Quote from: BC_Programmer on January 13, 2009, 03:10:53 AM
half of everything is work.

What's the other half?

Thinking
I would have been so tempted to say "fate".I was thinking of the definition of genius, I think, 1% inspiration, 99% perspiration.

why not use set ? easier i think Quote from: devcom on January 13, 2009, 12:51:05 PM
why not use set ? easier i think

read his question again. the item to be replaced is neither at an ABSOLUTE position nor a KNOWN size, so for would be needed.


Quote from: devcom on January 13, 2009, 12:51:05 PM
why not use set ? easier i think

Give US some example code, then...

Here's the original question, to refresh your memory. Read it carefully.

Quote
Is token replacement/removal within a delimited string possible within a batch file?

If I had a comma delimited string: a,b,c,D,e,f,g

Could I tell a batch file to replace, for example, D with h, leaving the rest of the string alone?
2892.

Solve : Escape Key symbol?

Answer»

Would there be a symbol for the escape KEY. I'm trying to make a batch file, and if you press escape it goes back to the main menu.Use alt-27. Note: the 27 must be typed from the numeric keypad. Every application seems to see escape as a different symbol. One EDITOR I have sees it as a question mark, notepad sees it as a left pointing arrow, and the command line sees it as ^[

Why make things difficult? Why not just use a alphanumeric key not already being used in your application?





But it's not like the PERSONS using the program in notepad . So, what's the symbol in batch files. Or would it be the same as the command line.Quote from: BatchFileCommand on January 12, 2009, 04:32:04 PM

But it's not like the persons using the program in notepad . So, what's the symbol in batch files. Or would it be the same as the command line.

it won't matter what the symbol is. Most applications, when seeing the escape, with translate it into a upwards arrow, but most translate it into the square "unknown glyph" box, but guess what... it's code changes as well.

you would need to edit your batch file via COPY CON or the DOS edit program in order to get the proper codes in. OR- use a real text editor, like EmEditor, PFE, Editpad, UltraEdit...Quote
use a real text editor

I use a real text editor for programming languages. Notepad ++ is an awesome program.ok, you should be able to insert a symbol somehow. the ASCII code, if memory serves, is 26. Could be wrong, though.Quote from: BC_Programmer on January 12, 2009, 07:48:15 PM
ok, you should be able to insert a symbol somehow. the ASCII code, if memory serves, is 26. Could be wrong, though.

You are. Escape is 27.
Tada! It worked. Problem solved .Quote from: Dias de verano on January 13, 2009, 06:08:40 AM
Quote from: BC_Programmer on January 12, 2009, 07:48:15 PM
ok, you should be able to insert a symbol somehow. the ASCII code, if memory serves, is 26. Could be wrong, though.

You are. Escape is 27.


Awww, So close too! Good thing I added the disclaimer Quote from: BC_Programmer on January 13, 2009, 12:44:21 PM
Quote from: Dias de verano on January 13, 2009, 06:08:40 AM
Quote from: BC_Programmer on January 12, 2009, 07:48:15 PM
ok, you should be able to insert a symbol somehow. the ASCII code, if memory serves, is 26. Could be wrong, though.

You are. Escape is 27.


Awww, So close too! Good thing I added the disclaimer

Time was, I knew them all by heart... all way from 0, NUL to 128, these DAYS if I ever need an ASCII code, I just look 'em up. My favourite editor, UltraEdit32, has an ASCII chart in the View menu

2893.

Solve : How to Make the Matrix?

Answer»

This is how to make the Matrix in a batch file-

Code: [Select]@echo off
cls
title Matrix
color 2
:start
echo %random% %random% %random% %random% %random% %random% %random% %random%
goto start
%random% means to type %random% not random letters
Save this as (to whatever folder) Matrix.bat


I am not responsibal if you mess up and ruin your computerWhat does it do? it looks like the matrix
ill send an attachment with it
looks like a bunch of numbers to me. Although I suppose, since it is a 2-dimensional array, one could call it a matrix. but it is no more a matrix then those used in 3d projection transformations.Here it is-

[attachment deleted by admin]Quote from: BC_Programmer

looks like a bunch of numbers to me. Although I suppose, since it is a 2-dimensional array, one could call it a matrix. but it is no more a matrix then those used in 3d projection transformations.

WELL...I am not impressed by this. Where did I see this before?Quote from: kpac on December 23, 2008, 03:42:50 PM
Where did I see this before?

perhaps here?

Quote from: macdad- on December 23, 2008, 04:58:13 PM
Quote from: kpac on December 23, 2008, 03:42:50 PM
Where did I see this before?

perhaps here?




Nope that version is crapwhat the crap!!!!!!!!!!!!!!!!!!!!!! you stole the signature bar i was using!!!

and thanks for your comment. Quote from: DFND-jimjim1 on December 23, 2008, 05:28:45 PM
Quote from: macdad- on December 23, 2008, 04:58:13 PM
Quote from: kpac on December 23, 2008, 03:42:50 PM
Where did I see this before?

perhaps here?




Nope that version is crap

excepting of course the fact it does the EXACT same THING yours does, with a more appropriate color, as well as not having spaces.

before declaring somebody elses work as crap perhaps you should reevaluate just how similar it is to your own.

Quote from: macdad- on December 23, 2008, 05:35:14 PM
what the crap!!!!!!!!!!!!!!!!!!!!!! you stole the signature bar i was using!!!

and thanks for your comment.

it's green, he must have made it from scratch, that is SO NOT just a cosmetic change.

And he DECIDED that he's special since one of his threads got enough replies to become a "hot" topic. Of course the issue would have been resolved by simply rebooting the router in the FIRST place, I'm sure, and the constant refusal to enter any configuration pages MAKES any assistance moot.Thanks....*glar*Quote from: DFND-jimjim1 on December 23, 2008, 05:45:17 PM
Thanks....*glar* *glare*

now explain yourself! Why did you take macdad's sig bar. So glad I removed mine...
2894.

Solve : A reading batch file.?

Answer»

Hello all,

I'm making a batch file that should help me to make a Perl script, I use the Perl script to scan something, to do that I need a big WORDLIST, I have got one now but I should get it to be useable for the Perlscript. But the point is that in order to turn all the words into my Perl script, I'll have to add this in front of each word:$a4=" and this at the end of each word: "; .

Code: [Select]file1
I
am
on
computer
hope
forumrun batch file, file2.txt is created
Code: [Select]file2
$a1="I";
$a2="am";
$a3="om";
$a4="computer";
$a5="hope";
$a6="forum";
So that if you run the batch file, and you have file1 in the same directory as the batch file, file 2 will be made but than with the stuff I need around it. I'm not so good at batches so I'll be pleased if anybody can help me with this.

Thanks in advance.I have done something like this before with C++ Console App to condition data to be WRITTEN back to another file, but not sure how you will be able to do this in batch...Maybe someone here can show us both. The incrementing identifier of $ax="data"; array with incrementing (x) and dropping the data read for each line into this format might be too much for a batch. I know that C++ and other programming languages can strip data line by line and insert the leading $ax=" (the data to be inserted), and trailing ";

In C++ or another language you would want to also write your incrementation value ( x ) to another file in order for this counter++ to pick up at the next available increment if something that will be run again and again as more words are added to this and it builds at the EOF.Code: [Select]@echo off
setlocal enabledelayedexpansion
if exist file2 del file2
set /a counter=1
for /F "delims==" %%L in (file1) do (
echo $a!counter!="%%L";>>file2
set /a counter=!counter!+1
)

2895.

Solve : Batch script to automatically bypass username in firefox??

Answer»

At work I need to enter in my username and password just to open up firefox. I would like to write a batch FILE that can automatically ENTERS in my username and password when I open up firefox.

Any comments or suggestions would be greatly appreciated.

thank you.A batch wont do...you need a GUI Macro that will drop and execute the CREDENTIAL process through the credential user interface.

I use a macro recorder called JitBit to do TRICKS like this in a GUI environment.

http://www.jitbit.com/macrorecorder.aspxBut it's possible to open a macro in a batch file.

2896.

Solve : Incrementing a for loop?

Answer»

Is it POSSIBLE to increment a for loop counter?

I am aware of for /l that offers a start and end value with an incremental value, but this option does not allow you to parse through a file. i'm LOOKING to traverse the contents of a file and skip certain lines based on a condition. for example:

for /f %%x in (somefile) do (
if %%x==somevalue (skip ITERATION/advance counter) else (some command)
)

from what i have been able to research the only value i can get from %%x is the contents its gathered from the file iteration, not an actual int i can increment.

thanks in advancedexample

Code: [Select]setlocal enabledelayedexpansion
set /a counter=1
for /f %%x in (somefile) do (
if !counter! EQU somevalue (do something) else (do ANOTHER thing)
set /a counter=!counter!+1
)

2897.

Solve : Duplicate LPT to COM?

Answer»

Does anyone know about the DOS program which can duplicate LPT output to COM?
It should send everything sent to LPT also to COM port.
I need duplication, not redirection!
Lets say that I have two printers attached: one parallel and one serial, and
that I want every print output from any application to be PRINTED to both
printers simultaneously.
OS is MSDOS 6.22 (no Windows around).The first problem I see is if the printers are different.
Years ago I used to do something like that. But noways the printers are much more complicated.
Here is the standard way to do that in the old DOS,
but not in the Windows.
You tell all program to send out put to a file. Then you do a batch program to copy it to both printers
It might help if you could explain why you need to do this. Why not just make two copies with one printer? Is this a commercial application?
This is the real situation:
There is a POS cash register with parallel POS printer. It have to be connected to video surveillance POS capture box which can be connected only to serial printers. POS capture box captures printer output (character print, EPSON format) and sends it to video surveillance application.
There are two solutions:
- change parallel printer with serial, redirect LPT to COM, and throw away parallel printer - EXPENSIVE !
- find a solution to duplicate all data sent to LPT port to COM and connect POS capture box to serial port.
If there is a solution in DOS please send me exact syntaxWhat about using MODE to redirect LPT2 to COM1 and then print to LPT1 and LPT2

Such as:

MODE LPT2:=COM1:

Then use a print from file that Geek-9pm suggested in 2 instructions one for LPT1 and one for LPT2, and LPT2 will pass the print task to COM1 serial printer.

Drivers may still be required, but this should get the data at least from that file to the Com1 port to print maybe.There is a way to hack this. You write a TSR that watches what ever goes to one device and then re sends it to the other device. If you have 100 POS systems to modify, you can PAY a programmer to do the code for you. But if it is a one time shot, just buy an old serial printer.
Quote from: DaveLembke on January 12, 2009, 10:09:02 AM

What about using MODE to redirect LPT2 to COM1 and then print to LPT1 and LPT2

I was going to suggest that myself, but they want duplication, not redirection.

As geek said, for your exact situation without buying additional hardware, a TSR would probably be needed. It might even be true that one has already been written.

but here's the thing, one is SERIAL, the other is PARALLEL. how do you duplicate a parallel output to a serial output properly? It's messy, at the very least; one would literally have to learn the SPECIFICS of how the capture box takes input. If it is simply text, it probably can be sent the exact same thing as the Parallel port is told to send. if it needs the exact same stream, then things could get messy.


Another solution is, I believe they have parallel to Serial adapters.If you send the print to a File first... then run the print instruction to LPT1 and LPT2, that will duplicate the output of the initial print due to LPT2 redirect to Com1.

If they are unable to print to a file, then yes this wouldnt work for replication, but if they can print to file and then call that file to print to both LPT1 and LPT2 ( redirected port ) then it should work.

And if there is any graphics ( logos etc ), yes the setup would likely puke as for this would only work best if all ascii due to printing to a file would likely create a file that cant be printed or it would strip the graphic that is unable to be interpreted.
I don't think DOS has a "print to file" feature built in.You are correct, DOS PRINT has no switches available to print to file but... there is a TSR available, although I havent used it to RATE how well it works at http://www.computing.net/answers/dos/dos-print-to-file/9514.html

This should allow printing to file....Other issue I just realized with the duplicate print is that its great and all about setting up LPT1 and LPT2 to print through MODE redirection of LPT2 to COM1, printing from file, but this process is not automated. Problem being that a print task would go out to file...then nothing would happen. Some service would have to know that the file has changed etc or been created and then print at both devices at both ports.

... Cant believe I overlooked that detail that is an important detail to make this work...

Our setup to print at 2 printers for our Food Store uses a VB Script and Windows, which have so much more potential than just DOS.
2898.

Solve : can i start a new windows os in comand promt??

Answer»

just like the topic but its the same xp im using

if can tell howI do this by using batch scripts when swapping between OS's or simply rebooting into Safe MODE or the RECOVERY Console or the same OS with DIFFERENT options:

1. Rewrite boot.ini to load a different OS by default (or the same OS with different options)
2. USE the Shutdown command with the -R option
3. Again rewrite boot.ini to return to the original OS/settings

Care is required.

Edit: I just realised that you might mean how can you restart Win XP from the command line, use the shutdown -r command at the Command Prompt.





2899.

Solve : if statement in a for statement?

Answer»

Is is possible to put an if statement in a for statement? Here is the BATCH file...

@echo on

SET file1=test1.txt
SET file2=test2.txt
SET source=U:\gendl
SET DEST=/home/asolutions/
SET logfile="U:\BatchFiles\IPSwitch Log Files\test.log"

:phase1
cd /d %source%
for %%f in (%file1% %file2%) do if not exist %source%\%%f goto 20
"C:\Program Files\Ipswitch\WS_FTP Professional\wsftppro.exe" -s local:%source%\%%f -d interfaces!kidneykonditioning:%dest% -quiet

:20
@ECHO ON
DATE /t >> %logfile%
TIME /t >> %logfile%
echo "No %%f to send!!!" >> %logfile%
ECHO =================================================== >> %logfile%
goto end

:end

exit
Quote

Is is possible to put an if statement in a for statement?

Sure is!

One problem I see is that the :20 construct either gets executed directly from a goto or ELSE the logic falls into the construct after wsftppro.exe executes.

The other problem is that %%f variable is referenced outside the for loop.

Code: [Select]for %%f in (%file1% %file2%) do if not exist %source%\%%f goto 20
"C:\Program Files\Ipswitch\WS_FTP Professional\wsftppro.exe" -s local:%source%\%%f -d interfaces!kidneykonditioning:%dest% -quietd

If both the if statement and the wsftppro.exe program are part of the for loop, you'll need to use parenthesis:

Code: [Select]for %%f in (%file1% %file2%) do (
if not exist %source%\%%f goto 20
"C:\Program Files\Ipswitch\WS_FTP Professional\wsftppro.exe" -s local:%source%\%%f -d interfaces!kidneykonditioning:%dest% -quietd
)

You have access to goto :eof which I think should be the last statement in the phase1 construct. Of course you may want to issue a message that all is well. I've modified it as per your suggestion but doesn't seem to get past the first file. What am I missing??? Thanks!!!

@echo on

SET file1=test1.txt
SET file2=test2.txt
SET source=U:\gendl
SET dest=/home/asolutions/
SET logfile="U:\BatchFiles\IPSwitch Log Files\test.log"

:phase1
cd /d %source%
for %%f in (%file1% %file2%) do (
if not exist %source%\%%f goto 20
"C:\Program Files\Ipswitch\WS_FTP Professional\wsftppro.exe" -s local:%source%\%%f -d interfaces!kidneykonditioning:%dest% -quiet
)
goto end

:20
@ECHO ON
DATE /t >> %logfile%
TIME /t >> %logfile%
echo "No file to send!!!" >> %logfile%
ECHO =================================================== >> %logfile%

:end
Quote
I've modified it as per your suggestion but doesn't seem to get past the first file. What am I missing???

Probably nothing. Did you try to debug the code? I suspect this line is the problem:

Code: [Select]if not exist %source%\%%f goto 20

If expanded, it should look like this: if not exist U:\gendl\test1.txt
Does the file exist? If not, the logic goes to :20, never to return to check for file2.txt

Consider rewriting the for loop to use an either/or approach.

if not exist filename (call :20) else (execute wsftppro.exe)

I'll leave it to you to fill in the paths and parameters.


That's correct, if expanded that's how it should look. How do I make it return to check for additional files (i.e. file2, file3, etc.) logging each entry for "No file to send" if file does not exist. If files do exist to run the wsftp program?

Would if be better to just have multiple if STATEMENTS & not use the for loop?

Ex.

if exist %file1% do ("C:\Program Files\Ipswitch\WS_FTP Professional\wsftppro.exe" -s local:%source%\%%f -d interfaces!kidneykonditioning:%dest% -quiet) else (
@ECHO ON
DATE /t >> %logfile%
TIME /t >> %logfile%
echo "No %file1% to send!!!" >> %logfile%
ECHO =================================================== >> %logfile%
)

if exist %file2% do ("C:\Program Files\Ipswitch\WS_FTP Professional\wsftppro.exe" -s local:%source%\%%f -d interfaces!kidneykonditioning:%dest% -quiet) else (
@ECHO ON
DATE /t >> %logfile%
TIME /t >> %logfile%
echo "No %file2% to send!!!" >> %logfile%
ECHO =================================================== >> %logfile%
)

if exist %file3% do ("C:\Program Files\Ipswitch\WS_FTP Professional\wsftppro.exe" -s local:%source%\%%f -d interfaces!kidneykonditioning:%dest% -quiet) else (
@ECHO ON
DATE /t >> %logfile%
TIME /t >> %logfile%
echo "No %file3% to send!!!" >> %logfile%
ECHO =================================================== >> %logfile%
)
Quote
Would if be better to just have multiple if statements & not use the for loop?

You decide. I think this snippet is what you're trying to do:

Code: [Select]@echo on

SET file1=test1.txt
SET file2=test2.txt
SET source=U:\gendl
SET dest=/home/asolutions/
SET logfile="U:\BatchFiles\IPSwitch Log Files\test.log"

:phase1
cd /d %source%
for %%f in (%file1% %file2%) do (
if not exist %source%\%%f (call :20) else (
"C:\Program Files\Ipswitch\WS_FTP Professional\wsftppro.exe" -s local:%source%\%%f -d interfaces!kidneykonditioning:%dest% -quiet)
)
goto :eof

:20
@ECHO ON
DATE /t >> %logfile%
TIME /t >> %logfile%
echo "No %%f to send!!!" >> %logfile%
ECHO =================================================== >> %logfile%

Quote
How do I make it return to check for additional files

Use the call statement instead of goto. Try directly NAMING the files in the for statement. This will reduce the number of changes for maintenance:

Not this:
Code: [Select]SET file1=test1.txt
SET file2=test2.txt
for %%f in (%file1% %file2%) do (

Try this instead:
Code: [Select]for %%f in (test1.txt test2.txt) do (

You can easily add file names in the for list without having to define new variables. Variables are useful, but unless the values are generated at run time, there is little reason not to hardcode them.

Good luck. Thank you for all your guidance. I finally got it to work.
2900.

Solve : Free Dos or Dos 6.22?

Answer»

Which one is easier to network? well wat version of Dos are you refrering to besides 6.22?
Free DOS...


I really couldn't tell you which one is easier to network; it heavily depends on the network CARD being used.

If the network card doesn't have DOS based drivers available, neither FreeDOS or DOS 6.22 will be ABLE to use it.What are some good network cards that you used successfully?
The only one I could get to work is a Microdyne NE100 and guess what, cant find one anywhere.
What to do What to do what too do???well, recently, I purchased a D-Link DFE530-TX (wow, that is so sad that I remember the model #...) and I recall the CD included drivers for DOS and windows 3.1.Only advantage I can see to FreeDOS over MSDOS is that FreeDOS is FREE, while you have to worry about licensing ( authentic copies of the operating system ) for MSDOS.

I have used FreeDOS before and found some issues however with Intel Pro 10 ISA drivers on a Pentium 75 system, yet I had no problems with my Windows 95 box on a Pentium MMX 133 running DOS 7, ...this was when playing with FreeDOS back in 2002 in college and maybe FreeDOS has had a few updates since to better support drivers written for MSDOS execution. If I remember right, the issues I had was that it was failing to mount the network adapter drivers under FreeDOS, but worked perfectly fine in MSDOS.

You can always just give it a try and see if it NETWORKS and if so you are good to go. But just like BC_Programmer stated it all depends on the network card used and how the driver interacts with the DOS kernel of FreeDOS instead of command.com of MSDOS.

Some other issues with FreeDOS were ABNORMAL program execution of some DOS games that worked fine in MSDOS...some would BLACK screen, others would start to play and then act up, and one came up with a memory stack overflow issue.