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.

4601.

Solve : Batch - append text to output of another command?

Answer» HELLO,

I am using this;
Code: [Select]:: List all the .doc files in a directory
DIR /b /o "c:\some_directory\*.doc">>filenames.txt
Which generates a nice list LIKE this;
file1.doc
another file.doc
third file.doc


This is lovely and has made me happy, but the simple question is how do I append a 'tab' character and some text to this nice list to give me the FOLLOWING output in my filenames.txt file;
file1.doc tab text_in_here
another file.doc tab text_in_here
third file.doc tab text_in_here


Its driving me mad!!

Many thanks for any help,

Cheers,

Stageyou can use for loop together with your dir command.
as an alternative solution, you can use this vbscript
Code: [Select]Set objFS = CreateObject("Scripting.FileSystemObject")
strFolder = "c:\some_directory"
Set objFolder = objFS.GetFolder(strFolder)
For Each strFile In objFolder.Files
If objFS.GetExtensionName(strFile) ="doc" Then
WScript.Echo strFile.Name & vbTab & "some words"
End If
Next

save as myscript.vbs and on command line
Code: [Select]C:\test> cscript /nologo myscript.vbs > newfile
Quote from: stage on May 10, 2009, 03:52:34 AM
Hello,

I am using this;
Code: [Select]:: List all the .doc files in a directory
DIR /b /o "c:\some_directory\*.doc">>filenames.txt
Which generates a nice list like this;
file1.doc
another file.doc
third file.doc


This is lovely and has made me happy, but the simple question is how do I append a 'tab' character and some text to this nice list to give me the following output in my filenames.txt file;
file1.doc tab text_in_here
another file.doc tab text_in_here
third file.doc tab text_in_here


Its driving me mad!!

Many thanks for any help,

Cheers,

Stage
As gh0st said, you COULD use a for loop, as demonstrated here:

Code: [Select]for /f "delims= " %%A in ('DIR /b /o c:\some_directory\*.doc') do echo %%A text_here>>filenames.txt
That should work as LONG as the filenames or the path don't contain spaces.Hey there,

Perfect. Thanks so much. I've learnt alot just in this one exercise.
Helpmeh answer does work ok with spaces in filenames but not spaces in directories. This is not a problem.

Cheers,


StageQuote from: stage on May 10, 2009, 12:53:35 PM
Hey there,

Perfect. Thanks so much. I've learnt alot just in this one exercise.
Helpmeh answer does work ok with spaces in filenames but not spaces in directories. This is not a problem.

Cheers,


Stage
Ok, I wasn't sure if it would work properly with spaces. I did it all free-thought (without debugging at all).
4602.

Solve : defrag?

Answer»

how do i make a batch file that will open defrag, start it, and shutdown after it Quote

try contacting customer support.

The above is your response to a general question in another THREAD.

Now that you've asked your general question here, I wonder if you have tried to write any of the code yourself? Quote from: computerperson#1 on May 21, 2009, 03:18:13 PM
how do i make a batch file that will open defrag, start it, and shutdown after it

You open a text editor, type the lines of code, then save the file.
what are the lines of code Why to people think Command Prompt can do all these magical things?Quote from: computerperson#1 on May 22, 2009, 05:29:32 AM
what are the lines of code

You need to "learn" how to write them. That is your task.
I cant say the only reason why I attempt to do it is so that I can make things easier. IE if I am working on another machine and want a sepfic series of things to happen and dont want to sit in that room and work on whatever else.Okay......

Anyways, if you're looking for a way to start programs automatically at different times, I suggest a program called Kana Reminder.
http://www.snapfiles.com/reviews/Kana_Reminder/kanareminder.html Learn it like I had too, call ms paint and go from there and ask questions after learning dos.Quote from: squall_01 on May 22, 2009, 03:52:43 PM
Learn it like I had too, call ms paint and go from there and ask questions after learning dos.

Junis, is that you?
so defrag. just defrag? ok
Code: [SELECT]L:\>defrag /?
Usage:
defrag <volume> [-a] [-f] [-v] [-?]
volume drive letter or mount point (d: or d:\vol\mountpoint)
-a Analyze only
-f Force DEFRAGMENTATION even if free space is low
-v Verbose output
-? Display this help text

shutdown:
Code: [Select]L:\>shutdown /?
Usage: shutdown [-i | -l | -s | -r | -a] [-f] [-m \\computername] [-t xx] [-c "comment"] [-d up:xx:yy]

No args Display this message (same as -?)
-i Display GUI interface, must be the first OPTION
-l Log off (cannot be used with -m option)
-s Shutdown the computer
-r Shutdown and restart the computer
-a ABORT a system shutdown
-m \\computername Remote computer to shutdown/restart/abort
-t xx Set timeout for shutdown to xx seconds
-c "comment" Shutdown comment (maximum of 127 characters)
-f Forces running applications to close without warning
-d [u][p]:xx:yy The reason code for the shutdown
u is the user code
p is a planned shutdown code
xx is the major reason code (positive integer less than 256)
yy is the minor reason code (positive integer less than 65536)
Finished Product:
Code: [Select]Defrag %homedrive%
shutdown -s -f -t 00
4603.

Solve : get command within ftp?

Answer»

Hi,

After I have used the get command WITHIN ftp command of ms-dos to retrieve files from my ftp server site, and then try to open the files in my local directory it just gives the message that "no preview available".

I can view these jpeg files when looking at them within the ftp server site so I don't know why I can't do the same when I have puilled them into my local directory using ms-dos ftp.

Any ideas why this would be?. Probably is nothing to do with getting the files via ms-dos and is some other setting.

Thanks,
Michael Quote from: MOC76 on May 09, 2009, 04:56:19 PM

Hi,

After I have used the get command within ftp command of ms-dos to retrieve files from my ftp server site, and then try to open the files in my local directory it just gives the message that "no preview available".

I can view these jpeg files when looking at them within the ftp server site so I don't know why I can't do the same when I have puilled them into my local directory using ms-dos ftp.

Any ideas why this would be?. Probably is nothing to do with getting the files via ms-dos and is some other setting.

Thanks,
Michael
Are you sure the pictures are formatted correctly?Yes. Am getting a 550 error in MS-DOS. Not sure what that is TELLING me though.Quote from: MOC76 on May 09, 2009, 05:31:28 PM
Yes. Am getting a 550 error in MS-DOS. Not sure what that is telling me though.
Does it specifically say error? Because when I used ftp, it would look something LIKE this:


000>Text
909>Different Text

and so on and so fourth...when you want to get file TYPES like jpg, set the transfer to binary formatSo before transfering, add "binary" before get.Thanks. I have tried that but no joy.

I enter the get command for a .jpg file and receive the following back (see the attached).

File is sent to my local directory but is empty (0 KB).

I have read that this "550 No such file or directory" message is to do with permissions. However I can't find anything which explains what is required to rectify this.

Appreciate any help.



[attachment deleted by admin]Quote from: MOC76 on May 10, 2009, 06:05:46 AM
Thanks. I have tried that but no joy.

I enter the get command for a .jpg file and receive the following back (see the attached).

File is sent to my local directory but is empty (0 KB).

I have read that this "550 No such file or directory" message is to do with permissions. However I can't find anything which explains what is required to rectify this.

Appreciate any help.


In your FTP Browser, right click on the images, and check that they are not hidden, read only or archived.
4604.

Solve : how to terminal the auto loop of bat?

Answer»

i make a BATCH FILE, this is ENTIRE code:

e:
Start cd E:\Program Files\CCD\HAPPY\libraries


xcopy "E:\My_Documents\Visual_Studio_2008\Projects\Profit_come_with_trust\Debug" /Y

but when i run this .bat file, it auto re-run

what is the code that only run for 1 time?

thanksQuote from: chiwing on May 23, 2009, 05:26:16 AM

i make a batch file, this is entire code:

e:
Start cd E:\Program Files\CCD\HAPPY\libraries


xcopy "E:\My_Documents\Visual_Studio_2008\Projects\Profit_come_with_trust\Debug" /Y

but when i run this .bat file, it auto re-run

what is the code that only run for 1 time?

thanks
It shouldn't auto-rerun, but just to be sure, add EXIT to the very end of it.
4605.

Solve : Create hidden folder??

Answer»

I know how to create a normal folder. What I need to do is create a folder from a batch file that is already hidden so I do not need to go in and manually MAKE the folder hidden.

Help?ATTRIB /?
Code: [Select]attrib +h "DRIVE:\ folder\folder 2\file.extension"For what purpose?Xenfire, you know why clear wasn't working??? Because it was hidden (for some reason I got an error)...so I just did
attrib -h file
clearing command
attrib +h file


and that's how I got /clear to work...Thank you Evan. works fine.Quote from: Xenfire on May 09, 2009, 03:58:06 PM

Thank you Evan. works fine.
So...ban (which I will probably implement after putting your name in again...) will work like this:

Code: [Select]if /i "%msg%"=="/ban" (
echo Ban who?
set /p ban=Username^:
echo. > "Hiddenpath\%ban%"
attrib +h "Hiddenpath\%ban%"
echo %ban% has been banned. > %serv%
goto modview

That will ban someone...then this will check to see if they are banned whenever they send a message.

Code: [Select]if exist "Hiddenpath\%usr" (
:loopban
cls
echo You have been banned. The ban will be reviewed by the admin.
pause > nul
goto loopban
It will go between :msgloop and set /p msg=Message^: in chatter...and won't go after :modview, so the mods can't get banned...good idea!My checker just goes when they try to log in to any COMPONENT of the program.Quote from: Xenfire on May 09, 2009, 04:10:09 PM
My checker just goes when they try to log in to any component of the program.
What do you mean it just goes away? It just EXITS? Did you do that on purpose? (if the second question was yes)I didn't say "goes away" I just said "goes"
as in runs.

double check the contents of the post before you reply silly.Quote from: Xenfire on May 10, 2009, 08:09:27 AM
I didn't say "goes away" I just said "goes"
as in runs.

double check the contents of the post before you reply silly.
Well it obviously runs when they first run the program, although then you'd have to PUT it in more than once.
4606.

Solve : Shortcut Variables?

Answer»

I don't know what they're called, so I'm calling them shortcut variables. I'm wondering about the variables such as %computername%, what all variables are there? I can't find anything about them.They're Environment Variables.

http://vlaurie.com/computers2/Articles/environment.htmOh, Environment Tables. Thank you.Anytime. Quote from: Sky Ninja on May 09, 2009, 11:47:06 PM

Oh, Environment Tables. Thank you.

Environment variables.
Type SET at the COMMAND prompt to see what they all are on your computer.List:

%CD% - CURRENT Directory
%DATE%, %TIME%, %NUMBER_OF_PROCESSORS% - Self Explanatory
%OS% - Doesn't exactly tell you the OS, just the family(Like WIN2K, XP are shown as Windows_NT in this variable)
4607.

Solve : is this bat right?

Answer»

when i open it and press "y" it says y was unexpted at this time what is wrong.

@ECHO off
set /p c=do you WANT to move on[y/n]?
if /I "%c%" "y" goto move
if /I "%c%" "n" exit
:move
set /p c=do you REALLY want to continue[y/n]?
if /I "%c%" "y" goto bob
if /i "%c%" "n" exit
:bob
set /p c=are you positive[y/n]?
if /I "%c%" "y" goto positive
if /I "%c%" "n" goto END
:positive
call bob.bat
cls
Missing either == or equ between strings in the If command lines. Enter IF/? at the command PROMPT to study the command.

Batch label END not defined. Command goto end fails. Enter GOTO/? at the command prompt to study the command.This should work:

Code: [Select]@echo off
set /p c=do you want to move on[y/n]?
if /I %c%==y goto move
if /I %c%==n exit
:move
set /p c=do you really want to continue[y/n]?
if /I %c%==y goto bob
if /i %c%==n exit
:bob
set /p c=are you positive[y/n]?
if /I %c%==y goto positive
if /I %c%==n goto end
:positive
cls
call bob.bat
:end
::(Your code for this part goes here)

4608.

Solve : User Input Time Limit?

Answer» QUOTE from: macdad- on May 10, 2009, 03:02:53 PM
What SERVICE pack do you have?

I have SP3
SP2...I can't get SP3Interesting...wonder why they cut out CHOICE in SP3....

Oh well.Quote from: macdad- on May 10, 2009, 03:14:18 PM
Interesting...wonder why they cut out Choice in SP3....

Oh well.
It's not in SP2.
4609.

Solve : Simple way to extract text from a group of files??

Answer»

Hello all!

I'm new here so please be patient!

I have a rather large LIST of text files. What I'd like to do is find a particular STRING of text inside each file and if FOUND - extract it to another file. That other file will contain all the strings of text from each file in the large list, each string will be on a new line.

Anyone willing to help?if your requirement is that SIMPLE, you can use findstr . type findstr /?

findstr /n "mystring" *.TXT

4610.

Solve : DOS Sleep.com command. Where is it??

Answer» DOS Sleep.com command. Where is it?
I thought there was a more or less standard Sleep.com program for DOS.
I guess not.
For what it is worth, here is a sleep command from my old 1098 collections of stuff I did in ASM.
http://geek9pm.com/asm/
No Mallware, no virus. Just plain old 16 bit DOS programs. The only on of INTEREST in SLEEP.COM and SLEEP.ASM.
SORRY, can not recall how it works. That was years ago.
4611.

Solve : Command won't work from notepad .bat file?

Answer»

Hello, first post.

I have a very intriguing problem and I'm hoping that it's not just a very very stupid mistake.

I opened notepad typed in my commands and then clicked Save As. I changed the "Save As Type" to All files and then saved the file as mybat.bat

Here is the CODE I have in my newly created .bat file:
D:
cd Video
FOR /F "tokens=1* skip=1 delims=\" %i IN (txt_files.txt) DO @echo %i %j >> txt1_files.txt
pause

lines 1 and 2 navigate to the correct directory
line 3 reads a .txt file, grabs a delimited string and puts it into the new .txt file

When I run mybat.bat file the window comes up for a fraction of a second and disappears. The new txt1_files.txt file is never created and the "pause" statement is never reached. When I open a cmd window and type the commands in (in the same order and typed exactly the same) it works, flawlessly.

So, the question is, am I doing something horribly/stupidly wrong, or can the FOR statement not be used in .bat files created from notepad, or am I missing something else all together.

I think I've included all the information needed, if I haven't I apologize, I've been struggling with this for quite some time.

Thanks in advance!Quote

When I run mybat.bat file the window comes up for a fraction of a second and disappears.

This suggests to me that you are running it from Windows Explorer by double clicking. When trouble shooting a batch file that behaves in this way, a good idea is to run it by OPENING a command prompt, changing the current drive and directory as appropriate, and finally typing the batch file name at the prompt. That way if the batch crashes out you just get the prompt back and you can see any error messages. These may give you (and us) an idea of what is happening.

In this case, it won't be necessary, as the problem is obvious. Where you use one percent sign in a FOR variable at the prompt, you use TWO of them in a batch file. Thus %i and %j NEED to become %%i and %%j.


Quote
I've been struggling with this for quite some time.

As with most commands, help is available by typing the command at the prompt with the /? switch.

Code: [Select]C:\>for /?
Runs a specified command for each file in a set of files.

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

%variable Specifies a single letter replaceable parameter.
(set) Specifies a set of one or more files. Wildcards may be used.
command Specifies the command to carry out for each file.
command-parameters
Specifies parameters or switches for the specified command.

To use the FOR command in a batch program, specify %%variable instead
of %variable. Variable names are case sensitive, so %i is different
from %I.
(That is just the beginning of the very detailed FOR help, which runs to about 4 screens)

Perhaps you should get used to using the prompt more.

Thank you so MUCH. This fixed the problem. I was beating myself up over this error. Is there anywhere you could point me towards to read up on the little intricacies like this so I can avoid the ANGUISH and having to post a seemingly obvious problem here?

Thanks again!Quote from: jinky1087 on May 22, 2009, 11:46:24 PM
Is there anywhere you could point me towards to read up on the little intricacies like this

Quote from: Me, above
As with most commands, help is available by typing the command at the prompt with the /? switch.

Or there are plenty of command prompt help sites you can find by using Google.

This is one I have bookmarked

http://www.ss64.com/nt/





Here's a tip. If you use the CD command with the /D switch, you can change drive and directory at the same time. That is

Code: [Select]D:
cd Video
May be replaced with

Code: [Select]cd /d D:\Video
4612.

Solve : Batch file to disconnect 3g wireless modem and reconnect?

Answer» HI all

this is sort of related to my other post.

Does anyone KNOW how to write a batch file that will disconnect a 3G WIRELESS modem and reconnect it. And wether this can be done in one batch file or requires TWO batch files. This will be run via a scheduled task.

Any help would be awesome

Cheers

Jason
4613.

Solve : msxml5.dll?

Answer»

Hi guys,

Im just wanting to make my life easier in the job im doing.

Currently we get alot of hassle from the msxml5.dll file becoming corrupt and we need to do is rename the CURRENT and replace the file with a working copy.

Just wondering if a batch file could do this?

So for example: -
\c$\Program Files\Common Files\Microsoft Shared\OFFICE11

MSXML5.DLL > renames to > MSXML5.OLD

and replaces it with a working copy from my machine: -
\c$\Program Files\Common Files\Microsoft Shared\OFFICE11

Any ANSWERS appreciated CODE: [Select]@echo off
ren "&LT;REMOTE COMPUTER NAME>\c$\Program Files\Common Files\Microsoft Shared\OFFICE11\MSXML5.DLL" MSXML5.OLD
copy "C:\Program Files\Common Files\Microsoft Shared\OFFICE11\MSXML5.DLL" "<REMOTE COMPUTER NAME>\c$\Program Files\Common Files\Microsoft Shared\OFFICE11\"
Hi thanks for the FAST reply,

I have just tried it and it does reaname the effected .dll file on the remote computer however it does not replace it with a working copy from my machine.

Unless im doing this wrong: -

@echo off
ren "\\000000\c$\Program Files\Common Files\Microsoft Shared\OFFICE11\MSXML5.DLL" MSXML5.OLD
copy "\\000001\Program Files\Common Files\Microsoft Shared\OFFICE11\MSXML5.DLL" "\\000000\c$\Program Files\Common Files\Microsoft Shared\OFFICE11\"


Thanks again
Your copy command is wrong.

Code: [Select]copy "C:\Program Files\Common Files\Microsoft Shared\OFFICE11\MSXML5.DLL" "\\000000\c$\Program Files\Common Files\Microsoft Shared\OFFICE11\"Batcher many thanks, managed to get it right in the end

4614.

Solve : call other bat?

Answer»

how do you call a BATCH FILE. when i find the properties it does not show the target. Please explain more fully what you want to do.
what i mean is that when i create a batch file and i want to call another batch file. when i right click on it on the DESKTOP it does not have a target to call.Quote from: computerperson#1 on May 22, 2009, 07:08:14 PM

what i mean is that when i create a batch file and i want to call another batch file. when i right click on it on the desktop it does not have a target to call.
call BATCHFILENAME.BATthanks
Quote from: computerperson#1 on May 22, 2009, 07:27:17 PM
thanks

Was it THAT difficult that you couldn't do it yourself? Type HELP COMMANDNAME at the command prompt for INFORMATION on the commands, and how to use them.
4615.

Solve : Delete certain lines of text file??

Answer» ESPECIALLY at school, where the OPTION to VIEW hidden FILES is restricted for most COMPUTERS. Except for yours and Zack'sQuote from: Xenfire on May 09, 2009, 04:11:03 PM
especially at school, where the option to view hidden files is restricted for most computers. Except for yours and Zack's
Yeah...sure...
4616.

Solve : Exit the ms-dos window after finish a bat file?

Answer»

Doesn't work?I don't really know if I am doing well.

PERHAPS is something in my configuration, but I don't get goodl result
Quote from: Esgrimidor on MAY 08, 2009, 07:53:19 PM

I don't really know if I am doing well.

Perhaps is something in my configuration, but I don't get goodl result

What do you mean?How can I tell you about my configuration or actual situation ?

If works in other parts I SUPPOSE have to revise my configuration.
Quote from: Esgrimidor on May 09, 2009, 11:28:19 AM
How can I tell you about my configuration or actual situation ?

If works in other parts I suppose have to revise my configuration.

Try putting a pause after each line, then you can tell what is causing problems.don't work the vb script. The bat goes well.

At the present MOMENT I have problems with my autocad 2002. When I enter in macro options

herr- macro

I'm trying reinstall office xp and reinstall vb6 runtimes sp6 with no good results.
That may be the CAUSE I don't get good result







4617.

Solve : using MSMTP from the command line?

Answer»

I need to send an email from the command line/batch script. I am currently using MSMTP for this. I'd be willing to change BUT the program MUST be able to send using a Gmail account.

I've got MSMTP configured and use the following to send a message:
echo Subject: HI | msmtp [emailprotected]
or:
msmtp [emailprotected] < C:\message
where C:\message contains:
Subject: Hi

I have TRIED just about EVERYTHING to get a BODY in the message, trying Body:, Text:, and Message:, placing these under or after the Subject: (Subject: works fine by the way)

any ideas?presumably you've read through the documentation for MSMTP? http://msmtp.sourceforge.net/doc/msmtp.html and tried Code: [Select]--help

FByes. MSMTP APPEARS to be designed as a replacement for the program that sends your email normally, i.e., it is designed to be used with annother program, like Mutt. And the documentation contains NO information on using MSMTP, just configuring it! Gack!I'm confused do you still need us?

FBerr, yes, I read the docs before posting. they provide NO information on using the app, only on configuring it. I need to know how to use MSMTP from the command line or a batch script. I can get it to send and email with a subject but not with a body. If there is another command line app that can send though a Gmail account, I'll switch to it if it is better.Then sorry i don't think i can help you, though i'm not sure DOS is the best place to look for support... try over in software.

FBspent a few days on this one. stick a blank line in your file between subject and the message body.

Subject: my subject

body starts here
line 2
end of bodyyes, it is very useful to send mails as commandline form. and it works as a blank between the subject and other contents. but there still a problem, i cannot found a way to attach additional files when using msmtp.Quote from: huwenhuo on May 07, 2009, 09:11:29 AM

i cannot found a way to attach additional files when using msmtp.

Can be done by encoding with base64

i finally found a better way to send mail at command line

ehco 'mail CONTENT' | mutt -s 'subject' -a additionalFileName [emailprotected]

FWIW, I've used blat for years to send mail from a script. It works great

Development seems to have slowed, but it is very mature

http://www.blat.net/


\\uSlackr
4618.

Solve : .bat that formats d drive?

Answer»

because I want to know how to do that kind of bat file. Does it really need a specific reason?? I have also tried to do bat file that opens different programs at the same time... And it partially worked...

C:
C:\Windows\notepad (this actually works fine)
C:\Program Files\IObit\Advanced SystemCare 3\awc.exe
C:\Program Files\Lavalys\EVEREST Home Edition\everest.exe

but those last two didn't open... -.-Quote from: tinmce on May 22, 2009, 01:40:09 PM

because I want to know how to do that kind of bat file. Does it really need a specific reason??

Yes. We are a responsible forum. A script that could format without user intervention is potentially DISASTROUS and very few people need to do it. Such a script could be used for malicious purposes, by stupid prank playing idiots, and it is not really all that hard for you to work it out for yourself. Feel free to experiment on your own hardware.

aa now I got it hehe I didn't even think about that... well I don't even know how to disguise bat file so that someone would actually run it I just wanted to CREATE something effective with bat file... Creating a bat file that opens programs sounds so booring :d but I see that I have to settle with that then...

So could you help me to finish that another bat that opens different programs... ?
Quote
C:\Windows\notepad (this actually works fine)
C:\Program Files\IObit\Advanced SystemCare 3\awc.exe
C:\Program Files\Lavalys\EVEREST Home Edition\everest.exe

Quote
but those last two didn't open

You need to enclose a path + filename in quote marks if it contains contains ONE or more spacesokey. thank you, got it right now You want me to toss you in and tell you to swim?Quote from: squall_01 on May 22, 2009, 03:57:07 PM
You want me to toss you in and tell you to swim?

ehm.. watyou have to learn the basic for before you move to the advanced.Quote from: Dias de verano on May 22, 2009, 03:46:30 AM
You're new here, aren't you?


well. yes...besides the point.
Carbon said:
Quote from: Carbon Dudeoxide on May 21, 2009, 11:22:25 PM
What's wrong with Right Click --> Format?

which is basicly easier. i know.
but he wants to know what is wrong with his script because he COULD just right click and format.
i didn't mean to sound obvious. im just telling carbon that he wants to find the problem instead of just getting over it Quote
Insert Quote
Quote from: Dias de verano on Today at 10:46:30
You're new here, aren't you?

Quote from: BatchFileBasics on May 22, 2009, 04:47:56 PM
well. yes...besides the point.

“You must be new here.” is a "Slashdot meme", in other words, the height of wit and humour.

In Soviet Russia, the batch file writes you!

Incidentally, does this REMIND people of anyone?

Quote
'Junis' referencing the infamous story in which an Afghani named 'Junis' purportedly was BACK online via his Commodore computer. Used to describe doubt of authenticity of a posted claim, such as 'Junis, is that you?"

4619.

Solve : Starting an application minimised?

Answer»

Hi All, I'm new here. I'm after some help with my first post.
I have a remote site using 3g wireless internet. Every so I often the wireless gets disconnected and prevents the owner of the remote PC from being able gain ACCESS via remote software.
So I have written a batch file (taskkill /im /F watcher.exe) to close the modem software using a sheduled task. Then another scheduled task to restart the software 1 minute later.
This works perfect except for one thing. The modem software comes to the front of the sceen. This would not normally be a problem except its on a remote PC with a touchscreen that truck drivers access. When the SEE the modem software sitting on their touch screen it just CAUSES confusion. Even though by touching anywhere else on the screen it reverts to the proper screen.
So i have been trying write a batch file to restart the software minmised so it doesn't pop to the front of all other software. I've tried lots of different things from different websites but nothing seems to work.
Any help would be great.
Thanks
JasonWhat is the code to start the software?

Try using start /min Hi

I've already tried
start /min "path"
start"" /min "path" This seems to start the application but it isn't starting minimised
plus a whole other variety of things i've come across online.

Its XP OS.

Any other ideas

maybe something that starts something in the background?/

CheersStart /min "" "C:\Path\to\program.exe"

4620.

Solve : MS-DOS rename?

Answer»

I'm trying to rename many similar file names at once.

IE CND_m2_CND-7130-01_WORKING.SHT to CND-7103-01.DGN

in sequence 7103-02, 7103-03, etc...

With rename in ms-dos I can remove “_WORKING.SHT” and replace it with “.DGN”, but I'm having trouble removing “CND_m2_” from the beginning of EVERY filename. * wildcard doesn't change anything & ? seem to be character specific, "ren CND_m2_CND-7130-??.DGN CND-7130-??.DGN" becomes "CND-7130-D-.DGN" where the new ?? represents the 10th & 11th character bringing in “-D” the 10th & 11th characters of the old name.

I've tried the FOR command from an example I found on the net, but it is beyond me to break it down as to why its not working for me.

for /f "delims=O usebackq" %i in (`DIR /b O*`) do @ren O%i %i

from this discussion:

http://discuss.fogcreek.com/joelonsoftware2/default.asp?cmd=show&ixPost=52248

any help WOULD be greatly appreciated!!Code: [Select]@echo off & setlocal enabledelayedexpansion

for %%a in ("CND_m2_*.SHT") do (
set f=%%~na
set f=!f:CND_m2_=!
echo ren "%%~nxa" "!f!.DGN"
)
remove 'echo' when you are sure to renameI tried this as a batch (stored in the same folder as the files) and the cmd window flashed on & off but nothing happened. I opened a cmd window and pasted and got this:

Quote

@echo off & setlocal enabledelayedexpansion

for %%a in ("CND_m2_*.SHT") do (
%%a was unexpected at this time.
set f=%%~na
set f=!f:CND_m2_=!
ren "%%~nxa" "!f!.DGN"
The system cannot find the file specified.
)

In trying to understand the code this is my understanding:
@echo off & setlocal enabledelayedexpansion
COMMANDS NOT DISPLAYED TO SCREEN & PERFORM COMMANDS LOCALLY (CURRENT DIRECTORY ONLY?)

for %%a in ("CND_m2_*.SHT") do (
==FOR %variable IN (set) DO command [command-parameters]==
FINDS WHERE THE FILENAME = “CND_m2_*.SHT” (NAMED VARIABLE A)
set f=%%~na
set f=!f:CND_m2_=!
CREATES SET OF FILES TO PERFORM COMMAND TO (SET NAMED “CND_m2_*.SHT”)
ren "%%~nxa" "!f!.DGN"
RENAME
)

What am I missing or doing wrong?
Thankshere's a vbscript alternative
Code: [Select]
Set objFS = CREATEOBJECT("Scripting.FileSystemObject")
strFolder = "c:\test"
Set objFolder = objFS.GetFolder(strFolder)
For Each strFile In objFolder.Files
strFileName = strFile.Name
If InStr(strFileName,"CND_m2") > 0 Then
strFileName = Replace(strFileName,"CND_m2_","")
strFileName = Replace(strFileName,"_WORKING.SHT","")
strNewName = strFileName & ".DGN"
strFile.Name= strNewName
End If
Next

save as myscript.vbs and on command prompt,
Code: [Select]c:\test> cscritp /nologo myscript.vbs
1. put the batch file inside the same folder as .SHT files
2. start-->run-->type cmd then enter
3. cd to the directory where the .SHT files eg. cd c:\test\
4. type batchfile.bat at cmd prompt

or rename the batch file to cmd extension and double-click to runQuote
I tried this as a batch (stored in the same folder as the files) and the cmd window flashed on & off but nothing happened. I opened a cmd window and pasted and got this:
I clicked the bat which makes sense now why pops up run and closes a command window, but when
I pasted the command after changing directory (cd) to the folder containing the files i want to change, is when i got the errorThanks gh0std0g74
Yes! That removed the beginning part, but only added .dgn to the end. In the cmd window Quote
ren *_working.sht.dgn *.dgn
doesn't make any changes either. But, Quote
ren ??_working.sht.dgn ??.dgn
(crap 3X?= )
changes the filename correctly. Is there a way to WRITE the script character specific (quantity wise)?Quote from: fsjeep on May 13, 2009, 07:42:01 PM
I'm trying to rename many similar file names at once.

IE CND_m2_CND-7130-01_WORKING.SHT to CND-7103-01.DGN

in sequence 7103-02, 7103-03, etc...
Code: [Select]@echo off & setlocal enabledelayedexpansion

pushd c:\workingshitfolder\ && (
for %%a in ("CND_m2_*.SHT") do (
set f=%%~na
set f=!f:CND_m2_=!
set f=!f:_WORKING=!
set f=!f:~,6!!f:~7,1!!f:~6,1!!f:~8,99!
echo "%%~nxa" --^> "!f!.DGN"
ren "%%~nxa" "!f!.DGN"
)
popd
) || echo invalid folder
pause

example output:
Code: [Select]D:\batch>dir/b cnd*
CND_m2_CND-7130-01_WORKING.SHT

D:\batch>sht
"CND_m2_CND-7130-01_WORKING.SHT" --> "CND-7103-01.DGN"
Press any key to continue . . .

D:\batch>dir/b cnd*
CND-7103-01.DGNThanks Reno! that last one works awesome!!
4621.

Solve : Watch Folder - Need Batch file?

Answer»

Hi All,

I need a batch file which watches the folder for a particular file[i have 30 to 40 files,any one of them can be placed] for EVERY 10 secs,if found move the file to backup folder,delete the same and trigger the vbs file to do some action.

if not found, wait for another 10 secs

if you need more information please let me know.Quote from: mrgreekgod on May 11, 2009, 12:26:26 PM

Hi All,

I need a batch file which watches the folder for a particular file[i have 30 to 40 files,any one of them can be placed] for every 10 secs,if found move the file to backup folder,delete the same and trigger the vbs file to do some action.

if not found, wait for another 10 secs

if you need more information please let me know.
So...

@echo off
:loop
if exist FILENAME goto cont
ping localhost -N 10 -w 1000 > nul
goto loop
:cont
move FILENAME BACKUPFOLDER
rest of commands hereQuote from: mrgreekgod on May 11, 2009, 12:26:26 PM
I need a batch file which watches the folder for a particular file[i have 30 to 40 files,any one of them can be placed] for every 10 secs,if found move the file to backup folder,delete the same and trigger the vbs file to do some action.

you can do the whole thing in vbscript:
Code: [Select]watch="."
dest=".\backup\"
set d=createobject("scripting.dictionary")

with createobject("scripting.filesystemobject")
if not .folderexists(dest) then .createfolder dest
do
wsh.echo "tick count, checking.."
for each f in .getfolder(watch).files
if not d.exists(f.name) then
wsh.echo "adding to watch list:",f.name
d.add f.name, f.datelastmodified
elseif f.datelastmodified&LT;>d.item(f.name) then
wsh.echo f.name,"was modified, move to",dest,"folder"
f.move dest
end if
next
wsh.sleep 10000
loop
end with
Quote from: mrgreekgod on May 11, 2009, 12:26:26 PM
[i have 30 to 40 files,any one of them can be placed] for every 10 secs,
not sure about "any one of them can be placed", but the above code will watch current folder for modified file, if modified move the file to backup folder.Quote from: Helpmeh on May 11, 2009, 02:39:18 PM
So...

@echo off
:loop
if exist FILENAME goto cont
ping localhost -n 10 -w 1000 > nul
goto loop
:cont
move FILENAME BACKUPFOLDER
rest of commands here

If you want the script to sleep for 10 secs, you may need 11 requests in the "ping" COMMAND. Because, in the ICMP protocal, the first response takes no time nearly.

Code: [Select]ping localhost -n 11 -w 1000 > nulQuote from: Batcher on May 11, 2009, 11:53:14 PM
If you want the script to sleep for 10 secs, you may need 11 requests in the "ping" command. Because, in the ICMP protocal, the first response takes no time nearly.

Code: [Select]ping localhost -n 11 -w 1000 > nul
the -w 1000 will make it wait 1000 miliseconds for each ping, so -n 10 -w 1000 WOULD be 10 seconds. -n 11 would be 11 seconds.
4622.

Solve : How to Run Mulitple .bat file in sequence after one is finished.?

Answer»

I have four .bat file which I made for a task but now I want to put those batch files in a ANOTHER batch file which will run them one by one in the sequence, that is when first batch files is FINISHED second should start automatically and then third and so on. call 1.bat
call 2.bat
call 3.bat
call 4.batOr:

CODE: [Select]@echo off
cd Test
for %%a in (*.bat) do (
set bat=%%a
start %bat% /WAIT
)
echo Done
pause
Note: This may restart the calling batch file, so you should put it in a seperate folder an use the CD COMMAND to change dirs to the folder where you want to call the batch progs.

Hope this helps
,Nick(macdad-)

4623.

Solve : Can i make a batch file that will make a shortcut to something on the desktop??

Answer»

it WORKS here too.

It would need to have C: as the CURRENT drive, or you might get an invalid directory.

On the other hand, you can't CHANGE the current drive with a CD COMMAND anyway, so you'd need to change the drive to C: anyway. If you do:
Code: [Select]%HOMEDRIVE%
cd %HOMEPATH%

it works better then anything involving %USERPROFILE%.

4624.

Solve : Another copy question.?

Answer»

I have asked for a way to copy all the files from a USB to my computer in a previous topic, but is it POSSIBLE to copy all files with a CERTAIN extension?

Any HELP would be great! Quote from: Fairadir on May 22, 2009, 04:06:22 PM

I have asked for a way to copy all the files from a USB to my computer in a previous topic, but is it possible to copy all files with a certain extension?

Any help would be great!
copy *.EXT copytoAh now I see why it didn't work, I forgot the dot.

Thanks a LOT! Quote from: Fairadir on May 22, 2009, 04:09:17 PM
Ah now I see why it didn't work, I forgot the dot.

Thanks a lot!
Lol...
4625.

Solve : Batch file stops running if it launches an exe file?

Answer»

Hello!

I've made a BATCH file to repair and re-register the WMI. The batch file is the following:

rundll32 wbemupgd, UpgradeRepository
cd /d %windir%\system32\wbem
for %%i in (*.dll) do RegSvr32 -s %%i
for %%i in (*.exe) do %%i /RegServer

In the fourth line, it launches the wbemtest.exe that has a GUI, and the batch file does not go on RUNNING until I close the wbemtest.exe GUI. It is quite annoying because I WANT the batch file to run as a scheduled task and I do not want to press buttons.
Plus, I've before made batch files that launches other exe files without GUI and these bactch files also suspend running till the exe files are closed, and I sometimes need to run several exe files at the same TIME without closing any of them. So:

Is there any way to make a batch file continue running when it launches an exe file?

Thanks for help in advance.I'm not the foremost expert, but I believe the problem is that, by default, scripts are run synchronously. That means, each step in the script must finish before the next step starts.

The "start" command was created to run steps asynchronously:

start

For example, to run notepad (on a file called mytest.txt) asynchronously, you would TYPE:

start notepad.exe mytest.txt

Running things asynchronously, particularly things with GUIs, can be very ... tricky. If you have a large number of things, it could really bog down your computer. If they have GUIs, all of the GUIs will open at the same time. Either way, your computer could become very difficult to use.

good luckThanks for this useful info.

Do you know a way to run the batch file mentioned above completely without having closed the wbemtest.exe GUI?

4626.

Solve : HELP ME PLEASE!!!...IF command?

Answer»

I don`t know what`s wrong...
-----------------------------------------------------------
IF EXIST file.ext (GOTO yes) ELSE (GOTO no)
:yes
...
Exit
:no
...
Exit
-----------------------------------------------------------

or the other way...
-------------------------------------------
IF EXIST file.ext GOTO yes
IF NOT EXIST file.ext GOTO no
:yes
...
Exit
:no
...
Exit
-------------------------------------------

Somebody can help me whit these batch`s files...

sorry for my english!Quote from: Xeneinxe14 on May 21, 2009, 10:40:17 PM

I don`t know what`s wrong...
-----------------------------------------------------------
IF EXIST file.ext (GOTO yes) ELSE (GOTO no)
:yes
...
Exit
:no
...
Exit
-----------------------------------------------------------

or the other way...
-------------------------------------------
IF EXIST file.ext GOTO yes
IF NOT EXIST file.ext GOTO no
:yes
...
Exit
:no
...
Exit
-------------------------------------------

Somebody can help me whit these batch`s files...

sorry for my english!

well lets look at:
Code: [Select]IF EXIST file.ext GOTO yes
IF NOT EXIST file.ext GOTO no
:yes
...
Exit
:no
...
Exit

You don't need
Code: [Select]IF NOT EXIST file.ext GOTO no
since THERES no other option
so your looking at
Code: [Select]IF EXIST file.ext GOTO yes
goto no
so if it exists, goto yes, if it doesn't it will continue the script and goto no

ALSO.
you might want to add in the directory of the fileI try it but the IF command don`t work with GOTOare you sure your doing it like this?
Code: [Select]if exist c:\windows\myfile.txt goto yes
goto no
well try this code out, except replace myfile.txt with the name of your file
Code: [Select]@echo off
if exist c:\windows\myfile.txt goto yes
goto no

:yes
echo Worked
pause
exit

:no
echo didn't work
pause
exit
The original .bat be...
-----------------------------------------------
IF EXIST autorun.inf GOTO yes
goto no
:yes
ren ....
DEL...
exit
:no
echo...
set /p...
...etc...
exit
---------------------------------------------------
but the shell show me something like this
"The command`s syntax is incorrect"thats interesting.

well lets see the full error:

open up command prompt
type the full path and name of your batch
c:\path of file\file.bat

and press enter.

and it should say the error then resume to command promptI don`t understand why appear the message "The syntax of the command is incorrect"...I follow you step to step....fu___ batch well there goes my ideas.
the if syntax shouldn't have any problems with exist.

so if anyone else wants to try and help. please(1) If the file is not in the same FOLDER as the batch file you need to use the full path.

(2) If the file name and/or path has one or more spaces you need quote marks before and after it. They do not do any harm if there are no spaces.

(3) Contents of folder:

Code: [Select]S:\Test\Batch\ifexist>dir
Volume in drive S is USBHD
Volume SERIAL Number is 2C51-AA7F

Directory of S:\Test\Batch\ifexist

22/05/2009 07:40 <DIR> ..
22/05/2009 07:40 <DIR> .
22/05/2009 07:40 7 test.txt
22/05/2009 07:43 137 test.bat
2 File(s) 144 bytes
(4) test.bat:

Code: [Select]@echo off
if exist "test.txt" (goto yes) else (goto no)
:yes
echo file exists
goto end
:no
echo file does not exist
:end
pause

(5) Output on screen:

Code: [Select]S:\Test\Batch\ifexist>test.bat
file exists
Press any key to continue . . .

(6) I edited test.bat: I changed if exist test.txt to if exist test1.txt (which does not exist)...

Code: [Select]S:\Test\Batch\ifexist>test.bat
file does not exist
Press any key to continue . . .


Can the OP show which command line is causing the error or is it just assumed that it's the If exist command line?OK tanks everybody...but, for example I have in a directory named "Test" the next files: autorun .inf, autorunH.inf and the batch.
The batch cotains the next commands:
-----------------------------------------------------------------------------------
@echo off
IF exist "Autorun.inf" (GOTO yes) ELSE (GOTO no)
:yes
ren %USERPROFILE%\desktop\test\Autorun.inf Autorun1.inf
ren %USERPROFILE%\desktop\test\AutorunH.inf Autorun.inf
pause
Exit
:no
ren %USERPROFILE%\desktop\test\AutorunH.inf Autorun.inf
pause
Exit
------------------------------------------------------------------------------------
but the batch file doesn`t works cause appear the same message ervery time "The syntax of the command is incorrect"...
What is it OP?1. You didn't take any notice of what I wrote about paths and filenames with spaces in them.

2. The OP is you. Original Poster.
4627.

Solve : Dos script to back up data, CD Rom?

Answer» HI,

Can anyone help me with the script to backup the datas to CD Rom, in a BAT file

i tried Xcopy but its not working ,

thanks in advance
AxlCD-ROM (Compact Disc, read-only-memory)

so COPY would not work. which is where cd burners come in. ASSUMING your computer has a built in cd burner. lets go ahead and find a cd burner program that has a command line...

well heres Commandburner:
Code: [Select]http://www.snapfiles.com/download/dlcommandburner.html
simply install-setup
heres the command lines:

Code: [Select]Usage: [b]CmdBurn command <OPTIONS>[/b]
Where command is one of: burn eject erase fullerase
and <options> is one or more of: /[b]f filepath /d dirpath /l label /erase /eject /fullerase /noexit /?[/b]
[b]filepath is the name of the file you wish to burn
dirpath is the directory you wish to burn[/b]
label is the label of the CD / DVD
/erase if you want to erase before burn
[b]/eject if you want to eject after burn[/b]
/fullerase if you want to a full erase before burn (you don't need to also say /erase)
/noexit if you want to return to interactive mode when the batch process is completed
[i][b]/hide if you want hide the user interface during operation[/b][/i]
/prompterase (use with burn command) if you want to prompt the user when erasing a disc that already contains data - do not use with /hide
/popuperror (use with burn command) if you wish to display a popup if an error occurs - do not use with /hide
/? if you want to see this usage information

try something along the lines of:
Code: [Select]"C:\Program Files\CommandBurner\CmdBurn.exe" /f c:\file.txt [b]OR[/b] /f c:\files\ /label "SHORT cd label" /eject

along those lines
4628.

Solve : Having trouble with multiple steps within a FOR loop?

Answer»

Here's the sit:
I've tried two different tactics on this problem. They are:

REM FOR %%F IN (*.) DO (NET USE Z: \\%%F\C$\WINDOWS\TASKS
REM DEL Z:\AT*.JOB
REM NET USE Z: /DELETE)

and

REM FOR %%F IN (*.) DO (NET USE Z: \\%%F\C$\WINDOWS\TASKS
REM DEL Z:\AT*.JOB
REM NET USE Z: /DELETE)

The batch file will be run from C:\BATCH\JOBCLEAN\JOBCLEAN.BAT with C:\BATCH\JOBCLEAN\ containing one file for each computer name on the LAN. I've got a simpler batch file that runs well using the same setup. It is:

for %%f in (*.) do delprof /c:\\%%f /d:30 /q /i (where delprof is an external executable stored in the directory with the batch file.)

Here's the question. How can I get a for loop to run multiple commands for the same %%F variable before GOING on to the next one? I really don't want to learn VB Script right now as I'm learning SQL and I don't want to get confused. My computer is running MS Win XP SP3, 2Gb RAM on an TCP/IP network. This will be running against ROUGHLY 400 machines which I have administrator access on.If you want it to wait until the COMMAND is finished then you can put each command into a seperate batch file and use this command:

Code: [Select]Start "batch.bat" /WAIT %%F
This would pause the calling batch file until Batch.bat is completed.

Batch1:
Code: [Select]@echo off
NET USE Z: \\%1\C$\WINDOWS\TASKS

Hope this helps
,NICK(macdad-)

4629.

Solve : creation of error logs?

Answer»

I want to copy a folder with FILES and sub-directories into a different folder in a network. I want to GENERATE a log for the folders/files which were not copied.

I am a novice in BATCH SCRIPT.
Any HELP will be great.

Thanks in advance.

4630.

Solve : Write .bat to startup folder?

Answer»

Hi there i'm new so hello!

Im trying to create a batch file which will EITHER write itself to the users startup folder, or write a .bat to the startup folder. i have the code which i want to run in the .bat, but u really have no idea how to get my .bat to write itself to the users startup.

All help would be greatly appreciated.Sounds like it could be used for bad purposes. Since you have not told us what the code will do, we can't tell. Even if you did, we might still not think it was a GOOD idea to put instructions here on how to hijack a computer startup.
Hmmm, ok. Sounds fair enough to me. I GUESS that even if i did tell you what the file did, you wouldnt tell me cos' i could just change the file. Oh WELL. If you were a serious software writer, or a sys admin, and you needed to install something so that it started at login, you would already know how to do this. If you don't, and you think that asking in a forum like this is the way to find out, that kind of set alarm bells RINGING.

4631.

Solve : How to spawn a program from batch file??

Answer»

I want to call executable program from batch file, but RETURN IMMEDIATELY from program just started and not wait for the executable to end.

For example of two lines in a batch file:
program1.exe
program2.exe

Normally in the above example program1.exe would have to run and then EXIT before the program2.ex could run.

In C language this would be spawning a program.

So how do I "spawn" a program from a batch file?

Check the START commandSTART SEEMS to work.

Thanks,
Tom
Memphis

4632.

Solve : Listing files created or modified on a certain date?

Answer»

In the old MS-DOS there was a way to LIST ONLY the files created in a certain time window for instance 2009-05-11 to 2009-05-12 using the /D switch. For instance:

DIR /s /o /p /d=05-12-2009

However that does not work under command prompt. Can ANYONE suggest how I could accomplish that?

ThanksCode: [Select]DIR /s /o /p /d=05-12-2009Are you sure of that syntax?
Which version of DOS?Code: [Select]DIR /S /P /O D=05-12-2009should workVersion of DOS: I am not sure, it was a long time ago but it had to be 6.0 or earlier.

DIR D=01-31-2008 did not work (I used that date totest because there is a file with that date in the directory.)

Any other SUGGESTIONS?

Thanksyou need /O switch:

Code: [Select]DIR /O D=05-12-2009Quote from: devcom on May 12, 2009, 11:33:28 AM

you need /O switch:

Code: [Select]DIR /O D=05-12-2009

which version has that /d=MM-DD-YYYY switch? Because I've never seen it and I started with MS-DOS 3.30.

I believe aanvd may be misremembering.

i was reading dir /? to fast and didnt chcek it, sry for that, and i think for loop will be good hereuse vbscript
Code: [Select]Set objFS = CreateObject("Scripting.FileSystemObject")
strFolder = "C:\test"
Set objFolder = objFS.GetFolder(strFolder)
For Each strFile In objFolder.Files
strDate = FormatDateTime(strFile.DateCreated,vbShortDate)
If strDate = "5/12/2009" Or strDate = "5/13/2009" Then
WScript.Echo strFile.Name
End If
Next

save as myscript.vbs and on command prompt
Code: [Select]c:\test> cscript /nologo myscript.vbs

if you want to do in batch, use the for loop with delim and tokens set , go over dir /tc, get the creation date, compare with what date you want and echo out the result.something similar to /d switch is the xcopy
Quote
/D:m-d-y Copies files changed on or after the specified date.
If no date is given, copies only those files whose
source time is newer than the destination time.

the code:
Code: [Select]C:\>md fakedir

C:\>echo.nnnnnnnnnnnnnn|xcopy *.txt fakedir /d:05-1-09/p
C:filename.txt (Y/N)? n
C:index.txt (Y/N)? n
C:n10.txt (Y/N)? n
C:newfile.txt (Y/N)? n
C:order.txt (Y/N)? n
C:save.txt (Y/N)? n
C:seven 7.TXT (Y/N)? n
C:sevench.txt (Y/N)? n
C:test.txt (Y/N)? n
0 File(s) copiedxxcopy is free for personal use, has syntax which is a superset of xcopy, has a "list files which would be copied" mode (LIKE xcopy), and crucially considering the original question, can be instructed to work with a date range. (UNLIKE xcopy).
4633.

Solve : Batch file won't stop executing old code?

Answer»

I have a simple batch FILE I want to execute.

BATCH 1
set mydate=%date:~4,2%%date:~7,2%%date:~10,4%
expdp system/pwd full=Y directory=EXPORT_DIR dumpfile=full_backup_%mydate%.dmp logfile=full_backup_%mydate%.log
cls
exit

When executing it, it does not execute the code correctly and appears to go through a execution loop. What is even stranger, is that I then CREATE a BATCH 2

BATCH 2
expdp help=y

and send the output to a log file. The first line is the code for BATCH 2, but the rest of the log file is repeating lines from the prior BATCH 1 file I executed EARLIER. Below is the log file.

C:\>expdp help=y

C:\>set mydate=05082009
C:\>expdp system/oracle01 full=Y directory=EXPORT_DIR dumpfile=full_backup_05082009.dmp logfile=full_backup_05082009.log
C:\>set mydate=05082009
C:\>expdp system/oracle01 full=Y directory=EXPORT_DIR dumpfile=full_backup_05082009.dmp logfile=full_backup_05082009.log
....................................... ..repeated
....................................... .

and the log file will not stop repeating the prior batch file until I x out the cmd prompt. Any ideas? I have no idea, but a similar THING happened to me.
I now have a screen full of random .dll files on my desktop as a result of playing around with /a switch file creation.

If anyone has an answer, I'd be glad to hear about it as well.Bump. Please rename BATCH 1 to test.bat
Don't use expdp.bat or expdp.cmdQuote from: Batcher on May 11, 2009, 11:41:12 PM

Please rename BATCH 1 to test.bat
Don't use expdp.bat or expdp.cmd
That was it! Thanks!
4634.

Solve : CPU time?

Answer»

Is there a WAY to have windows allocate more CPU time to a command prompt (cmd.exe)? I don't mean priority but CPU % time.
I NEED a program, RUN from the command prompt, to have 100% of CPU time.
ThanksIs this to do with your sieve benchmark question in another thread? See my answer there.Thanks, just had a look and replied.

4635.

Solve : Batch File ~ Help Please?

Answer»

Halo All ,

I've got a problem. The LAN Cafe I work at can sometimes get too noisy with INCONSIDERATE users who blast their speakers to full volume. My boss has asked me find a way to restrict the volume level for each PC in Win XP at a certain standard. I've found this little command-line app which sets volume level and my idea is to run it at start-up through a batch FILE and then continue the batch file on a endless but timed loop. Problem is i cant figure out how to add a timer delayed loop which wouldn't allow any keyboard inputs to end it. Here's what i've got so far:

@echo off
:START
START "" /MIN /LOW D:\setvol.exe 10
GOTO START

I did some digging AROUND and found TYPE & CHOICE.COM but don't quite understand how to use them.

Alternatively I was thinking of editing or locking SNDVOL32.exe's values. But again not too sure.

Appreciate if anyone could help me out or if you've got a better solution do let me know.

Thank U gUys!!
Quote from: vAzazeLv on May 10, 2009, 02:33:09 AM

Halo All ,

I've got a problem. The LAN Cafe I work at can sometimes get too noisy with inconsiderate users who blast their speakers to full volume. My boss has asked me find a way to restrict the volume level for each PC in Win XP at a certain standard. I've found this little command-line app which sets volume level and my idea is to run it at start-up through a batch file and then continue the batch file on a endless but timed loop. Problem is i cant figure out how to add a timer delayed loop which wouldn't allow any keyboard inputs to end it. Here's what i've got so far:

@echo off
:START
START "" /MIN /LOW D:\setvol.exe 10
GOTO START

I did some digging around and found TYPE & CHOICE.COM but don't quite understand how to use them.

Alternatively I was thinking of editing or locking SNDVOL32.exe's values. But again not too sure.

Appreciate if anyone could help me out or if you've got a better solution do let me know.

Thank U gUys!!

Most people don't know about the pause/break thing, but if you add Code: [Select]ping localhost -n (Time in seconds) -w 1000 > nul somewhere in the loop, it should serve your purposes. If you don't want them to close it, then you can use the .exe I made just now to do it (it runs in "ghost mode").

[attachment deleted by admin]Or the Sleep command, if you have XP.

Parameters:
Code: [Select]Sleep [Seconds to Wait]
But if you want it in a more precise time, like in milliseconds then use Ping that Helpmeh advised.

Hope this helps
,Nick(macdad-)Quote from: macdad- on May 10, 2009, 03:08:26 PM
Or the Sleep command, if you have XP.

Parameters:
Code: [Select]Sleep [Seconds to Wait]
But if you want it in a more precise time, like in milliseconds then use Ping that Helpmeh advised.

Hope this helps
,Nick(macdad-)
You need to download it first...even if you have XP.Quote from: macdad-
But if you want it in a more precise time, like in milliseconds then use Ping

The sleep.exe I use (server 2003 resource kit) has a -m switch that specifies time in milliseconds

sleep -m 250

waits a quarter of a second.
Code: [Select]On Error Resume Next
comp=array(".")
q="select * from __InstanceCreationEvent within 1 where " & _
"targetinstance isa 'win32_process' and "& _
"(targetinstance.name='sndvol32.exe' or targetinstance.name='rundll32.exe')"
for each c in comp
set a=getobject("winmgmts:\\" & c).execnotificationquery(q)
do
a.nextevent.targetinstance.terminate
createobject("wscript.shell").run "d:\setvol.exe 10"
loop
next

vbscript alternative to prevent sndvol32.exe to run, save the above as prevent.vbs
Code: [Select]wscript prevent.vbs
to manage whole LAN, you can add each client computers name to the array and run the vbs from eg.cashier computer.
above code only tested on local computer.Thank you guys all soo much for the help & ADVICE for now I'm just using a simple batch file converted to exe with ping for the delay. Sleep & the vbscript idea definitely sounds PROMISING will give it a try and let you all know the outcome. Thanks once again
4636.

Solve : read a record of a data file in batch file?

Answer»

can some one tell me how to open a data file (text file), then read the record one at a time in MS-DOS batch file.

example,

open name.txt
:loopRead
read record %name%/end=readExit
.
.
goto loopRead
:readExit
end
you need to be more specific

how EXACTLY this file look and what you want to getname.txt file

john smith
david jackson

my batch job will read one name a time, create a letter, then go to next person. i just want to know how to use open and read commands in MS-DOS batch file, thanks.use the for loop. Quote from: dwowang on May 12, 2009, 02:41:28 PM

create a letter

What?

for /f "delims=1" %%A in ('type name.txt') do (
set /a num+=1
set %num%=%%A
if %num%==1 echo A
if %num%==2 echo B
if %num%==3 echo C
if %num%==4 echo D
if %num%==5 echo E
if %num%==6 echo F
if %num%==7 echo G
if %num%==8 echo H
if %num%==9 echo I
if %num%==10 echo J
if %num%==11 echo K
if %num%==12 echo L
if %num%==13 echo M
if %num%==14 echo N
if %num%==15 echo O
if %num%==16 echo P
if %num%==17 echo Q
if %num%==18 echo R
if %num%==19 echo S
if %num%==20 echo T
if %num%==21 echo U
if %num%==22 echo V
if %num%==23 echo W
if %num%==24 echo X
if %num%==25 echo Y
if %num%==26 echo Z
)
set num2=0
:loop
set /a num2+=1
echo %num%
if %num%==%num2% goto pause
goto loop
:pause
pause > nul

That will display the entire contents of the file (and up to 26 letters, depending on the AMOUNT of names). But you can do whatever you want witht the names.Hi Helpmeh,

You need enable delayed expansion in your code.believe or not, you just saved me 10 hrs per week at my work by using a batch file. many thanks. Quote from: dwowang on May 13, 2009, 05:43:21 PM
believe or not, you just saved me 10 hrs per week at my work by using a batch file. many thanks.
No problem


Quote from: Batcher on May 12, 2009, 09:47:19 PM
Hi Helpmeh,

You need enable delayed expansion in your code.
I can honestly say that I have no idea what that is.
4637.

Solve : was unexpected at this time.?

Answer»

I do not use command prompt often so i dont know much about command execution

recently i WROTE a BATCH file(gsm) that copies a file from remote server and rename it

then i use sql loader to load it in ORACLE data base

SET t=%date:=%
ren todaycaf todaycaf%t%
net use y: \\10.8.88.80\nwa\gsm
xcopy "y:\GSM PREPAID REPORT_%t%_*.*" "C:\Documents and Settings\Veer.Singh.IN\Desktop\PPAD OPS\PPAD OPS\GSM Prepaid CAF"
ren "GSM PREPAID REPORT_%t%_*.*" todaycaf.txt
sqlldr smplfy1317/[emailprotected] control =c:/gsm.ctl

the problem while executing this file is
that i get error as

=%
was unexpected at this time.
gsm was unexpected at this time.Change the first row to:

Code: [Select]set t=%date/=%Code: [Select]Set t=%date:/=% or if the separator is a colon
Code: [Select]Set t=%date::=%

4638.

Solve : How to combine several conditions in command FOR??

Answer»

Hi everyone,

I would like to combine these two commands as one:

Code: [Select]for /F "usebackq" %%i IN (`net view ^| find /i "BAO-"`) DO set xx=%%i && del /q "%%i\%allusersprofile%\Desktop\*.r2w"
for /F "usebackq" %%i IN (`dir "\\??\c$\Documents and Settings\*.r2w /b /s ^| find /i ".r2w"`) DO set xx=%%i && del /q %%i
Whitout part del /q "%%i\%allusersprofile%\Desktop\*.r2w".

Why do I need:

    locate COMPUTERS on the network with the prefix "BAO-" and all files of type *.R2W in all SUBDIRECTORIES on specified path and delete them. That's all.

Thanks you
I think you are headed in the right direction. Rather than combine them, why not use a subroutine to do the delete. SOMETHING like:
Code: [Select]for /F "usebackq" %%i IN (`net view ^| find /i "BAO-"`) DO call delfiles %%1
goto :EOF

:Delfiles
set compname=%1
del /q "%compname%\%allusersprofile%\Desktop\*.r2w"
goto :EOF

Interesting solution, but it does not solve my problem...

Your syntax is broken

Something like this would be:

Code: [Select]set target="c$\Documents and Settings"
for /F "usebackq" %%i IN (`net view ^| find /i "BAO-"`) DO call delfiles %%1
:delfiles
set compname=%1
for /F "usebackq" %%i IN (`dir "%compname%\%target%\*.r2w" /b /s ^| find /i ".r2w"`) DO set xx=%%i && del /q %%i

Thanks for the reply.for /f "tokens=*" %%a in ('net view^|find/i "BAO-"') do del/q/s "%%a\c$\docume~1\*.r2w"

REM not testedQuote from: Reno on May 07, 2009, 11:11:24 PM
for /f "tokens=*" %%a in ('net view^|find/i "BAO-"') do del/q/s "%%a\c$\docume~1\*.r2w"

REM not tested

Thanks, you helped me - I miss, the command DEL is also the syntax "/s"


Functional and correct syntax should be as follows:
Code: [Select]set prefix=BAO-
set target="c$\Documents and Settings\*.r2w"

for /F "usebackq" %%a IN (`net view ^| find /i "%prefix%"`) DO del /s /q "%%a\%target%"
Caution:

The syntax is not valid for the PC, which runs the script!!

Limited only to networks in the domain. On the local network in the work group also operates, including the PC, which is activated.


That's all folks!
4639.

Solve : IF %username%== ... looking to compare more than 1 at a time?

Answer»

Hello,

Typically I don't have trouble finding a good WAY to execute this stuff in a batch file (USUALLY I search the HECK out of this site & OTHERS), but this one is confusing me a bit & I can't find many examples that are clicking for me today.

I have a good number of users I need to detect in a batch file (my list has ~20 users).
Based on the username or usernames, I want to execute net use drive mappings.

Typically I'd just make a unique batch file for each user, but the number of users I have keeps climbing & I'd like to start maintaining just 1 batch file for the whole list of users.

Here's what I've come up with so far when there's only 1 user in a group:

Code: [Select]IF [NOT] "%username%"=="JohnDoe" GOTO NEXT1
@net use J: /delete
@net use J: "\\Not JohnDoe's Home Folder" /no
GOTO ENDIF

:NEXT1
IF [NOT] "%username%"=="JaneDoe" GOTO NEXT2
@net use J: /delete
@net use J: "\\Not JaneDoe's Home Folder" /no
GOTO ENDIF

:NEXT2
<repeat thru list of users>

:ENDIF

This should work fine, but it rapidly increases the number of lines in the file.
What I'd like to do is compare a group of people in 1 shot. Something like:

Code: [Select]IF [NOT] "%username%"=="JohnDoe" OR "JaneDoe" OR "FredDoe" GOTO NEXT1
@net use K: /delete
@net use K: "\\Folder that all 3 users store files in" /no
GOTO ENDIF

:NEXT1
IF [NOT] "%username%"=="VIP1" OR "VIP2" OR "VIP3" GOTO NEXT1
@net use K: /delete
@net use K: "\\Folder that only VIP users store files in" /no
GOTO ENDIF

:NEXT2
<and so on and so forth>

:ENDIF

If it exists, does anyone have the correct syntax I should use to compare a group of usernames in this manner? Please let me know if I can clarify anything.Code: [Select]IF NOT "%username%" equ "JohnDoe" set /a num+=1
IF NOT "%username%" equ "JaneDoe" set /a num+=1
IF NOT "%username%" equ "FredDoe" set /a num+=1

if %num% equ 3 goto NEXT1


Works just fine - THANKS!

I did run into the problem of the %username% containing upper case characters & that throws things off a bit.
I.E. JohnDoe != johndoe

Next challenge up!

*edit*

Easy enough...

Code: [Select]IF /i NOT "%username%"=="JohnDoe" GOTO NEXT1

4640.

Solve : make batch save %var% to .txt and retrieve %var% from .txt?

Answer»

i have this program that can run on the command line (goes faster that way) and i have a .bat that makes it easier to do this what i want is to save where it it up to when it exits using a .txt file so that it has an input file and
makes an output file that becomes the NEW input file and it goes on and on and on(until i stop it)
i WOULD like to name the files 1(the 1st input),2,3,4,5,6,...

p.s no files are deleted in the process and i would like to have it run and when i want to stop i can and when i start it again it can GO from where it left off (that is why i want to save a variable to a .txt file

p.s.s
the program is evolve 4.0 and can be found here http://www.stauffercom.com/evolve4/
some more info about the command line is here http://www.stauffercom.com/evolve4/evolve_batch.html

[attachment deleted by admin]Quote from: Ädamas on May 10, 2009, 04:47:31 AM

i have this program that can run on the command line (goes faster that way) and i have a .bat that makes it easier to do this what i want is to save where it it up to when it exits using a .txt file so that it has an input file and
makes an output file that becomes the new input file and it goes on and on and on(until i stop it)
i would like to name the files 1(the 1st input),2,3,4,5,6,...

p.s no files are deleted in the process and i would like to have it run and when i want to stop i can and when i start it again it can go from where it left off (that is why i want to save a variable to a .txt file

p.s.s
the program is evolve 4.0 and can be found here http://www.stauffercom.com/evolve4/
some more info about the command line is here http://www.stauffercom.com/evolve4/evolve_batch.html

Ok...

echo %var%>filename.txt
rem The above line sends the contents of %var% to filename.txt
set /p var=rem The above line recieves the contents of filename.txt and sets %var% as it.

Understand?it is not writeing to the file but it is reading from it
this is my batch
Code: [Select]@echo off
:setup0
echo do you want to start from where you left off[y\n]
set/p "cho=>"
if %cho%==y goto setup1
if %cho%==n goto setup2

:setup1
cls
echo time
set/p "time=>"
echo input
set /p in=<filename.txt
echo %out%
echo output
set/p "out=>"
echo are the time,input and output correct[y/n]
set/p "cho=>"
if %cho%==y goto evolve_b
if %cho%==n goto setup
%out%>filename.txt

:setup2
cls
echo time
set/p "time=>"
echo input
set/p "in=>"
echo output
set/p "out=>"
echo are the time,input and output correct[y/n]
set/p "cho=>"
if %cho%==y goto evolve_b
if %cho%==n goto setup

:evolve_b
cd C:\Program Files\Evolve
evolve_batch
evolve_batch s %time% %in%.evolve %out%.evolve

%out% is the variable i want to save and i want to make %in% have the value of %out% when i start it againThe easiest way to retrieve a value from a file is
Set /P in=
Note this will read only the first line of filename.ext and will put the value into %in%

Grahamit now reads from the file and saves to the file but not with the value of %out% instead it deletes all the text in the .txt Code: [Select]@echo off & setlocal
:setup0
if not exist save.txt goto setup2
echo do you want to start from where you left off[y\n]
set/p "cho=>"
if %cho%==y goto setup1
if %cho%==n goto setup2
goto:eof

:setup1
for /f "tokens=*" %%a in (save.txt) do %%a
set out
goto:eof

:setup2
set/p out=enter string:
echo variable out=%out% will be saved as save.txt
>save.txt echo set out=%out%
sample untested code@ Reno

where do you put the code in the batch every time i answer yes to the "do you want to start from where you left off[y\n]"
it exits the batch
Code: [Select]@echo off & setlocal
:setup0
if not exist save.txt goto setup3
echo do you want to start from where you left off[y\n]
set/p "cho=>"
if %cho%==y goto setup1
if %cho%==n goto setup2
goto:eof

:setup1
cls
for /f "tokens=*" %out% in (save.txt) do %out%
echo time
set/p "time=>"
echo input
echo %out%
echo %out%
echo output
set/p "out=>"
echo are the time,input and output correct[y/n]
set/p "cho=>"
if %cho%==y goto evolve_b
if %cho%==n goto setup

:setup2
cls
echo time
set/p "time=>"
echo input
set/p "in=>"
echo output
set/p "out=>"
echo are the time,input and output correct[y/n]
set/p "cho=>"
if %cho%==y goto evolve_b
if %cho%==n goto setup

:setup3
set/p out=enter string:
echo variable out=%out% will be saved as save.txt
>save.txt echo set out=%out%

:evolve_b
cd C:\Program Files\Evolve
evolve_batch
evolve_batch s %time% %out%.evolve %out%.evolve

i changed it a bit it would not fit



i got headache
i only give example how to save a bunch of variables into a txt file and later retrieve the vars the next time batch is executed.

for /f "tokens=*" %out% in (save.txt) do %out% <--- incorrect for loop syntax
:setup1 <--- let's say this is sort of a "batch function" in OOP term, you have to put goto:eof at the end of each function except the last one, or the the next line of code will be executed


Code: [Select]:evolve_b
cd C:\Program Files\Evolve
evolve_batch
evolve_batch s %time% %out%.evolve %out%.evolvewhat are the value of var time,out,evolve,out on the following 2 condition:
1.do you want to start from where you left off[y\n] Y
2.do you want to start from where you left off[y\n] N

it would be nice if you can gives example as i don't quite understand the problem.
Quote
what are the value of var time,out,evolve,out on the following 2 condition:
1.do you want to start from where you left off[y\n] Y
2.do you want to start from where you left off[y\n] N
1) time is hours(h),minutes(m),SECONDS(s) or steps(u)
so when i type in the time it is
45s(seconds)
30m(minutes)
24h(hours)
4000u(steps)

in is the starting conditions of the simulation (in this case it is the previous out file)

.evolve is not a variable it is just the files extension

out is the output file


2)in this case i set the varables to anything i want to.
hmm, maybe something like below works??

Code: [Select]@echo off & setlocal

:setup
set/p c=do you want to start from where you left off [y\n] :
echo.%c%|findstr/ix "y n yes no">nul || goto:setup

if /i %c:~,1%.==y. for /f "tokens=*" %%a in (save.txt) do set %%a
if /i %c:~,1%.==n. (
set/p var_time=time :
set/p var_in=input :
set/p var_out=output :
set var_>save.txt
)

:validateYesNo
echo evolve_batch s %var_time% %var_in%.evolve %var_out%.evolve
set/p c=are the time,input and output correct [y/n] :
echo.%c%|findstr/ix "y n yes no">nul || goto:validateYesNo

if /i %c:~,1%.==n. goto:setup
cd C:\Program Files\Evolve
evolve_batch
evolve_batch s %var_time% %var_in%.evolve %var_out%.evolvewow Reno
that one looked very good but i wanted it to set %var_in% to what %var_out% was last timeCode: [Select]@echo off & setlocal & set c=n

if not exist save.txt goto skip
:setup
set c=&set/p c=do you want to start from where you left off [y\n] :
echo.%c%|findstr/ix "y n yes no">nul || goto:setup

:skip
if /i %c:~,1%.==y. for /f "tokens=*" %%a in (save.txt) do set %%a
if /i %c:~,1%.==n. (
set/p var_time=time :
set/p var_in=input :
)
set/p var_out=output :

:validateYesNo
echo evolve_batch s %var_time% %var_in%.evolve %var_out%.evolve
set c=&set/p c=are the time,input and output correct [y/n] :
echo.%c%|findstr/ix "y n yes no">nul || goto:validateYesNo

if /i %c:~,1%.==n. goto:setup
>save.txt echo var_time=%var_time%
>>save.txt echo var_in=%var_out%
cd C:\Program Files\Evolve
evolve_batch
evolve_batch s %var_time% %var_in%.evolve %var_out%.evolve
CODE UPDATED. CHECK POST #11i wanted it to set %var_in% to what %var_out% was last time it was ran so

//first run
%var_in%=1
%var_out%=2
//second run
%var_in%=2(from save.txt{so i don't need to enter this})
%var_out%=3
//third run
%var_in%=3(again from save.txt)
%var_out%=4

and so on

perfect THANK you so much
4641.

Solve : Characters with accent does not appear in DOS, does not appear in Windows?

Answer»

Hi,
There is a problem with hungarian characters showing. If I create a file in dos with the following command
DIR /n >c:\temp.txt

I can open the file in dos correctly even with an editor (edit.com), however in windows xp for examle notepad or whatever instead the Hungarian characters (LIKE é á ű ú ő ó ü) it displays weard symbols. Everything is set in autoexec.nt and config.sys to the hugarian settings with the 852 code format, but still no result. How could I MAKE applications in windows to show the appropriate result of my command.
Please Help!! If its not the right forum, please tell me where to write or forward the msg to the right department.
Quote from: bajroly on May 14, 2009, 04:07:43 AM

Hi,
There is a problem with hungarian characters showing. If I create a file in dos with the following command
dir /n >c:\temp.txt

I can open the file in dos correctly even with an editor (edit.com), however in windows xp for examle notepad or whatever instead the Hungarian characters (like é á ű ú ő ó ü) it displays weard symbols. Everything is set in autoexec.nt and config.sys to the hugarian settings with the 852 code format, but still no result. How could I make applications in windows to show the appropriate result of my command.
Please Help!! If its not the right forum, please tell me where to write or forward the msg to the right department.

Try opening microsoft word, and putting the characters in there. Then save the file as PLAIN TEXT FORMAT (.txt). And you will also need to change your notepad font if you want to view them in notepad, one of the System fonts should do it I think...Hi,
Thanks for helping me out. I changed the font style in Notepad to Terminal and it showed up as I expected.
Thank you!
4642.

Solve : Findstr s/ "# and other special characters?

Answer»

I've searched this site and others and still can't seem to solve this problem - a newbie problem I'm sure. I've tried /l and /C:string but it doesn't fix the problem either.

I'm searching files for text strings to make sure they've been updated. Unfortunately the strings contain special characters. I've been ABLE to resolve other characters such as %program% by using %%program%% but for some REASON replacing #string with ##string is not working.

I'm running a .bat FILE where I'm trying to find "#Role = VPMADMIN.ADMIN,VPMDESIGNER.VPM" with findstr commands like;
findstr /s "##Role = VPMADMIN.ADMIN,VPMDESIGNER.VPM" fileabc.txt

Also, I'm trying to find "ISPAM9InstallPath=%programfiles%\CAA_APPS\%%DSI%%\intel_a\fileabc.txt"
I'm using find /c "ISPAM9InstallPath=%%programfiles%%\CAA_APPS\%%DSI%%\intel_a\fileabc.txt"
The output shows that it's converted the %% to % but the findstr returns ==1 (not FOUND). I've checked the file and know it's there. (actually I copied the string into the .bat and added the extra %'s).

Any ideas?
(THANKS, Dave)
Use spaces to separate multiple search strings unless the argument is prefixed
with /C. For example, 'FINDSTR "hello there" x.y' searches for "hello" or
"there" in file x.y. 'FINDSTR /C:"hello there" x.y' searches for
"hello there" in file x.y.

\x Escape: literal use of metacharacter x

Code: [Select]C:\>findstr /c:"#Role = VPMADMIN.ADMIN,VPMDESIGNER.VPM" text.txt
#Role = VPMADMIN.ADMIN,VPMDESIGNER.VPM

C:\>findstr /c:"ISPAM9InstallPath=\%programfiles\%\CAA_APPS\\%\%DSI\%\%\intel_a
\fileabc.txt" text.txt
ISPAM9InstallPath=%programfiles%\CAA_APPS\%%DSI%%\intel_a\fileabc.txtWell,,,, The \ worked for the # but not for the %. here is my command and the result;
findstr /s /c:"ISPAM9InstallPath=\%programfiles\%\CAA_APPS\\%DSI\%\intel_a
findstr /s /c:"ISPAM9InstallPath=\\CAA_APPS\\\intel_a\" fileabc.txt

When I use;
findstr /s /c:"ISPAM9InstallPath=%%programfiles%%\CAA_APPS\%%DSI%%\intel_a"
the DOS window shows that it's been changed to;
findstr /s /c:"ISPAM9InstallPath=%programfiles%\CAA_APPS\%DSI%\intel_a"
but it still comes back as "not found".

using the /c: seems to have no effect.
I then tried the /x and changed the search string to just a portion of the string in the target file. It printed the full text to the output file. I would have expected not found because the line contained more characters that that of the search argument.

Keep in mind, I'm not entering these commands from a cmd line interactively, I'm using a .bat file.

I wonder if this has something to do with executing the commands from within a .bat file?
FOUND the problem. Once I used the %% I apparently then needed to also use the \\. Funny thing is that in using \ or \\, the DOS window showed that it was searching for ISPAM9InstallPath=%programfiles%\CAA_APPS\%DSI%\intel_a"

Here's what ended up working.
FINDSTR /S "ISPAM9InstallPath=%%programfiles%%\\CAA_APPS\\%%DSI%%\\intel_a"

4643.

Solve : how can i stop batch/cmd from erasing old lines??

Answer»

Quote from: Reno on May 20, 2009, 09:28:36 AM

answer: post #2

Worth repeating
i chaged the
Code: [Select]evolve_b.bat>a.txt
to
Code: [Select]evolve_batch.exe>a.txt
and it now writes this to the .txt
Code: [Select]
Usage:
evolve_batch s <time-spec> <infile.evolve> <outfile.evolve>

evolve_batch p <infile.evolve>

evolve_batch k <kforth_file>

evolve_batch = <file1.evolve> <file2.evolve>

evolve_batch rc <file.evolve> [x y]

evolve_batch 1S <infile.evolve> <outfile.evolve>

ERROR: No arguments.


which is some of the text i want to copy i would like to copy this and what is PUT below it
Code: [Select]@echo off & setlocal & set c=N
title evolve_b

if not exist save.txt goto skip
:SETUP
set c=&set/p c=do you want to start from where you left off [y\n] :
echo.%c%|findstr/ix "y n yes no">nul || goto:setup

:skip
if /i %c:~,1%.==y. for /f "tokens=*" %%a in (save.txt) do set %%a
if /i %c:~,1%.==n. (
set/p var_time=time :
set/p var_in=input :
)
set/p var_out=output :

:validateYesNo
echo evolve_batch s %var_time% %var_in%.evolve %var_out%.evolve
set c=&set/p c=are the time,input and output correct [y/n] :
echo.%c%|findstr/ix "y n yes no">nul || goto:validateYesNo

if /i %c:~,1%.==n. goto:setup
>save.txt echo var_time=%var_time%
>>save.txt echo var_in=%var_out%
cd C:\Program Files\Evolve
>temp.txt evolve_batch.exe
type temp.txt
type temp.txt>>a.txt
>temp.txt evolve_batch.exe s %var_time% %var_in%.evolve %var_out%.evolve
type temp.txt
type temp.txt>>a.txt

notes: with this method, you will lose the real-time display of evolvebatch.exethank you for helping me Reno
and i don't care that it does not display the info when it's run i usually leave it going unattended for an hour or so unless i want to save the info (by copying and pasting it in to excel for graphing which i don't have to do any more)
so THANK you again for helping me no problem.

glad the script works well
4644.

Solve : A little help with batch?

Answer»

copy con is an old command that usually used to create a file.
whatever you type in the console will be echoed back to std-out.
therefore you use 'copy con>out.txt', to redirect the std-out to a file.
then to end press CTRL-Z.

but if you are refering to CON(SOLE).
if you do this
type nul>test.txt 3>&1
you will lose the command prompt, whatever command you type, the console output will be redirected to file 'test.txt'
the '3' REFER to console, but i can't FIND any good use for it.con is both an input, and output device. in the context of "copy con File" it is an input device. Therefore it copies the standard input to the file until Ctrl-Z, or EOF, is pressed.

copy con will copy a file to the screen. the output cannot be piped, since the output isn't on stdout but rather directly to the output console, the screen.



the numbers 1 through 3 are actually valid filehandles, and represent the standard Input, output, and error streams.Quote from: BC_Programmer on June 03, 2009, 04:59:09 PM

copy <file> con will copy a file to the screen. the output cannot be piped, since the output isn't on stdout but rather directly to the output console, the screen.
copy con - copy from file to console, great, i never the syntax exist. for clarification, i usually use 'copy con file', not 'copy con>file', a mistake i made in the above post.
now if only type 'copy con', whatever i type+enter is displayed twice, so i believe the extra echoed string is save into file when using 'copy con file'

Quote from: BC_Programmer on June 03, 2009, 04:59:09 PM
the numbers 1 through 3 are actually valid filehandles, and represent the standard Input, output, and error streams.
i agree it's actual file handles in windows.

but in nt batch, i am sticking with this until i am PROVEN wrong:
1> std-out
2> std-err
3> console
not sure about std-in represent what number.CON represents both stdin and stdout- it DEPENDS on the context.

for example, copy con would be stdin, since it's reading from con. copy con would be stdout, since it's WRITING to the console.
4645.

Solve : Batch file - Open PDF and Display at 100%?

Answer»

Hi everyone. Please forgive my IGNORANCE with Batch files but...

I want to create a very simple Batch file that 1) opens a PDF Adobe Reader and 2) set the zoom level of the PDF to 100%. Here's what I am using now:

start your_important_document.pdf

This simple one-LINE script seems to takes care of task #1 just fine... but how do I accomplish #2? This doc might help
www.adobe.com/devnet/acrobat/pdfs/pdf_open_parameters.pdfThanks very much for the document link. What would the syntax be for using the "zoom" command in a batch file? (Please forgive my ignorance. Batch files are new to me. I'm using it to open a PDF VIA a button click in a Flash Application.)Have a look on page 5.I see it... I just can't make it work. (When I say I'm a neophyte, sadly I'm not just kidding around. I'm a Flash/Actionscript guy quickly thrust into this Batch file world. My apologies.)

The Adobe document shows this as an example:

Acrobat.exe /A "zoom=100" "my_document.pdf"

but it won't work for me. I'm sure my syntax is off...

Try the command:

start "" "C:\Program Files\Adobe\Reader 8.0\Reader\AcroRd32.exe /a "zoom=100" "path\to\file.pdf"

Adjust the path for Adobe if necessary.I get an error message saying it can't FIND the file. (I've double checked the path and names very carefully, and they are correct.)

In any case, this opens a bigger can of worms. My Flash application will be distributed on a USB drive to users with different versions of different operating systems, so identifying a specific path and application name within the batch file isn't an option, I don't think.

My original "start my_document.pdf" line (without specifying opening Adobe Reader) worked everywhere I tested it. Is there a different solution I'm not seeing?

In any case, thanks so much for your help...Quote

Acrobat.exe /A "zoom=100" "my_document.pdf"
Don't leave just yeat.
Somebody will show up and WRITE a model for you.
Thee tow things to resolve.
1. The name and path of the Adobe reader.
2. The name and path of the PD file you want to show

Are the PDF files always in the same area?
Code: [Select]C:\>type 2pdfdos.bat

copy c:\readiris\readiris.pdf "C:\Program Files\Adobe\Reader 9.0\Reader\"

cd "C:\Program Files\Adobe\Reader 9.0\Reader\"

Acrord32.exe /A "zoom=100" "readiris.pdf"C:\>



Output:

C:\>2pdfdos.bat

C:\>copy c:\readiris\readiris.pdf "C:\Program Files\Adobe\Reader 9.0\Reader\"
1 file(s) copied.

C:\>cd "C:\Program Files\Adobe\Reader 9.0\Reader\"

C:\Program Files\Adobe\Reader 9.0\Reader>Acrord32.exe /A "zoom=100" "readiris.pdf"

C:\Program Files\Adobe\Reader 9.0\Reader>

http://partners.adobe.com/public/developer/en/acrobat/sdk/pdf/
intro_to_sdk/DeveloperFAQ.pdf#page=27

Quote
<<<<"
All the following information from the above document. )

How Do I Use Command Lines with Acrobat and Adobe Reader on Windows?

These are unsupported command lines, but have worked for some developers. There is no documentation for these commands other than what is listed below. You can display and print a PDF file with Acrobat and Adobe Reader from the command line.

NOTE:All examples below use Adobe Reader, but apply to Acrobat as well. If you are using Acrobat, substitute Acrobat.exe in place of AcroRd32.exe on the command line.AcroRd32.exe pathname — Executes Adobe Reader and displays the file, whose full path must be provided.

Other options for the command line are:
AcroRd32.exe /p pathname — Executes Adobe Reader and displays the Print dialog box.
AcroRd32.exe /t path "printername" "drivername" "portname" — Initiates Adobe Reader and prints a file, whose path must be fully specified, while suppressing the Print dialog box.

The four parameters of the /t option evaluate to path, printername, drivername, and portname (all
strings).
●printername — The name of your printer.
●drivername — Your printer driver’s name, as it appears in your printer’s properties.
●portname — The printer’s port. portname cannot contain any "/" characters; if it
4646.

Solve : Partition using cmd prompt??

Answer»

To further expand on nothlit's recommendation...

Partition MAGIC would be your best bet. Also, the additional hard drive would work as well.

If it were a Vista OS, you could use the "shrink" functionality of diskpart, but unfortunately, XP doesn't have this function.

So, nothlit is correct...

Some additional info Why not try partition tools and there are some free, such as EASEUS Partition Manager...
http://www.softpedia.com/get/System/Hard-Disk-Utils/EASEUS-Partition-Manager.shtmlHi, i tried the above method to partition my 120GB tumbdrive, but it does not work.

diskpart

list disk

select disk 1 (in my case its disk 1 for my tumbdrive)

create partition extended [10000]



but all that COMES out is the who list of commands that appears if you type "help" in the command prompt.

any suggestions?
thanks

I saw you were having some trouble a while back?
If'n you still are with the partition with cmd.. I saw that once you were in the DISKPART and typed "help" and got the prompt with everything, you got a list of things.
If you typed "partition" you got the help list again, so type
"CREATE PARTITION"

and that should get you a list that looks something like this:
DISKPART> CREATE PARTITION

Microsoft DiskPart version 5.1.3565

EFI - Create an EFI system partition.
EXTENDED - Create an extended partition.
LOGICAL - Create a logical drive.
MSR - Create a Microsoft reserved partition.
PRIMARY - Create a primary partition.

and you choose WHICHEVER you want and it should GUIDE you though the rest I'm assuming?He hasn't been back since May of last Year...Quote from: michelleAudacity on May 20, 2009, 03:29:06 PM

I saw you were having some trouble a while back?
If'n you still are with the partition with cmd.. I saw that once you were in the DISKPART and typed "help" and got the prompt with everything, you got a list of things.
If you typed "partition" you got the help list again, so type
"CREATE PARTITION"

and that should get you a list that looks something like this:
DISKPART> CREATE PARTITION

Microsoft DiskPart version 5.1.3565

EFI - Create an EFI system partition.
EXTENDED - Create an extended partition.
LOGICAL - Create a logical drive.
MSR - Create a Microsoft reserved partition.
PRIMARY - Create a primary partition.

and you choose whichever you want and it should guide you though the rest I'm assuming?



will try when i have the time. Thanks for your help. really appreciate it ^^
4647.

Solve : manipulating files?

Answer»

Hi All!!

I have multiple files in a folder! I have to search in these files and, depending on the content of them, save them in specific folders.

I need HELP creating a batch file to perform this task.

Thanks for the help.so depending on what kind of string of words are inside the file, send to another folder? brain deadAn example:

I have a folder (c:\receive) with many TXT files.
Each file has an indefinite sequence of characters.
In the FIRST line of each file is a sequence (string) of 3 characters that identify the type of information.
Depending on this information the file should be moved to another folder.

As below:

- c:\receive\file1.txt -> have the string "ABF" -> move to c:\folder1;

- c:\receive \file2.txt -> have the string "CZ7" -> move to folder c:\folder2;

Thanks for the first post.if you have Python for windows, here's an alternative solution
Code: [Select]import os,glob
currentdir = os.path.join("c:\\","test") # directory c:\test where TXT files are
os.chdir(currentdir)
for file in glob.glob("*.txt"):
firstline = open(file).readline().strip()
if firstline == "ABF":
destination = os.path.join("c:\\","folder1")
elif firstline == "C27":
destination = os.path.join("c:\\","folder2")
os.rename(file, os.path.join(destination,file) #move to specific folder

thank you for the post.
I try to download the python for windows and do the test.
I answer if a error occurs or if it right.when I try to run the code, the error is below:

Code: [Select]>>> import os,glob
>>> currentdir = os.path.join("d:\\","receb")
>>> os.chdir(currentdir)
>>> for file in glob.glob("*.ekt"):
... firstline = open(file).readline().strip()
... if firstline == "BFT":
... destination = os.path.join("d:\\","prod")
... elif firstline == "MZ7":
Traceback ( File "<interactive input>", line 5
elif firstline == "MZ7":
^
SyntaxError: invalid syntax

This is my first time on Python! I looked at the documentation and could not be found.
Please check and return.you must properly indent your Python code. indentation is very important in Python if not, your script won't run. also, what you are using is the INTERPRETER where you type in your commands one by one.. its one way to test your code, however for this case, please put the code in a file, save it as whatever name you want to give. eg myscript.py , then on the command line, type
Code: [Select]c:\test> python myscript.py

you must indent your if / else statement properly
Code: [Select]....
if firstline == "BFT":
#do something
elif firstline == "M27": <------ this line align properly with the previous "if"
elif firstline == "M27": <------ this is wrong...

please look at the Python documentation SITE, especially the tutorial for Python beginnerYes, unlike every other language python doesn't ignore most whitespace, and instead takes the thoughtful approach and makes it part of the syntax. confusing at first, but it makes for more readable code in the end, I would imagine.Quote from: BC_Programmer on June 03, 2009, 06:16:10 PM

but it makes for more readable code in the end, I would imagine.
you are right. especially if you have a large project. also, Python doesn't use unnecessary symbols like $,% or open and close braces for if/else, loops...thereby increasing readability of code.Hi all,

Thank you for your help.

Finally I got the script to run correctly and without error.
Below the final script:

Code: [Select]import os,glob
currentdir = os.path.join("d:\\","receb")
os.chdir(currentdir)
for file in glob.glob("*.ekt"):
firstline = open(file).readline().strip()
text = firstline.find("BFT")
text2 = firstline.find("MZ7")
text3 = firstline.find("PEA")
if text >= 0:
destination = os.path.join("d:\\","prod")
elif text2 >= 0:
destination = os.path.join("d:\\","mp")
elif text3 >= 0:
destination = os.path.join("d:\\","pea")
os.rename(file, os.path.join(destination,file))
text = 0
text2 = 0
text3 = 0

I will devote even more to learn this language.
Thank you very much even.Quote from: lchbusch on June 04, 2009, 09:12:01 AM
Hi all,

Thank you for your help.

Finally I got the script to run correctly and without error.
Below the final script:

Code: [Select]import os,glob
currentdir = os.path.join("d:\\","receb")
os.chdir(currentdir)
for file in glob.glob("*.ekt"):
firstline = open(file).readline().strip()
text = firstline.find("BFT")
text2 = firstline.find("MZ7")
text3 = firstline.find("PEA")
if text >= 0:
destination = os.path.join("d:\\","prod")
elif text2 >= 0:
destination = os.path.join("d:\\","mp")
elif text3 >= 0:
destination = os.path.join("d:\\","pea")
os.rename(file, os.path.join(destination,file))
text = 0
text2 = 0
text3 = 0

I will devote even more to learn this language.
Thank you very much even.

good for you... some "enhancement" to your script.
1) don't have to use find anymore.. you can use "in" operator
2) next time ,you can use a dictionary to store. eg
Code: [Select]paths = {
"PEA" : os.path.join("d:\\","pea"),
"MZ7" : os.path.....
}

final code can be shortened:
Code: [Select]import os,glob
currentdir = os.path.join("d:\\","receb")
os.chdir(currentdir)
for file in glob.glob("*.ekt"):
firstline = open(file).readline().strip()
if "BFT" in line:
destination = os.path.join("d:\\","prod")
elif "MZ7" in line:
destination = os.path.join("d:\\","mp")
elif "PEA" in line:
destination = os.path.join("d:\\","pea")
os.rename(file, os.path.join(destination,file))

Dear gh0std0g74,

One more time, thanks a lot!!

I CHANGED the script as its your indication!

I'll see how that dictionaries are used to implement in a new opportunity.

4648.

Solve : Windows Crashed Need To Backup/Transfer/Move files to my External Hard Drive?

Answer»

Thank you for your help.

I have a dell 1710 Windows Vista. My Windows shut down and I never backed up any of my files. Dos is working great but takes a long TIME. I was wondering if there is a command that will transfer everything from my C: drive an either move/transfer/or copy all the files at once to my External E: drive.

Right now I'm having to me each directory at a time within each directory and that is just TAKING forever.

Thanks again for your help

JoeSmoeBy DOS, what exactly do you mean?

Also, can you give us some more insight to the problem? What exactly happens? Any error messages? What did you do before the problem?Thank you for your help.

I'm using Dos to backup my files to my external hardrive. After all my files are moved I'm going to recover my whole computer and set it back to factory settings. Like when I first bought it.

I'm trying to save/move/copy or transfer the files to my external hardrive before I do this.
I know the command to move 1 directory at a time. This is taking a very long time. What I'm wanting to know is can I transfer my whole c: drive to me external hard drive using a dos command.

I was listening to an audio file before my windows just shut down. I have not been able to repair windows or even go back to a previous date that windows was working properly. It seems the whole file is corrupt or just shutdown and will not work at all.

I hope I answered your questions correctly.

Thanks

JoeSmoeI ASSUME you've tried Safe Mode?

Have you tried a Repair Install with the Vista DVD?

As for your initial question, I'm actually not very familiar with Vista. How did you get into DOS? Is it Command Prompt by any chance?Safe actually does not come up. It offers to options when I turn on my computer. 1st one is to do a repair. the 2nd one is to skip it and just go directly opening up windows. The second one does not work. The screen stays black. I assume this is because windows is not COMING up.

Under the 1 section after it tries to repair there are other options. One of the options is to operate in Dos.

I just need to understand the command for transferring all the files from one drive to the next drive. So from C: to E:(Which is my external Hardrive)

Dos Windows XP is very similar to Vista.

You have a guess to what the dos command might be?

Thanks,

JoeSmoeHave a look at the Copy command.

Code: [Select]Copy /?
For example:

Code: [Select]copy "C:\path\to\file.txt" "E:\directory\file.txt"
You can do it with folders too:

Code: [Select]copy "C:\folder" "E:\folder"
I would avoid copying the entire drive. Look for specific files/folders, especially important data that you absolutely need.

Note: you may WANT to look at the xcopy command as well.I will give it a try

Thank you again

JSGood luck.

4649.

Solve : For loop Skip=%var%?

Answer»

As the title depicts, in a for loop, I need skip to equal %var%. I tried for /f "skip=%var% delims=:" and for /f "delims=: skip=%var%" but it SAYS that it was unexpected at this time.Since you didn't post your code or say what OS you are using we can't see where your problem is

However, this works

Code: [Select]@ECHO off
echo 1:a>test.txt
echo 2:b>>test.txt
echo 3:c>>test.txt
echo 4:d>>test.txt
set var=2
for /f "tokens=1-2 skip=%var% delims=:" %%A in (test.txt) do (
echo %%A %%B
)
Code: [Select]3 c
4 dQuote from: Dias de verano on MAY 21, 2009, 01:00:49 PM

Since you didn't post your code or say what OS you are using we can't see where your problem is

However, this works

Code: [Select]@echo off
echo 1:a>test.txt
echo 2:b>>test.txt
echo 3:c>>test.txt
echo 4:d>>test.txt
set var=2
for /f "tokens=1-2 skip=%var% delims=:" %%A in (test.txt) do (
echo %%A %%B
)
Code: [Select]3 c
4 d
Strange...it didn't work for me the FIRST time.

Quote from: Dias de verano on May 21, 2009, 01:00:49 PM
say what OS you are using
It SHOWS that beside my post...
4650.

Solve : want to remove particular string from a dat file through batch file.please help?

Answer»

I have to extract some set of record from the delivery FILE named delivery-2009.6.1-1.10.29172.dat based on the input from another file CALLED component.txt using a batch file having code as below.
=============================================
@echo off
REM *****************************************************************************
REM Batch file to read components from a file and extract matching lines from
REM archived delivery.dat files
REM
REM Input files: components.txt - list of components to be SEARCHED for
REM delivery*.dat - all archived delivery.dat files
REM Output file: deliver_results.dat - list of all delivery*.dat records with a
REM component in components.txt
REM ******************************************************************************

REM set value=

setlocal EnableDelayedExpansion

for /f "tokens=*" %%a in ('type components.txt 2^>NUL') do (
set value=%%a
echo value=!value!
findstr /s %%a delivery*.dat >> deliver_results.dat

if %errorlevel%==0 (
echo !value! Found - logged files into deliver_results.dat
) else (
echo No matches found
)
)
=============

I am not getting desired result in deliver_results.dat file.

In the output file I am seeing that always file name from which the record was extracted is showng at the beginning of the record which I don't want.Please suggest what can be done so that file name doesn't appear at the beginning.


Input component.txt file looks like

3103458901
0031029107
and so on

Input delivery file named delivery-2009.6.1-1.10.29172.dat looks like

"100026390","06 ","KI3","3103458901/KI3 ","RECEIPT"
"100025696","07 ","LE3","0031004367/LE3 ","RECEIPT"

Output deliver_result.dat file looking like

delivery-2009.6.1-1.10.29172.dat:"100026390","06 ","KI3","3103458901/KI3 ","RECEIPT"

I don't want this file name "delivery-2009.6.1-1.10.29172.dat:" to be appearing in deliver_results.dat.
output should be like the file delivery-2009.6.1-1.10.29172.dat ..

Please modify the code so that I can get desired result.That will be great help.
this is not batch. if you have Python on windows
Code: [Select]import os,glob
component="component.txt"
comp=open(component).read().split("\n")
path=os.path.join("c:\\","test")
os.chdir(path)
for files in glob.glob("delivery*"):
for line in open(files):
line=line.strip()
oline=line.split(",") #split the line on comma
#try to get 3103458901 from "3103458901/KI3 "
number = oline[3].split("/")[0].replace('"',"")
if number in comp:
print ','.join(oline)
save the above myscript.py and on command line:
Code: [Select]C:\test>python test.py > delivery_result.dat

as for the batch part where you don't want the filename, set delims to ":" and set also your tokens (i believe you now how to use it already)...then use the for loop to get rid of it.type delivery*.dat|findstr/sl "%%a">>deliver_results.dat
Quote from: Reno on June 05, 2009, 12:48:53 AM

type delivery*.dat|findstr/sl "%%a">>deliver_results.dat

findstr can find MULTIPLE files, so type is not needed
Code: [Select]findstr ..... delivery*dat >> results.dat
Quote from: gh0std0g74 on June 05, 2009, 01:45:38 AM
findstr can find multiple files, so type is not needed
Code: [Select]findstr ..... delivery*dat >> results.dat

dude, it will display the filename in front of the found line when use in conjunction with file mask delievery*.dat. therefore type is needed to pipe into findstr.

after testing, i revised a bit on the code, it should be:
Code: [Select]type delivery*.dat 2>nul|findstr/sl "%%a">>deliver_results.datCode: [Select]FOR /F "tokens=2* delims=:" %%k in ('findstr /i %%a *.txt') do ( echo %%k >> newfile )