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.

3201.

Solve : insert line in text file with loop?

Answer»

Hello,

I'm a complete N00B in scripting, but I'm pretty DESPERATE so I have to ask this question.

I want to insert a line in a text file with a batch. But this have to happen once in every ten LINES, till the end of the file.

Can somebody help me with this rather simple question? LOOKS like homework... but until you prove that it isnt, try to useCode: [Select] for /? in cmdQuote from: devcom on April 08, 2009, 09:36:29 AM

looks like homework... but until you prove that it isnt, try to useCode: [Select] for /? in cmd

The rule of thumb is "Innocent untill proven guilty", which most people don't seem to follow in here...if you are able to use tools for string processing, such as gawk for windows(see my sig),
Code: [Select]C:\test>more file.txt
line 1
line 2
line 3
line 4
line 5
line 6
line 7
line 8
line 9
line 10

C:\test>gawk "NR%2==0{print;print \"text\";next}1" file.txt
line 1
line 2
text
line 3
line 4
text
line 5
line 6
text
line 7
line 8
text
line 9
line 10
text

the example prints "text" for every 2 lines.I'm actually still trying to figure out what self-respecting school WOULD teach batch.Thanks for the comments so far.
I'm not able to use tools like gawk or sed. It isn't possible to use internet on the machine I have to do the task I described.

I know it sounds lazy but at the moment I don't have the time to teach myself how to do the trick, so can anybody help me with this?
3202.

Solve : Computer stuck at start up?

Answer»

Hi I have an old desktop computer (Windows 95?) which used to work fine until we moved house. it was in storage (did not get damp ETC) and now it will not work. It turns on fine and goes through the page where you can press F2 for set up options etc and then goes to the big blue screen saying with clouds saying Windows 95 but never goes any further. Does anyone know what I can do to sort this out? All i want to do is retrieve some files off of the computer (a big MUSIC playlist thing) and transfer it ONTO another computer but I cannot fix it. The monitor is fine as it works on the other computer we have. Any ideas would be GRATEFULLY received! ThanksIf thats all you need, whip the disk out and plug it into your new pc, or stick it into a usb caddy - it will then be very easy to copy off anything you want!hello again! thankyou very much for your reply. sorry to be a total computer moron but how do i remove the disk? what disk?! thanks!Slave Drive Tutorial

3203.

Solve : How doi get the old file ccording to time it was created??

Answer»

Quote from: DIAS de verano on April 08, 2009, 03:08:46 AM

/a-d - directory attribute negated (don't include directories in list)
/a-d - directory attribute negated (don't include directories in list) + EXPLICIT include hidden&system file(s)

Quote from: kishorei on April 08, 2009, 04:09:28 AM
How do i move all these files orderly date wise to a specified folder?
care to give some example?Test1.txt craeted at 2/4/09
Test2.txt craeted at 3/4/09
Test3.txt craeted at 4/4/09
Test4.txt craeted at 5/4/09

First i want to sort the above files by date wise and move the old file first.
Then i want to sort the REMAINING THREE files and move the old file and so on..


CODE: [Select]@echo off & setlocal enabledelayedexpansion

for /f "tokens=*" %%a in ('dir/b/od/tc/a-d *.txt') do (
echo.
dir/tc "%%a"|find/i ".txt"
set/p c=Move %%a (y/n^)?
for %%b in (y Y) do if !c!.==%%b. move "%%a" c:\temp\ && echo done
)
3204.

Solve : Minimise the dos window?

Answer»

Is it not possible to minimise the dos window ?
THANKS
devduttaaClick the square with a minus sign.
Dias, you're doing it wrong, the response should have been something like:


Minimizing Console windows is a black art practices only by a few seasoned veterans. Most perform this task by writing a small C program that uses findWindow() to locate the appropriate console window and then calling SetWindowState() to set the window the the minimized position.


Alternatively, you can click the minimize button, but all the seasoned veterans will laugh at you.He's going to start ANOTHER thread anyway.
that's true, but we MAY as well amuse ourselves in the process. Well,get amusements. But I think I will also get amusement if if tou help
to write the required C code. THANKS
devduttaaFirst explain what you WANT to do. Start the command window minimised, or minimise an already running window?
Quote from: devduttaa on April 09, 2009, 10:33:30 AM

Well,get amusements. But I think I will also get amusement if if tou help
to write the required C code. THANKS
devduttaa


LMAO

when did C come into this?Quote from: BC_Programmer on April 09, 2009, 10:45:39 AM

LMAO

when did C come into this?

Quote from: BC_Programmer
Most perform this task by writing a small C program
that's what I thought; just confirming...


In any case I'd go with the SECOND option, it may be less hip but it works. also it coincides with the method already provided.

I'd download cmdow.exe and use CMDOW @ /MIN
3205.

Solve : Monitoring processes to trigger an action?

Answer»

Hi there,

I am trying to create a relatively simple batch file that opens two applications when run.

This is OK, but the first application needs a login which may take a user between 5 secs and 5 hours!

Therefore, I would like the second application to run after the login has occured. Monitoring system processes I notice a unique programme runs when the login is completed.

Is it POSSIBLE to add a line to the batch file to 'watch' for this programme and then run the next application?

Many thanks in advance for your help.

Regards

PaulQuote from: PaulB on April 08, 2009, 05:11:46 AM

Therefore, I would like the second application to run after the login has occured. Monitoring system processes I notice a unique programme runs when the login is completed.

how do you notice that programme is running?? what the name of it?
post your current batch code here.Hi there,

I notice the programme is running by going to Windows Task Manager and monitoring the processes. After the user has 'logged in' the same process loads. This is called viewserver.exe.

I would like this process to trigger the next stage of the batch file.

ThanksCode: [Select]@echo off
>$$$.vbs echo q="select * from __InstanceCreationEvent within 1 where " ^& _
>>$$$.vbs echo "targetinstance ISA 'win32_process' and targetinstance.name='viewserver.exe'"
>>$$$.vbs echo getobject("winmgmts:").execnotificationquery(q).nextevent

echo First stage of batch file

for %%a in (cscript//nologo del) do %%a $$$.vbs

echo viewserver.exe creation detected
echo next stage of the batch fileHi Reno, That is brillaint, thanks...

I was using the follwowing but got into trouble. I could sometimes see the error level change, but the next programme would not launch, or both would launch without seeing the trigger..........


@echo off
START C:\Programme1
PING 1.1.1.1 -n 1 -w 1000 >NUL
:LOOP1
tasklist>C:\tasklist.txt
cd c:\
FIND "ViewServer.exe" c:\tasklist.txt
PING 1.1.1.1 -n 5 -w 1000 >NUL
echo %errorlevel%
IF %ERRORLEVEL% EQU 1 GOTO LOOP1 ELSE START C:\SEARCH
DEL c:\tasklist.txt

if you want to check errorlevel for find then you must move that if
Code: [Select]@echo off
START C:\Programme1
PING 1.1.1.1 -n 1 -w 1000 >NUL

:LOOP1
PING 1.1.1.1 -n 5 -w 1000 >NUL
tasklist>C:\tasklist.txt
cd c:\

Find "ViewServer.exe" c:\tasklist.txt
IF %ERRORLEVEL% EQU 1 GOTO LOOP1 ELSE START C:\SEARCH

DEL c:\tasklist.txt
that old code was looking for PINGs errorlevel
3206.

Solve : How to insert a carriage return?

Answer»

I'm trying to merge a lot of archives in one, with WinXP - CMD

With copy *.txt /O myfile.sal

My problem is I have 2 files, a1.txt and a2.txt
a1.txt
1
2
3

a2.txt
a
b
c

The result is
1
2
3a
b
c

I need to insert a carriage RETURN between 3 and a
Is it possible?

Thanks

Luisthis MAY work:
Code: [Select]for /f %%a in ('dir /B *.txt') do (
type %%a >>myfile.sal
echo.>>myfile.sal
)

Perfect!

THANK yo so much!

Luis

3207.

Solve : Problem printing in dos 6.2?

Answer»

try unchecking fast printing direct to port.



Also we should stop following this silly train of thought... if the printer is plugged into your Printer port then we don't need to involve the COM ports. (of course if it IS plugged into a COM port... well that's a different story)

The COM ports are for serial devices- period. Nothing else.

Try unchecking the fast printing... checkbox, see what effect that has. also make sure the port is set to LPT1.BP

Have unchecked fast print to port and confirmed printer set to LPT1.

No joy either printing from Notepad or in WSWin archive document... get the same message on HPlllP display 'MP Load Letter' [calling for letter SIZE rather than A4 in the tray - not PAPER as previously stated].

Control Panel->Printers

select the laserjet. click Setup.

Change the paper source and paper size.

BC

Did what you suggested: Removed the HP Laserjet lllP and selected HP Laserjet.

Was asked to insert disk #6 of the Win 3.1 pack... GOT a message that the UNIDRV [or somesuch] installed in the computer was more recent than the one on th diskette... Did I want to overwrite it? Said No.

There is nothing to do with regard to Changing paper source.. the alternative is 'manual' and the paper size for the printer is A4... always has been for YEARS!

However after all this got the SAME RESULT with attempting to print in Notebook or WSWin archived files.

So I re-installed the HP Laserjet lllP.... and ticked the 'fast printing' box.I meant check the settings for the laserjet 3; I wasn't suggesting to remove anything at all, although I can see how it was interpreted that way.

There is a "setup" button on the resulting dialog, after clicking printers in control panel.



Select the printer from there, and click that setup button.


The laserjet III and it's driver can detect when the selected tray is empty, and prompt for more paper. In this case it might be that a paper source is selected that has no paper.


Quote


There is nothing to do with regard to Changing paper source.. the alternative is 'manual' and the paper size for the printer is A4... always has been for YEARS!

The paper size,paper source, and other settings are stored on the PC. reinstalling the driver has the effect of clearing these settings, regardless of how many "years" it has been set; and you've tinkered with a large number of drivers.


BC

I have re-installed the HP LaserJet lllP and have therefore gone through the panels that you have shown.

There is only an Upper Tray [no other] to select and likewise the paper size is 8 1/2 x 11.

And the PRINTER informs one when the tray is empty or not quite properly inserted in the tray..

And [as layman] cannot quite see why the printer/program is SELECTIVELY printing files in WSWin.... Of course as an expert you are in a better position to suggest probabilties... whereas my focus may lie in long usage...

KenThanks BC,

And sorry Kahawn, kinda doing this blindy.Quote from: macdad- on October 27, 2009, 04:40:02 PM
Thanks BC,

And sorry Kahawn, kinda doing this blindy.

As one who is blind in both eyes...

Am now looking to see if there are any more 'contributors' who will dip their toes and perhaps take the thread to 100!

Has been suggested elsewhere that it is a problem with 'handshaking'... whatever that implies/means... perhaps that is what you [and BC] are driving at?PROGRESS REPORT

Read the HP Printer Manual where it said that to override the Display messages hold down the Alt key and depress the Continue button.

IT WORKS... When the Display shows 'MP Load Letter' it will print the Notepad document as well as the WSWin 'archive' file.

However this must be done for EVERY PRINTOUT. [unless one is printing multiple pages in that document... not checked this as yet].

The Manual also states that the computer software will override any software in the Printer.

So I conclude there is some message in Win 3.1 that brings up the 'MP Load Letter' in the Printer Display.

So are there any experts in Win 3.1 that can identify the problem?

Thanks

PROBLEM SOLVED...

Found that when the printer display showed 'MP Load Paper' I looked at the Page Setup for the document in the Computer and found that they were 8 x 11 1/4... changed them to A4 and Voila! the document printed.

Now why the settings in the documents changed to Letter is a mystery as I have always been using A4 for preparing my files.

In any case I would like to thank macdad and BC for their support and for introducing me to new facets in Dos and Win 3.1.

Ken
It would have changed when you fiddled about with the drivers, or perhaps tweaked something else; the printer page, or more precisely, what shows up on the printer page, is controlled by the driver but that data is stored in... Win.ini, I believe.

Now, if that printer had a more descriptive error message, you might have avoided all this TEDIUM!BC

Thanks for your comment BC

However I feel that the Printer Display is a very small area and the 'message' fills it.. If I were a computer buff [and perhaps 25 years younger] I would have worked it out quicker... with hindsight it cannot have been clearer : MP Load Letter [sized] Paper! No pressure to solve the problem in retirement.

All this 'tedium' [as you put it] has been solved with two simple procedures: re-setting WSWin to its original settings in Wswchange ws [to find the 'drivers'] and looking at the Page Setup before printing.

Reflect on the time when I was a Manager/Accountant in a small firm and did not have the patience to wait for the engineer to visit the office and would tackle any problems with the photocopier myself....oh yes, I keep forgetting the display is on the printer, not the screen, not a lot of real estate there.
3208.

Solve : Calling DOS batch file from C programme?

Answer»

Has anyone any familiarity with CALLING batch files from C?
I want to call a batch file from a C programme and pass one parameter from the C to the batch.
The system call in the C programme is
Code: [Select]system("testing_parse_lines_DOS-2.bat oldrptname");
with the parameter being oldrptname. Note that oldrptname is a variable and contains data which will be different every time the C programme is run.
The batch file is
Code: [Select]@echo off
setlocal enabledelayedexpansion
for /f "tokens=1,2,3,4* delims=\" %%a in (moveTIFF.dat) do (
set full_line=\%%a\%%b\%%c\%%d
set file_name=%%d
echo Full line: !full_line!
echo File name: !file_name!
echo.
copy /b !file_name! !full_line!
)
del RPT.dat
del moveTiff.dat
rename error.dat %1
and the parameter passed is %1.
The problem is that the renaming works up to a point. It changes the file name 'error.dat' to 'oldrptname' rather than the contents of the variable oldrptname. The data in oldrptname will always have the form "xxxxxxxx.RPT".
I am hoping that the error is a simple syntax error.I don't KNOW C, but I do know that oldrptname in
system("testing_parse_lines_DOS-2.bat oldrptname");
is being run as a switch to the batch file as itself, no variable. Perhaps if you show me how to call a variable in C I can HELP you more. Scrap any further comments in this post. I solved it. I will now go and salsh my wrists for stupidity!

I have done a little further work. Currently I am calling the batch file with the new filename present to see how it behaves.
Code: [Select]testing_parse_lines_DOS-2.bat 20090220-TESTMOVE.RPT
I wrote a little batch file for testing
Code: [Select]@echo off
echo %1
echo finished moving of files
rename error.dat %1
This batch file will echo the parameter (20090220-TESTMOVE.RPT) send to it and then attempt to change the file name of error.dat to the parameter (20090220-TESTMOVE.RPT). Unfortunately it gives an error message. See attachment
I am wondering if the error message is related to my use of %1 in the 'rename error.dat %1'? Is the syntax, grammar ETC: correct?
Or is it something else?

[Saving space, attachment deleted by admin]place the %1 in quotes, as in, "%1".
Code: [Select]@echo off
echo %1
echo finished moving of files
rename error.dat %1

There is nothing wrong with your code. Works fine. You cannot have duplicate file names in the same directory.File cannot be found could mean the file does not exist (error.dat) or there is a spelling error.

Code: [Select]C:\Temp>dir
Volume in drive C is xpSystem
Volume Serial Number is 60D0-12D6

Directory of C:\Temp

11/04/2009 09:22 AM <DIR> .
11/04/2009 09:22 AM <DIR> ..
11/04/2009 09:16 AM 2 error.dat
11/04/2009 09:16 AM 73 Test.bat
2 File(s) 75 bytes
2 Dir(s) 1,739,354,112 bytes free

C:\Temp>test 20090220-TESTMOVE.RPT
20090220-TESTMOVE.RPT
finished moving of files

C:\Temp>dir
Volume in drive C is xpSystem
Volume Serial Number is 60D0-12D6

Directory of C:\Temp

11/04/2009 09:22 AM <DIR> .
11/04/2009 09:22 AM <DIR> ..
11/04/2009 09:16 AM 2 20090220-TESTMOVE.RPT
11/04/2009 09:16 AM 73 Test.bat
2 File(s) 75 bytes
2 Dir(s) 1,739,354,112 bytes free

C:\Temp>


Quote

place the %1 in quotes, as in, "%1".

Quotes are only required if a file name has embedded spaces or special characters that would mess up the interpreter. That does not appear to be the case here.

I was thinking more along hte LINES of the hyphen, but I checked, hyphen is acceptable either way.
3209.

Solve : SFTP in Dos cmd?

Answer»

Hi
Can we do SFTP USING DOS command

Regardsyes

http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html

3210.

Solve : question about a bat file at login.?

Answer»

Thanks for all you help.

this is what i have at the moment, and it works...

start IEXPLORE.EXE
NET USE H: /HOME
NET USE T: \\ourserver02\software
NET USE P: \\ourserver01\Public
NET USE Q: \\ourserver02\Audit
NET USE R: \\ourserver\it-ops
\\ourserverdc02\SYSVOL\xxxxx.ie\scripts\LSclient.exe miinvser
exit


the problem seems to be when you run
"c:\PROGRAM files\internet explorer\iexplore.exe"
the bat file WONT go past that part, but if you change it to

start IEXPLORE.EXE
it works fine.

not really sure why one works where the other fails, as they would appear to be doing the same thing..
but thanks again to everybody who helped, its much APPRECIATED...

Damien

Quote

start IEXPLORE.EXE

Internet Explorer works well when INVOKED without a path.
For more information you have to get into the Microsoft SDK.
3211.

Solve : saving a file every 30 seconds?

Answer»

I am experienced DOS user from back in the old days but have never had this type of problem so I hope someone can help or at least answer this for me.

We need to transfer a file of acquired data from one directory to another. The other directory is actually on another computer that is connected by radio, however, it is essentially networked through software in XP. We can copy the new file in DOS to the other computer but the problem is we need to do this automatically every 30 seconds. That is where my problem is.

Can you put a loop in a batch file or time an event like save a file in DOS?

We are looking at other methods like a backup PROGRAM in XP to backup a file or directory every 30 seconds. The data changes in these files and we need to constantly send it to the other computer in case or experiment crashes.

Thanks in advance for any suggestions or help

Dave Quote from: rmcel123 on May 06, 2009, 11:44:01 AM

...
Can you put a loop in a batch file or time an event like save a file in DOS?

Yes and yes.

With a goto statement you can make it loop.

http://www.vfrazee.com/ms-dos/6.22/help/goto.htm


To make it wait 30 seconds, one way is to USE a free third party utility program.
ftp://ftp.simtel.net/pub/simtelnet/msdos/batchutl/
and look for wait.zip


Quote
We are looking at other methods like a backup program in XP to backup a file or directory every 30 seconds. The data changes in these files and we need to constantly send it to the other computer in case or experiment crashes.

Syncback is very nice ( and there is a free version ) backup software.
You can read more about it, and download it here:
http://www.snapfiles.com/get/SyncBack.html
but I don't know if you could schedule it via Windows scheduler for every 30 seconds. Maybe the closest you could get would be once per minute?
Unless... you ran Syncback from the command line, and used wait.exe to make the batch file wait 30 seconds... .. it's an idea....

Quote
Thanks in advance for any suggestions or help

I hope this helps.

You can use, presuming you are running an NT family operating system, (Windows NT4, 2000, XP, 2003, Vista, etc) a utility called Sleep.exe which is part of the Microsoft Windows Server 2003 Resource Kit. This will suspend operation for either a specified number of seconds or milliseconds.

http://download.microsoft.com/download/8/e/c/8ec3a7d8-05b4-440a-a71e-ca3ee25fe057/rktools.exe

Code: [Select]
REM This is a "label"

:loop

REM do some stuff
REM wait 30 seconds
sleep 30
REM do some more stuff
REM goto next quits the loop
REM loop again
goto loop

:next

what about:
Code: [Select]ping -n 1 -w 30000 1.1.1.1 >nul
or

Code: [Select]@echo off
setlocal enableextensions

:SETUP
set sec=0
set /a sec=%1
set cout=0

:LOOP
set time_1=%time:~-4,1%
:ADD
set time_2=%time:~-4,1%
if not %time_1%==%time_2% (goto COUNT)
goto ADD

:COUNT
set /a cout+=1
if %cout% equ %sec% (goto :EOF)
goto LOOP
goto :EOF

??

then he dont need any .exe


Thanks for the suggestions. We actually like Syncback and it works fine for our needs.....sort of.

We are communicating between 2 computers using 2.4Ghz radios that supposedly simulate a network when all is well. One is attached to a helium balloon and will travel up to 30kms before exploding and sending the payload back to earth. We need to transfer data while the unit is working in case we don't RECOVER the payload.We are having a few hiccups and need to get this set up properly before we tackle the automatic save stuff.

I also have tried robocopy which is a MS utility, basically a super xcopy command. We can do that in 1 minute saves which is fine.

Thanks again for all the help.

Dave
3212.

Solve : spaces and batch files?

Answer»

Hi,I am trying to find a way to copy a file (*.pst) to somewhere else that I choose.
I am using the windows XP and running as *.bat AND *.cmd

It looks like this:
======================
@echo off
cd\
dir *.pst /s /b &GT;pst.txt
======================

The output txt file looks like this:
======================
C:\Documents and Settings\Darrell\Local Settings\Application Data\Microsoft\Outlook\archive.pst
C:\Documents and Settings\Darrell\Local Settings\Application Data\Microsoft\Outlook\Outlook1.pst
======================

My problem is that obviously my output file cannot put Quotes around each location, or at least I don't know how to.
Also even if I go in and manually put quotes in place by editing my "copy batch file" it will only go as far as the 1st space and then creates an error.

My Copy Batch file looks like this:
======================
cd c:\
for /F %%a in (pst.txt) do xcopy "%%a" C:\backup /n
pause
======================

As you can see I have tried (in the above example) to wrap the %%a variable in quotes, that doesn't work either.
This is the error I get when it runs:
======================
Hi,I am trying to find a way to copy a file (*.pst) to somewhere else that I choose.
I am using the windows XP and running as *.bat AND *.cmd

It looks like this:
======================
@echo off
cd\
dir *.pst /s /b >pst.txt
======================

The output txt file looks like this:
======================
C:\Documents and Settings\Darrell\Local Settings\Application Data\Microsoft\Outlook\archive.pst
C:\Documents and Settings\Darrell\Local Settings\Application Data\Microsoft\Outlook\Outlook1.pst
======================

My problem is that obviously my output file cannot put Quotes around each location, or at least I don't know how to.
Also even if I go in and manually put quotes in place my "copy batch file" it will only go as far as the 1st space and the creates an error.

My Copy Batch file looks like this:
======================
cd c:\
for /F %%a in (pst.txt) do xcopy "%%a" C:\backup /n
pause
======================

As you can see I have tried (in the above example) to wrap the %%a variable in quotes, that doesn't work either.

This is the error I get when it runs:
======================

C:\Documents and Settings\Darrell\Desktop\get PST>cd c:\

C:\>for /F %a in (pst.txt) do xcopy "%a" C:\backup /n

C:\>xcopy "C:\Documents" C:\backup /n
File not found - Documents
0 File(s) copied

C:\>xcopy "C:\Documents" C:\backup /n
File not found - Documents
0 File(s) copied

C:\>pause
Press any key to continue . . .
==========================================
As you can see it only reads C:\Documents and then stops, Can anybody help with this? I hope I have given you enough info. DazSorry about the 1st attempt at pasting my QUESTION. SOMEHOW it did it twice.
Here is the actal question in full.
Hi,I am trying to find a way to copy a file (*.pst) to somewhere else that I choose.
I am using the windows XP and running as *.bat AND *.cmd

It looks like this:
======================
@echo off
cd\
dir *.pst /s /b >pst.txt
======================

The output txt file looks like this:
======================
C:\Documents and Settings\Darrell\Local Settings\Application Data\Microsoft\Outlook\archive.pst
C:\Documents and Settings\Darrell\Local Settings\Application Data\Microsoft\Outlook\Outlook1.pst
======================

My problem is that obviously my output file cannot put Quotes around each location, or at least I don't know how to.
Also even if I go in and manually put quotes in place my "copy batch file" it will only go as far as the 1st space and the creates an error.

My Copy Batch file looks like this:
======================
cd c:\
for /F %%a in (pst.txt) do xcopy "%%a" C:\backup /n
pause
======================

As you can see I have tried (in the above example) to wrap the %%a variable in quotes, that doesn't work either.

This is the error I get when it runs:
======================

C:\Documents and Settings\Darrell\Desktop\get PST>cd c:\

C:\>for /F %a in (pst.txt) do xcopy "%a" C:\backup /n

C:\>xcopy "C:\Documents" C:\backup /n
File not found - Documents
0 File(s) copied

C:\>xcopy "C:\Documents" C:\backup /n
File not found - Documents
0 File(s) copied

C:\>pause
Press any key to continue . . .
==========================================
As you can see it only reads C:\Documents and then stops, Can anybody help with this? I hope I have given you enough info. DazWelcome to the CH forums.

Quote

My Copy Batch file looks like this:
======================
cd c:\
for /F %%a in (pst.txt) do xcopy "%%a" C:\backup /n
pause
======================

Amend your For command line to include "Delims=*" and see what happens.

Good luckExcellent. That worked PERFECTLY. I probably should have asked this question earlier today and saved about 4 hours of frustration. Thanks a lot. You're very welcome and thanks for coming back to report your success..

Can you explain what that edit does exactly please?I'm no expert but...

The For command parses input until a delimiter is found. The default delimiters are space and tab. In your script the first line of pst.txt would be parsed until a space was encountered at which point %%a would be set to the value C:\Documents

By using "Delims=*" the default delimiters no longer apply. "Delims=" could also have been used as could any character which does not appear in the input being parsed.

As you will know entering For/? at the Command Prompt displays info on the For command.I understand. Thanks again.
3213.

Solve : Displaying the file creation date?

Answer»

Quote from: BC_Programmer on May 05, 2009, 02:05:18 PM

does DOS even maintain both the modified AND created dates? I'm not sure I remember correctly.

There is no created date in MS-DOS 6.22. Version 7.10 and later can store CREATION/modified but only when LFNs are enabled.





Quote from: gh0std0g74 on May 04, 2009, 06:15:18 PM
because of reasons like what you have posted? requirement changes? in the past you don't need to find out about creation date, but now you do, and then you found out that DOS6.22 doesn't have the facility to allow that? worse, you went to search for a third party tool and found it does the work you want, but is not written to be run on DOS6.22 because its too old? are these valid reasons for you?
Wow, steady.. Do you have ANGER issues with MS-DOS? I looked for a third party tool, did I? I was not aware that I'd done that. Have you tried my QBasic SOLUTION?
Hi Dias,

Thanks for the query, could I trouble you for a few pointers on dissecting the text file (I can DIRECT it to the file ok, but to get chunks back may involve a bit of heartache)

Thanks for taking the time to respond, I appreciate the 'help each other out' attitude some people have. I'm not sure if there's any way I can help you out..

All the best,Sorry Dias, just seen your Qbasic solution, I'll give it a try, eternal thanks.Quote from: AlexTheGrater on May 07, 2009, 10:11:27 AM
just seen your Qbasic solution

Code: [Select]REM Open the file previously created
REM Which has the output of DIR
open "dirline.txt" for input as #1

REM skip over the first 5 lines of the DIR output
for j=1 to 5: line input #1, d$:next j

REM Get the next line
line input #1, a$

REM I omitted this, it is probably good housekeeping
REM to close the file
close #1

REM Show the part of the line with the date / time info
REM that is, the 10 characters starting at position 29
print "File created on "; MID$(a$, 29, 10)

REM exit back to batch file
system
Thanks, Diaz. It works! You're a star..
3214.

Solve : This is Bug in .bat file??

Answer» THANKS, My computer have wscript.exe and cscript.exe. I used file BAT with
Quote
cscript //nologo scriptname.vbs &GT; file.txt
exit /B wscript.exe
scriptname.vbs

and it worked, thanks again You ran the script twice.
3215.

Solve : pc will not boot from boot devices?

Answer»

pc Gateway X500
os xp


I was trying to reformat the hard drive, I put operating system in the drive and deleted the partition on the hard drive (Probably should not have) Now pc will not boot from any boot device(incl hard drive, EITHER cdrom, or even floppy) the reason for this is that when I deleted the partition it disabled all the boot devices including the hard drive. My question, is how do I enable the boot devices or fix this problem
in general.You should be able to change the boot SETTINGS in your BIOS before any boot device is attempted...

The BIOS is usually entered by pressing either "F2" or the 'Del' key but it should tell you the correct key to press when you TURN on your PC.

Set the boot device order to 1. CD ROM/DVD, 2. HDD and then boot from your WINDOWS XP installation CD. Your computer should then boot from the CD. During the installation process, you will be asked where you want to install Windows and you should choose your HDD - the installation will see there is no available partition and will create on for you...

Hope this helps,

Mat

3216.

Solve : VBS and JScript bug & how to fix it?

Answer»

Dusty and I are collaborating on an FAQ for doing floating-point arithmetic using the Evaluate.vbs script I posted some weeks ago. Among the VBS functions this can access is one CALLED FormatCurrency. This takes a value and displays it as a currency value, i.e. the local currency symbol as defined in Control Panel, that is, $ (dollar) £ (pound), € (EURO) etc, followed by the value expressed with 2 decimal places. Although my local currency is the UK pound, I could only get values showing with a dollar sign. A Google search reveals that this is a known problem, and AFFECTS VBScript and JScript in Vista Service Pack 1, Server 2008, and XP Service Pack 3. Currency and other locale-specific formats such as date, time, etc may not be displayed correctly.

There is a Microsoft Hotfix, KB951978, and you can read about the problem and download the right fix for your OS here:

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

There was no need to reboot afterwards on my XP SP3 system.

I daresay most English language users will be unaware of this issue, since the only such countries that do not use the dollar sign (that I can THINK of) are the Irish Republic and Great Britain. (Of course it would affect English speaking expats living in non-dollar-using countries who have SET the currency symbol to the local one.) However, for the sake of accuracy I felt it desirable to make this known.

Thanks for sharing this fact.

3217.

Solve : Formatting a cd??

Answer»

Two questions:

1.)I'd like to backup the output of my batch file to a cd. Is it necessary to format the cd to fat32?

2.)When I type the COMMAND, >format d: /fs:fat32

I get the warning: ALL DATA ON NON-REMOVABLE DISK DRIVE D: WILL BE LOST.

The cd is of course, removable. I'm not going to hurt my C: drive, am I? You don't NEED to format the cd.

Unless it's a rewritable disk formatting it is like writing to it. It will make it into a coaster.It's a read-write disk.

So, the format command is only used now for the HARD drive since floppys are obsolete?Correct. Don't format your cd's. The utility that you use for creating the disk will take care of what you need.you need to format them if you use packet writing software; which would appear to be the case here.Quote from: BC_Programmer on November 04, 2009, 11:17:07 AM

you need to format them if you use packet writing software; which would appear to be the case here.

You know, I had forgotten about that. GOOD catch.
3218.

Solve : MS-DOS COMMAND TO OPEN AND EXIT(CLOSE) A WINDOW?

Answer»

To those who help us learn.
Sir, I want to OPEN from command prompt ,what is the MS-DOS COMMAND,PLEASE ?
Next I want to exit(close) the window that REMAINS on the Desktop (after playing my videos); what's the MS-DOS COMMAND to do the job, please ?
With regards, 'spdCHF'.Quote from: spdCHF on April 10, 2009, 05:35:36 AM

To those who help us learn.
Sir, I want to open <VLC media player> from command prompt ,what is the MS-DOS COMMAND,please ?
Next I want to exit(close) the <VLC media player> window that remains on the Desktop (after playing my videos); what's the MS-DOS COMMAND to do the job, please ?
With regards, 'spdCHF'.
I don't use VLC but I'm fairly sure there's a switch that automatically closes it after playing music/etc.you have to know the full path of were it is. Its not LIKE you can type mspaint and have it come up cause it is a internal command. What you can do is make a bat and run it like that so that you wont have to call up the path all the time.Didn't he ask these questions before when he was devduttaa?
Yep.

I dont check every one
3219.

Solve : Dos "Eventcreate" and Event????

Answer»

I'm sure at one POINT in time I found a command that would allow you search the eventlog for an EVENT, I know you can EventCreate to add an ENTRY, but how do I look for entries and put them to a string if found?

What do I NEED this for. I am using perfmon with diskspace counters which logs information to the eventlog when the alert goes off, I want the bat file that is launching to look for the event so it knows what system caused the alert. Hopefully this makes sense and hopefully I'm not LOSING my mind with thinking I saw such a command.

Thanks. (1)
http://technet.microsoft.com/en-us/library/cc757231%28WS.10%29.aspx

(2)
http://www.google.co.uk/search?source=ig&hl=en&rlz=&=&q=event+log+command+line&btnG=Google+Search&meta=lr%3D&aq=0&oq=event+log+comma

3220.

Solve : retrieving files from a corrupted hard drive?

Answer»

when i try to get a list of the Dir for c: drive i get a error message if this is the case how would i be able to know where specific files are located? I'm only trying to retrieve some video and pictures, and some files from quicken. is there a blanket command that i could use to copy the entire c: drive to a external hard drive connected via usb? my usb is the e:cd \ REM start at root directory

xcopy /s /H *.* D:

( I have not tested the above xcopy )

C:\>xcopy /?
Copies files and directory trees.

XCOPY source [destination] [/A | /M] [/D[:date]] [/P] [/S [/E]] [/V] [/W]
[/C] [/I] [/Q] [/F] [/L] [/G] [/H] [/R] [/T] [/U]
[/K] [/N] [/O] [/X] [/Y] [/-Y] [/Z]
[/EXCLUDE:FILE1[+file2][+file3]...]

source Specifies the file(s) to copy.
destination Specifies the location and/or name of new files.
/A Copies only files with the archive attribute set,
doesn't change the attribute.
/M Copies only files with the archive attribute set,
turns off the archive attribute.
/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.
/EXCLUDE:file1[+file2][+file3]...
Specifies a list of files containing strings. Each string
should be in a separate LINE in the files. When any of the
strings match any part of the absolute path of the file to be
copied, that file will be excluded from being copied. For
example, specifying a string like \obj\ or .obj will exclude
all files underneath the directory obj or all files with the
.obj extension respectively.
/P Prompts you before creating each destination file.
/S Copies DIRECTORIES and subdirectories except EMPTY ones.
/E Copies directories and subdirectories, including empty ones.
Same as /S /E. May be used to modify /T.
/V Verifies each new file.
/W Prompts you to press a key before copying.
/C Continues copying even if errors occur.
/I If destination does not exist and copying more than one file,
assumes that destination must be a directory.
/Q Does not display file names while copying.
/F Displays full source and destination file names while copying.
/L Displays files that would be copied.
/G Allows the copying of encrypted files to destination that does
not support encryption.
/H Copies hidden and system files also.
/R Overwrites read-only files.
/T Creates directory structure, but does not copy files. Does not
include empty directories or subdirectories. /T /E includes
empty directories and subdirectories.
/U Copies only files that already exist in destination.
/K Copies attributes. Normal Xcopy will reset read-only attributes.
/N Copies using the generated short names.
/O Copies file ownership and ACL information.
/X Copies file audit settings (implies /O).
/Y Suppresses prompting to confirm you want to overwrite an
existing destination file.
/-Y Causes prompting to confirm you want to overwrite an
existing destination file.
/Z Copies networked files in restartable mode.

The switch /Y may be preset in the COPYCMD environment variable.
This may be overridden with /-Y on the command line.

C:\>Quote

when i try to get a list of the Dir for c: drive i get a error message
What is the error message?
3221.

Solve : How do i make a CMD Prompt..???

Answer»

Quote from: Carbon Dudeoxide on May 02, 2009, 05:58:41 AM



maybe i should rephrase to
"@OP , you have asked alot on batch previously and i am sure you can find the answer from those posts. why don't you try your best? "How about one person solved the problem with half the effort three put into talking about post COUNTS.

Sometimes it would be easier just to ignore the post or repeat yourself.Quote from: fat_basterd21 on May 04, 2009, 09:53:07 AM
How about one person solved the problem with half the effort three put into talking about post counts.

Sometimes it would be easier just to ignore the post or repeat yourself.

How about nothing. Dickhead screen name. Yes FB, please change your screen name.

And also please don't be a hypocrite.well I've had my dickhead screen name for about 4 years now sorry NOBODY was ever offended before. And how am I a hypocrite? I try to answer questions not tell people to think harder...

I wasn't trying to be rude, just STATING you could have answerd the poster the first time with less effort and the lack of rudeness...CORRECTION, the last post of mine I could find

on: July 17, 2006, 01:58:01 PM

Also I'm offended that anyone is offended by such a funny comedy. Add this line to your .bat file

tskill WHINE.exeFB,

Your being a hypocrite by this number:

Quote from: fat_basterd21 on May 04, 2009, 09:53:07 AM
How about one person solved the problem with half the effort three put into talking about post counts.

Sometimes it would be easier just to ignore the post or repeat yourself.

And you didn't help worth a darn and this is just pointless:
Quote from: fat_basterd21 on May 04, 2009, 08:09:14 PM
tskill whine.exe
don't waste your energy, macdad, it isn't worth it.
I think my first post was helpful in saying, if all you wanna do is whine about how you already told them in another post your better off to just ignore the post. Or if you would have taken one step further and linked it to an original post while pointing out this is a repeat, fine. "Think harder" is hardly worth posting and is frustrating for the poster. I hope this "Helps" other people to use their head before being an *censored* in the future!Can the abusive language, F_B21.
Quote from: fat_basterd21 on May 06, 2009, 05:43:18 PM
If all you wanna do is whine about how you already told them in another post your better off to just ignore the post.

err...


didn't you already say that in another post? And now your basically whining about that here?


Unfortunately, all the whining ends here. This topic need not continue.

Settle the matter elsewhere, guys. That's what PMs are for.

Topic Closed.
3222.

Solve : DOS Command window in second or invisible?

Answer»

Quote from: macdad- on May 04, 2009, 11:32:44 AM

Oh you have is starting in Startup Manager, not a seperate bat file.

Can you list off the options on it?

Okis Macdad- . I'll try. See you later. Thank.
Quote from: macdad- on May 04, 2009, 11:32:44 AM
Oh you have is starting in Startup Manager, not a seperate bat file.

Can you list off the options on it?

Startup Manager is a simple program. Don't have the versatility of Startup Delayer. But offer the possibility to insert batch files .



By Esgrimidor


There is a paid program that does the way of Startup Delayer and this one asking when you enter in the system for the perfil o special bat you desire to execute.

With Startup Manager you have to propose before reinitiate.

So... I think there is a lot of opportunities. I was seeing the large post we have of scripting in the forum and CERTAINLY is not very difficult for a professional do a special startup.

In my case i'm not a professional. Perhaps I HOPE to find the work done.

IN this case I think we can ignore the construction of Startup Manager moving the bat to other folder where SM don't see him. Then make all the necesary modifications there and insert with Startup Delayer than interact better with msconfig.exe and subsequently with the register.

Startup Manager seems to me a strange program. I does his work without a certainly rule. I don't know because select some executables, dll, and so on, and others no.

On resume. I think Startup Delayer is a better program and we can make the additional bats with all our desires and language possibilities and insert with SD. After only is necessary mark or unmark a part of the list of bat to select the way we want the startup.

And sure we can modify this with another special script. And certainly I don't have idea of doing this.....

I know, there isn't a command for batch that lets you run batch programs in the background(hidden) and I'm not to familiar with Startup Manager either. A member of this forum told me of a program to compile to exe thats permits run in minimize mode.
I'm waiting for the link and I proof.
Thank a lot
Sorry I couldn't help. Quote from: macdad- on May 05, 2009, 12:12:47 PM
Sorry I couldn't help.

Next time perhaps.
I'm happy to be here.
Quote from: macdad- on May 04, 2009, 06:51:06 AM
Sorry for asking, It's just that of course people ask how to make PRANK batch programs and yours kinda sounds a bit suspicious, but since your doing this to just to CLEAN up the screen, then here:

Code: [Select]start trabajo.bat /MIN

Mmmmmm

Startup Manager create the trabajo.bat
this bat contains all lines with "Start"

Is a line inside another bat ?

It's possible with trabajo.bat /MIN ?


Seems so if its inside a batch fileUnderstood

Privat MESSAGE me you e-mail and I will send it to ya. REAL small and is freeware so no worries.okis.

Best Regards
pepe
3223.

Solve : How do I Calculate between two date/time strings??

Answer»

I have a program that receives in a string (for the example I put the value in a variable).
This string contains a DATE/TIME that I want a job to run on. I PARSE out the DATE/TIME from the string and compare this to the current date/time but it doesn't want to run (or should I SAY it ALWAYS wants to run even though the date/time is still in the future).

I have put in echo statements that display the results of the strings and everything is correct.
(You can cut and paste this code into a BAT file for testing).

Any help would be appreciated.
Ken



@echo OFF
REM set up the job date and time (hard coded for testing purposes
set JOBFILE="5.200905061159.KWL.J65.Nightly_Process. job"
set RUNDATETIME=%JOBFILE:~3,12%

REM Set up the current time
set CURRENTHOUR=%TIME:~0,2%
if %CURRENTHOUR% LSS 10 set CURRENTHOUR=0%TIME:~1,1%

REM Set up the current date (regardless of format)
REM Set the initial tokens to be 1 through 3 (to be used later)
set $TOK=1-3
REM Take the first part of the string returned by the "date /t" command and put it in the $D1 variable
for /f "tokens=1 delims=.:/-, " %%u in ('date /t') do set $D1=%%u
REM If the first character of the variable $D1 is greater than 9, it must be a letter,
REM therefore the day of WEEK is given, so we adjust our $tok variable to skip the day of week
if "%$D1:~0,1%" GTR "9" set $TOK=2-4
REM Get each part of the date in 3 steps using either parts 1-3 or 2-4 depending on if day of week is given
for /f "tokens=%$tok% delims=.:/-, " %%u in ('date /t') do (
REM get the yy mm and dd from the date [Enter] command to assign the parts in the previous step
for /f "skip=1 tokens=2-4 delims=/-,()." %%X in ('echo.^|date') do (
REM Set the parts of the date
set %%x=%%u
set %%y=%%v
set %%z=%%w
REM clear the $D1 and $TOK variable since we are done with them
set $D1=
set $TOK=
)
)

set CURDATETIME=%yy%%mm%%dd%%CURRENTHOUR%%TIME:~3,2%

echo Calculated current date and time (s/b YYYYMMDDHHMM) %CURDATETIME%
if %RUNDATETIME% GTR %CURDATETIME% goto EOF
echo The sample job (%RUNDATETIME%) would now run
PAUSE

REM ;------------------------------------------------------------------
:EOF
date/time numbers are too long. GTR only works with valid numbers. Batch number variables are limited to 32-bits of precision, as you will see by the error messages if you use set /a to create them.

Since you did not use set /a, the strings are treated as ASCII strings, and since "2" is not greater than "2", the GTR test is failed. Make them shorter. By the way, you don't want any leading zeroes.

Ok great at leas now I can see where the problem is.
How to fix the CURDATETIME to only have YY instead of YYYY.
AND i have no idea how to get rid of the leading zeros with the new calculation.

Help!The reason I said you don't want leading zeroes is because set /a interprets a number starting with a zero as being in octal, so it is a good habit to not use them unless you actually need to.

YY therefore won't do (atleast not until next year)

MMDDhhmm with a leading nonzero digit will work, let's say 1, so that 6th May 19:30 becomes 106051930

Except that there would be a problem with curdatetime being on Dec 31st and rundatetime being on Jan 1st.

But we can use Visual Basic Script to do the comparison:

Code: [Select]@echo OFF

REM Create VBS file

echo Wscript.echo eval(WScript.Arguments(0))>evaluate.vbs

REM set up the job date and time (hard coded for testing purposes
set JOBFILE="5.200905062059.KWL.J65.Nightly_Process. job"
set RUNDATETIME=%JOBFILE:~3,12%

REM Set up the current time
set CURRENTHOUR=%TIME:~0,2%
if %CURRENTHOUR% LSS 10 set CURRENTHOUR=0%TIME:~1,1%

REM Set up the current date (regardless of format)
REM Set the initial tokens to be 1 through 3 (to be used later)
set $TOK=1-3
REM Take the first part of the string returned by the "date /t" command and put it in the $D1 variable
for /f "tokens=1 delims=.:/-, " %%u in ('date /t') do set $D1=%%u
REM If the first character of the variable $D1 is greater than 9, it must be a letter,
REM therefore the day of week is given, so we adjust our $tok variable to skip the day of week
if "%$D1:~0,1%" GTR "9" set $TOK=2-4
REM Get each part of the date in 3 steps using either parts 1-3 or 2-4 depending on if day of week is given
for /f "tokens=%$tok% delims=.:/-, " %%u in ('date /t') do (
REM get the yy mm and dd from the date [Enter] command to assign the parts in the previous step
for /f "skip=1 tokens=2-4 delims=/-,()." %%x in ('echo.^|date') do (
REM Set the parts of the date
set %%x=%%u
set %%y=%%v
set %%z=%%w
REM clear the $D1 and $TOK variable since we are done with them
set $D1=
set $TOK=
)
)

set CURDATETIME=%yy%%mm%%dd%%CURRENTHOUR%%TIME:~3,2%


echo Calculated current date and time (s/b YYYYMMDDHHMM) %CURDATETIME%

echo test: if %RunDateTime% GTR %CurDateTime% don't run job

for /f "delims=" %%A in ( ' cscript //nologo evaluate.vbs "%rundatetime% > %curdatetime%" ' ) do set Result=%%A

REM Result is -1 if test is passed, 0 if it is failed

if "%Result%"=="-1" goto EOF

echo The sample job would now run

REM ;------------------------------------------------------------------

:EOF

Ok I found a way of doing this in plain old DOS.

I took your advise and added the SET /A.
I also decided to split the date and the time into two test instead of 1 since DOS can't GTR a 12 digit date.

Thanks for your help.
Ken


@ECHO OFF
REM set up the job date and time
set JOBFILE="5.200905060900.KWL.J65.Nightly_Process. job"

REM Extract the job date
set /a RUNDATE=%JOBFILE:~2,8%

REM Set up the current date (regardless of format)
REM Set the initial tokens to be 1 through 3 (to be used later)
set $TOK=1-3
REM Take the first part of the string returned by the "date /t" command and put it in the $D1 variable
for /f "tokens=1 delims=.:/-, " %%u in ('date /t') do set $D1=%%u
REM If the first character of the variable $D1 is greater than 9, it must be a letter,
REM therefore the day of week is given, so we adjust our $tok variable to skip the day of week
if "%$D1:~0,1%" GTR "9" set $TOK=2-4
REM Get each part of the date in 3 steps using either parts 1-3 or 2-4 depending on if day of week is given
for /f "tokens=%$tok% delims=.:/-, " %%u in ('date /t') do (
REM get the yy mm and dd from the date [Enter] command to assign the parts in the previous step
for /f "skip=1 tokens=2-4 delims=/-,()." %%x in ('echo.^|date') do (
REM Set the parts of the date
set %%x=%%u
set %%y=%%v
set %%z=%%w
REM clear the $D1 and $TOK variable since we are done with them
set $D1=
set $TOK=
)
)
set /a CURDATE=%yy%%mm%%dd%

REM Check to see if this job is to be run today, if not skip the rest
if %RUNDATE% LSS %CURDATE% goto NOTRUN

REM Extract the job time
set RUNHOUR=%JOBFILE:~10,2%
if %RUNHOUR% LSS 10 set RUNHOUR=%JOBFILE:~11,1%
set /a RUNTIME=%RUNHOUR%%JOBFILE:~12,2%

REM Set up the current time
set CURRENTHOUR=%TIME:~0,2%
if %CURRENTHOUR% LSS 10 set CURRENTHOUR=0%TIME:~1,1%
set /a CURTIME=%CURRENTHOUR%%TIME:~3,2%

set CURDATETIME=%CURDATE%%CURTIME%
set RUNDATETIME=%RUNDATE%%RUNTIME%

REM Check to see if this job is to run now, if not skip the rest
if %CURTIME% LSS %RUNTIME% goto NOTRUN

echo Job would run %CURDATETIME% (%RUNDATETIME%)
goto EOF

:NOTRUN
echo Job would NOT run %CURDATETIME% (%RUNDATETIME%)

REM ;------------------------------------------------------------------
:EOF
PAUSE
date calc is easier with vbscript
Code: [Select]strJobFile = "5.200905060900.KWL.J65.Nightly_Process.job"
strJobFileYear = Mid(strJobFile,3,4)
strJobFileMth =Mid(strJobFile,7,2)
strJobFileDay =Mid(strJobFile,9,2)
strDate = strJobFileYear & " " & strJobFileMth & " " & strJobFileDay
strNowDate = Year(now) & " " & Month(Now) & " " & Day(Now)
WScript.Echo DateDiff("d",strDate,strNowDate)
Quote from: gh0std0g74 on May 06, 2009, 07:09:33 PM

date calc is easier with vbscript

In every way.

3224.

Solve : output to file problem?

Answer»

Hello,

I've got a BATCH file that I use to help me with my day to day activities. I've come into a problem where I call a program and pipe the information to a file, but the information always comes out empty.

I've posted the section of the batch file that's giving me trouble. It works. It will create the file, but no output goes to the file. I've tried with >> and >, but neither seem to work. I'm at a loss, really. This really isn't my line of work, but something to help me day to day. Any help would be greatly appreciated. I believe the trouble line is in teal....

:DEFAULT_PWDS
M:
CD %CHECKPWD_DIR%
set /p PWD=Enter Password for %SLID%:
IF EXIST %CHECKPWD_DIR%\check_%ORACLE_SID%.log DEL %CHECKPWD_DIR%\check_%ORACLE_SID%.log
start /WAIT /D%CHECKPWD_DIR% checkpwd %SLID%/%PWD%@%ORACLE_SID% default_passwords.txt >> %CHECKPWD_DIR%\check_%ORACLE_SID%.log

start notepad %CHECKPWD_DIR%\check_%ORACLE_SID%.log

Thank you,

JeremyA pipe "|" is used to send input to another program. If you send the information to a file, then a redirect (>) must be used


If you have used pipes, “|” with Unix Shell Programming or other environments, then a pipe with CMD (Batch) will not always work the same as other environments.

IF EXIST %CHECKPWD_DIR%\check_%ORACLE_SID%.log DEL

( in reference to the above line: You might CD to the directory where the log is and delete the log. ) ( If the log is not there, you will get a harmless message. )( a redirect will create the log automatically )

As a test use the real path and not the output of variables.

start notepad %CHECKPWD_DIR%\check_%ORACLE_SID%.log

I see no reason for start

cd to where the log is.

notepad oracle.log

We can open notepad with a batch file but the edit functions are manual.

Unix has sed which will run automatically

Good Luck



I appreciate the response, but I'm not worried about unix commands at this point.

This works just fine when I run the steps manually. It's when I put it into a larger batch file to help me with everything, no output goes to the file. The file gets created (if it does not exist), but it's always a 0kb file.

I tried your trick (taking out all the variable), but no dice. It still does the same thing. Creates an empty file. BTW, I developed with no variables and put them in after the fact.

Any other suggestions?HA! Figured it out. For some reason it doesn't redirect when the START command is used. I took out

start /I /SEPARATE /WAIT /D %CHECKPWD_DIR%

from the start and now it works like a charm....

SWEEEEEET! I guess this can be considered closed. Good to hear you solved the problem.

I'm not sure why start can cause problems.

Start opens a new window and new copy of CMD. Perhaps the file was there but HIDDEN?Quote

Start opens a new window and new copy of CMD. Perhaps the file was there but hidden?

A new copy of CMD is a bad idea in Batch programming.
Unless that is want you really want.
I'm fairly new to batch programming so the advice is noted and appreciated.
3225.

Solve : Run another command and Not return control to first batch file?

Answer»

I'm running a script and the LAST command is to use NOTEPAD to open a file.
The 1ST script won't finish unless notepad is closed.

notepad x.txt
exit

Is there a WAY to run the notepad command in the 1st script and let the 1st script finish without closing notepad?Try

Start notepad x.txt &AMP; exit

Good luck.

3226.

Solve : just learning?

Answer»

Quote from: Reno on April 07, 2009, 10:55:08 PM

pinging for 15minutes seems like not a good idea, could have some side-effect which i am not sure of. besides ping delay is not really accurate. that's why in the first PLACE i suggest using vbs sleep function instead of ping.
if you just need to delay for 4-5 seconds once in a while, i would have suggest you using ping instead of vbs sleep.

the code:
>$sleep.vbs echo wsh.sleep 900000
cscript//nologo $sleep.vbs


900000 is in miliseconds, or 900seconds=15minutes.

True, but if you are using it on computers which may not have sleep, ping is your best (only) choice. Although it seems fairly accurate...not to nano seconds, but I've made a stopwatch in batch...almost...Quote from: Helpmeh on April 08, 2009, 05:49:41 AM
True, but if you are using it on computers which may not have sleep, ping is your best (only) choice. Although it seems fairly accurate...not to nano seconds, but I've made a stopwatch in batch...almost...

All Windows computers have VBScript, and can use sleep.vbs.

I did look for a virus and Norton said I'm Clean but that dosen't mean everything. I do like to download games and the cracks may have something looming around

I use this command for work (I Work for a cable co) to check for NETWORK problems and Iperf is the program they offer but I got tired of typing it in to a command line so I started this file.

I ran a test last night with the command and it worked perfectly until I needed to stop. I used CTL-C it asked if I wanted to terminate Y or N of course I said yes......and window gone. That was my only mistake NEXT time I will say No then I can copy my results before closing the window.

I will give this out to others in my company so I just want to get it right as I can.

Quote
>$sleep.vbs echo wsh.sleep 900000
cscript//nologo $sleep.vbs

This worked grate is there a way to tell it to stop after 24hrs but not close the window? Isn't there a timeout command I can try. In need to copy it into a text doc to be emailed.

Again thank you
JamesHey Reno,

The code you posted put the command to sleep just as you said but it never recovers. I even shorten the time.

When I tested it earlier I did not give it enough time to see if it would run the next test. It is just what I looking for.

any ideas
James
Quote from: olo131 on April 08, 2009, 05:02:41 PM
is there a way to tell it to stop after 24hrs but not close the window? Isn't there a timeout command I can try. In need to copy it into a text doc to be emailed.
Quote from: olo131 on April 08, 2009, 09:18:29 PM
The code you posted put the command to sleep just as you said but it never recovers. I even shorten the time.
the code is only for sleep, so after sleep, you have to use some sort of restarting, eg. goto statement, call, restart the batch %0, etc

24 hours stop:15minutes = 4x / hour
24hr x 4x = 96x
not exactly 24 hours, roughly around 24hours + 96 * (time needed to run batch file)


Code: [Select]@echo off
echo.
echo CREATED FOR KNOLOGY SPEED TEST by: OLO 131

>$sleep.vbs echo wsh.sleep 900000
for /l %%a in (1 1 96) do (
call:B
cscript//nologo $sleep.vbs
)
echo 24hrs!! do copy here..
goto:eof

:B
echo.
echo Time and Date of Test
echo.
Date /t
Time /t
echo.
echo Iperf Speed Test Server xx.x.xx.xxx
iperf -c xx.x.xx.xxx -r -w 64k -t 20 -i 1
echo.
echo.
echo.
echo.
echo Ping Iperf Server Test
ping xx.x.xx.xxx -n 20 -l 64k
echo.
echo.
echo Trace Route Iperf Server
tracert xx.x.xx.xxx
echo.
echo.
echo DONE!
echo _______________________________________ __________________________________
echo.Reno,

You are the MAN I ran my test for 24hr worked perfectly now I will do a search for a stop command.

Thank you again, Reno and everyone who helped me
James
3227.

Solve : What is the command to....?

Answer»

Make all the commands in your BATCH not APPEAR (be DISPLAYED) on the screen?@ECHO offThank you.

3228.

Solve : Kill Disk?

Answer»

Newbie here. So right away you know I have a PROBLEM. I have Kill Disk hxxp://www.killdisk.com/
I have a HP Laptop that had Vista and was always GIVING me problems. It kept failing to connect to internet, or Printer etc etc so finally got miffed and decided to "UPGRADE to XP"
I used KillDisk to erase the drive. Loaded XP and it cannot find C Drive.
In fact is says it can't find any drive. I do not have a DOS disk, Kill Disk does not recognize partition or format commands.

So how do I GET the hard drive formated? My days of DOS have long been forgotten
I obviously need an MS-DOS bootable disk, went to Mr Sofite can't find a download that produces a MS DOS disk. All vista units do not allow you to format with MS-DOS like XP used too?
Any help WOULD be appreciated.google "download DOS" and you'll get several websites which allow you to download
the code to create a DOS bootable disk.bootdisk.com...

3229.

Solve : Send mail?

Answer»

hi guys

if possible to send mail in dos with ATTACHMENT ?

GO to the search box and type in "send email".i am sorry no help fonund .......................There is no built in command in DOS to send mail and if you mean DOS in windows, that is Command Prompt(just to let you know)

But there was a while back some command-line application to send mail in CMD(Command prompt)..I'll get back with you when i find it.Quote from: macdad- on MAY 06, 2009, 06:10:11 AM

There is no built in command in DOS to send mail and if you mean DOS in windows, that is Command Prompt(just to let you know)

But there was a while back some command-line application to send mail in CMD(Command prompt)..I'll get back with you when i find it.
I saw another thread like this...I think Dias posted a vbscipt code that sends mail.
3230.

Solve : How to use Tab and Enter in a Batch File?

Answer»

Hi All,

I like to open a application where I would like enter few values.

To enter each value I need to USE TAB.

Also to save this I need to use ENTER.

Can anyone answer how can I pass values to a application using TAB and ENTER in between.

Hoping for a QUICK reply.

Thanks and Regards,
Ekram .Quote

...open a application where ...
If the application requires TAB then it is not a command line application.
Either the application is a Windows program or it has its own visual interface.

Batch files are used to pass parameters to an application that expects command parameters. KEYBOARD Automation is beyond the intent of Batch files. Kwyvoard Automation is, or close to, impossible for applications that do not allow some control from the command line.

You may wish to TRY any one of the many Keyboard Automation Tools found on Google. Or, if you know basic programming, you can use Visual Basic.

Keyboard Automation Tools found on Googleif this need to be batch then post that values and about that key's, i can attach my own edited choice.exe wich allow to use special keys like F1 enter tab DEL etc
3231.

Solve : command line arguments in dos?

Answer» HI All,

I am new to dos.
I have to use some command which should accept source and destination path as command line arguments and the file name to copy.
whenever i SUPPLY three arguments my functionality should work.
how can i ACHIEVE this?

Thanks in advance.can anybody please help me...What do you need help with ?
Do you have to create a program to accept and process the parameters, or does this program already exist and you need to know how to supply parameters on the command line ?thank you...
i need a program for this.

When you say program, you mean batch script ?Actually speaking i do not know how to achieve this...(through batch file or command etc)
Please give me possible ways.
I am sorry as i am new to this forum as well as dos.


So your requirement is
receive 3 parameters
Source Directory (%1)
Destination Directory (%2)
Filename (%3)

Copy filename from Source to Destination

The simplest way is (with no error checking)
Code: [Select]Copy %1\%3 %2Thank you gpl.
Its working.
I have created a batch file with your command.
I have passed three arguments to the file while running it.

Can we copy the file from ONE machine to other machine?
3232.

Solve : HELP Backing up amsdos program?

Answer»

Is there a way I can back up a huge ms dos program to something beside floppy discs? Maybe something that plugs into the floppy drive? THANKS
Is DOS the base OS or is it RUNNING DOS inside Windows? If the latter, then you could plug in a USB, etc and copy it over. If the former, then you will need hardware and software (like a backup drive & program) which might be hard to find in 2009.

- Another possibility is to add a second hard drive to the system and back it up to that.

- My last thought is to take the DOs drive out of that computer and plug it into a Windows PC. When windows recognizes the second drive, back it up WITHIN Windows then return it o the original PC.


If you explain a little better what exactly you are attempting to do it will eliminate alot of the guesswork.I am working in a hardware store that has thousands of parts listed in its database. We ALSO have a point of sale program plus a complete customer list. I don't feel entirely safe ADDING any more items until I can at least back up this database. This is a MSDOS operating system and the computer for it has only floppy drives. Thanks for the advise !!!

3233.

Solve : Text file as input??

Answer»

Hi folks.

I really want to know how i make a batch file that takes input from a text file and puts it in a variable.

Its because im going to make a game with database technology.

ps. How do i make batch do math?file.txt
Code: [Select]SomeTextHere
batfile.bat

@echo off
Code: [Select]for /f %%a in (file.txt) do set var=%%a
echo %var%
pause

OR


file.txt
Code: [Select]life=100
batfile.bat
Code: [Select]@echo off
for /f "tokens=1,2 delims==" %%a in (file.txt) do set life=%%b
echo %life%
pauseJoedavis,

That is completely irrelevant to what he is needing. Please read the post first before replying.Quote from: macdad- on April 08, 2009, 12:50:22 PM

Joedavis,

That is completely irrelevant to what he is needing. Please read the post first before replying.

Relevance doesn't worry joedavis.
it's irrelevant because they asked how to get a batch to do math, not for a batch to do math.Quote from: joedavis on April 08, 2009, 02:01:35 PM

I'm sure BC is correct. Would BC explain "How to get a Batch file to do floating point math?


billrich, we know it's you! We covered FP maths in batch AGES ago.
Quote from: On40 on April 08, 2009, 09:52:32 AM
Hi folks.

I really want to know how i make a batch file that takes input from a text file and puts it in a variable.

Its because im going to make a game with database technology.

ps. How do i make batch do math?

see that last part? PS? that doesn't mean, "devote all your time and resources to solving this one, simple problem with various ways of creating one line batch programs that often shell external interactive windows applications"


Devcom cliched the CORE of the question- your attempt to address the PS would have been better served with an explanation of the /a switch, rather then the PROVISION of multiple samples that include references to the google calculator and shell the windows calculator.


From Set /?:

Quote
Two new switches have been added to the SET command:

SET /A expression
SET /P variable=[promptString]

The /A switch specifies that the string to the right of the equal sign
is a numerical expression that is evaluated. The expression evaluator
is pretty simple and supports the following operations, in decreasing
order of precedence:

() - grouping
! ~ - - unary operators
* / % - arithmetic operators
+ - - arithmetic operators
<< >> - logical shift
& - bitwise and
^ - bitwise exclusive or
| - bitwise or
= *= /= %= += -= - assignment
&= ^= |= <<= >>=
, - expression separator

If you use any of the logical or modulus operators, you will need to
enclose the expression string in quotes. Any non-numeric strings in the
expression are treated as environment variable names whose values are
converted to numbers before using them. If an environment variable name
is specified but is not defined in the current environment, then a value
of zero is used. This allows you to do arithmetic with environment
variable values WITHOUT having to type all those % signs to get their
values. If SET /A is executed from the command line outside of a
command script, then it displays the final value of the expression. The
assignment operator requires an environment variable name to the left of
the assignment operator. Numeric values are decimal numbers, unless
prefixed by 0x for hexadecimal numbers, and 0 for octal numbers.
So 0x12 is the same as 18 is the same as 022. Please note that the octal
notation can be confusing: 08 and 09 are not valid numbers because 8 and
9 are not valid octal digits.
Quote from: Dias de verano on April 08, 2009, 02:20:00 PM
billrich, we know it's you! We covered FP maths in batch ages ago.


LOL, my first draft of my post started with, "billrich... I mean, joedavis..."


BC,


I hope the Dandy from England with the Spanish name continues to help all the new people.

Best of Luck to everyone.

Quote from: On40 on April 08, 2009, 09:52:32 AM
Its because im going to make a game with database technology.
here's a more fun way to make games.Here's some code for crying out loud: This is assuming that the info will only be 1 line in the file on the first line:

Code: [Select]for /f %%Z in ('type [path to file]') do set variable=%%Z

You should be able to echo %variable%Quote from: devcom on April 08, 2009, 10:12:14 AM
file.txt
Code: [Select]life=100
batfile.bat
Code: [Select]@echo off
for /f "tokens=1,2 delims==" %%a in (file.txt) do set life=%%b
echo %life%
pause

Code: [Select]@echo off
for /f "tokens=*" %%a in (file.txt) do set %%a
echo %life%
pauseOh thanks for the help, but can you please explain what happens and how i type the syntax for the file reading thing? I really want to learn it in and out so i modify and tweak it in alot of directions.try for /? in cmd, for better explanation someone will explain, coz i dont speak Eng so good Thanks people.

Especiallly from you devcom! I found out that it could read multi-line info making it more effective. Im going to make that game now!
3234.

Solve : Doskey, and how Macros work?

Answer»

I read the help file and spent quite some time (about 6 hours) googling for information on doskey.exe (I believe that's what it's called) and, honestly, couldn't find the ANSWER I was looking for.

The description lends me to think that it allows the user to create a macro for a program. However, all the examples I've seen have only shown how to create a macro for the command PROMPT. I'm curious, could you do this for any executable?

Suppose, for example, I WANTED to create a macro for notepad.exe where "Ctrl+Shift+S" would allow me to "save as", as it usually does in most programs but for some reason does not allow me to do so in Notepad. (by the way, I'm using WINDOWS XP, not sure if that makes a difference.) I'm very used to using the ctrl+shift+S combo, and it annoys me GREATLY that I cannot do it in Notepad. I can also find several other uses for macros, say, in computer games and the like.

Thank you for your time and patience. ^^Doskey is, as it's name suggests, for dos (or the commandline). You need a different tool. There are several. Googling for "windows macro" will turn up several. Autohotkey seems a popular tool. It's open source. Take a look

http://www.autohotkey.com/

3235.

Solve : MS-DOS Question?

Answer»

I didnt EXPECT you to do it for me, I posted what i thought it was and then i asked if it was correct...

And THANKS very much Bill.Then I APOLOGIZE for the misunderstanding.No PROBS.

3236.

Solve : Removing empty directories...?

Answer»

imagine my surprise when I found batch discussed in Raymond CHENS blog.

http://blogs.msdn.com/oldnewthing/archive/2008/04/17/8399914.aspx

I love this guy! I have just spent the best part of 40 mins reading BACK to Nov 2008 which is when I was last there, and was reminded of this gem

Quote from: Raymond

Not my finest hour: Getting instructions on doing something I've already done

Last YEAR, I sent some email to the people who run our team's check-in validation tool asking how I could add a new rule to the validation tests. One of the members wrote back, "You do it just like this guy," and sent me a reference to another check-in that added a validation rule.

That other check-in was made by me.

But wait, it gets better.

That other check-in? It added the very rule I was thinking about adding.
lol


and some of the comments too- almost 50% of the time it seems to turn into a nitpicking session. Although I guess that happens with all blog comments...finally! i ALWAYS HATE it when Recycle Bin says it can't delete the empty folder.
3237.

Solve : going crazy!! is this possible???

Answer»

Dias I need your help!!I need to understand how the "maxdatenum" works as I am getting problem when latest date is 4/1/09 instead of 3/31/09.It is still extracting only 3/31/09 even if latest date is 4/1/09 or later.
please help me understand.I have googled for this but no use.
Apologies for the stupid error in my code. The script was supposed to extract the first 8 characters of each line which are MM/DD/YY e.g. 04/01/09 and re arrange them to make a number for the date in the form YYYYMMDD e.g. 20090331 or 20090401 such that a later date makes a greater number. However by a stupid error I had the month and day transposed. I would have caught it if I had tested with a month later than March. Fixed below.

Code: [Select]@echo off
setlocal enabledelayedexpansion

set filename=test0401.txt

REM pass 1 - determine latest date
echo Examining file - determining latest date
set maxdatenum=0
set lastdate=

for /f "delims=" %%L in ( ' type "%filename%" ' ) do (
set thisline=%%L
set datestamp=!thisline:~0,8!

REM Fixed
set dateM=!datestamp:~0,2!
REM was previously !datestamp:~3,2!

REM Fixed
set dateD=!datestamp:~3,2!
REM was previously !datestamp:~0,2!

set dateY=20!datestamp:~6,2!

REM Datenum=YYYYMMDD
REM e.g. 20093103
REM e.g. 20090401

set datenum=!dateY!!dateM!!dateD!

if !datenum! GTR !maxdatenum! (
set maxdatenum=!datenum!
set lastdate=!datestamp!
echo Found date : !datestamp!
)
)
echo Latest date found : %lastdate%
REM filenames cannot have / character
set filenamedate=%lastdate:/=-%
REM pass 2 extract latest date's lines
REM containing DOWNLOAD because only pairs have this line
set alreadydone=
REM The filename transferred is TOKEN 6
for /f "tokens=1-26 delims= " %%L in ( ' type "%filename%" ^| find "%lastdate%" ^| find "DOWNLOAD"' ) do (
set filename=%%~nxQ
REM Echo Found filename : !filename!
REM Find number part within transferred filename
REM Delimiter is underscore character
for /f "delims=_" %%A in ("!filename!") do (
set number=%%A
echo !alreadydone! | find ",!number!,">nul || (
set alreadydone=,!number!,!alreadydone!
echo.
REM Echo File number part : !number!
Set Outfile=%filenamedate%-!number!.txt
Echo Creating file : !outfile!
if exist "!outfile!.tmp" del "!outfile!.tmp"
if exist "!outfile!" del "!outfile!"
REM Examine entire log file and extract lines containing CURRENT
REM transferred file number
REM group each filenumber pair together, ignore lines containing message.txt
REM Write to temp file first
for /f "delims=" %%B in ( ' type "%filename%" ^| find "%lastdate%" ^| find "!number!" ^| find /v "message.txt"' ) do (
Echo %%B>>"!outfile!.tmp"
)
REM Only take latest pair for each file number
REM Count lines in output
set numlines=0&for /f "delims=" %%C in ( ' type "!outfile!.tmp"' ) do set /a numlines+=1
REM Subtract 2, this GIVES the first line to take
set /a startline=!numlines!-2
REM Transfer last 2 lines of tmp file to
REM real output file
set line=1
for /f "delims=" %%C in ( ' type "!outfile!.tmp"' ) do (

if !line! GTR !startline! (
echo %%C>>!outfile!
echo %%C
)
set /a line+=1
)
del "!outfile!.tmp"
)
)
)
Echo.
Yes I guessed you have add the date format numbers but when I tried to correct it and refered to other topics in google I did not find any.Thank you so MUCH for your time.It works perfect now.

3238.

Solve : convert screen showing SEARCH results (Vista_) to editable text, how to?

Answer»

What is all this loop hole BUSINESS?
its techincally now called a WORM hole since its gotten to the point of making a Multi-Dimensional Worm Hole Device to SOLVE this PREDICAMENT

3239.

Solve : want silent mode on batch\DOS?

Answer»

suppose if my file is in E:\Temp\Avast.arc

my command is:

Arc.exe x Avast.arc

i want to hide the process DONE by this command

so what shld b d solution

I USE freearc

CAN ANY 1 HELP ME
THIS IS ONE OF THE MOST BIGGEST QUERIES IN MY LIFE I don't know how to hide.

3240.

Solve : I need hope (sorry!)?

Answer»

I have a script that calls dsrm to delete computer accounts. Some accounts have special "features" and dsrm will not remove them. I understand why, but my problem is that when dsrm fails, it sets the ERRORLEVEL to -2147016643 and I cannot test for it in my batch script.

more...
when i run the command from the commandline
Code: [Select]> dsrm cn=bob1,ou=workstations,dc=ourcompany,dc=com -noprompt you get this error:
dsrm failed:cn=bob1,ou=workstations,dc=ourcompany,dc=com:The directory service can perform the requested operation only on a leaf object.

and if I then run Code: [Select]> echo %errorlevel% it returns -2147016643

However, if I ADD that same command on the line immediately after the dsrm command in my script, the script echos "0". Code: [Select] dsrm %CN% -noprompt >>%actlog%
echo %errorlevel%
Similarly, if I test using Code: [Select]IF ERRORLEVEL 1 or Code: [Select]IF /i %errorlevel% NEQ 0 the test always fails.

It APPEARS cmd shell has a problem with this errorlevel.

What don't I know?

\\uSlackr
i bet that dsrm sets errorlevel higher than cmd can handle, i mean 32 bit integer is highest number in cmd

you can try echo dsrm to file and check for errors:



Code: [Select]@echo off
dsrm cn=bob1,ou=workstations,dc=ourcompany,dc=com -noprompt >dsrm_log.txt

for /f "tokens=1-3* delims=:" %%a in ('type dsrm_log.txt ^| findstr "failed"') do (
if not "%%a" equ "" (
echo.%%a
echo.%%c
)
)
pauseI have a follow up question. Can I get the output of stderr to be read by a for loop without first sending it to a file? That way I could run the dsrm in a for command and maybe find the results there.

Maybe something like:

Code: [Select]for /f "tokens=*" %a in ('dsrm .... &2>1') do ...
\\uSlackrQuote from: devcom on May 01, 2009, 02:26:35 AM


Code: [Select]@echo off
dsrm cn=bob1,ou=workstations,dc=ourcompany,dc=com -noprompt >dsrm_log.txt

for /f "tokens=1-3* delims=:" %%a in ('type dsrm_log.txt ^| findstr "failed"') do (
if not "%%a" equ "" (
echo.%%a
echo.%%c
)
)
[/QUOTE]

devcom, what does the carat do in the type line? (type dsrm_log.txt ^| findstr "failed"). Is it an escape character?

\\uSlackr
Code: [Select]@echo off

for /f "tokens=1-3* delims=:" %%a in ('dsrm cn=bob1,ou=workstations,dc=ourcompany,dc=com -noprompt 1>nul ^|findstr "failed"') do (
if not "%%a" equ "" (
echo.%%a
echo.%%c
)
)
try thisQuote from: devcom on May 04, 2009, 10:25:53 AM
Code: [Select]@echo off

for /f "tokens=1-3* delims=:" %%a in ('dsrm cn=bob1,ou=workstations,dc=ourcompany,dc=com -noprompt 1>nul ^|findstr "failed"') do (
if not "%%a" equ "" (
echo.%%a
echo.%%c
)
)

'for' doesn't like the redirection characters in the command. I've tried a couple things to get around this to no avail.

Also it appears that dsrm sends the error message to stderr and therefore is not being captured by the for command. I'm currently working with this code:

Code: [Select] del %tempout%
dsrm %CN% -noprompt 2>>%tempout%
for /f "tokens=1,2 delims=: " %%a in (%tempout%) do (
echo b:%%b
if /i %%b EQU failed echo "failed"
)
to send stderr to a file and read it from there.

\\uSlackr





devcom, I need a little more help, if you please. I couldn't make your code work as the for command barfed on the >1. Here is the code I wound up with. It sends the stderr output of dsrm to a temp file and looks at that for results (I call is as a subroutine with the CN as a parameter)

Code: [Select]:DeleteAcct2
set CN=%1
if %MODE%==Prod (
del %tempout%
dsrm %CN% -noprompt 2>>%tempout% 1>nul
for /f "tokens=1,2 delims=: " %%a in (%tempout%) do (
if /i %%b EQU failed (
echo "Error deleting %CN%"
set /a ErrCount+=1
) else (
echo Computer account deleted: %CN%
set /a ActCount+=1
)
)
) else (
echo "Mode is %MODE% - not deleting, %CN% >>%inactlog%
)
goto :EOFThis seems to work, except the output of the command is two lines and this code attempts to process both lines:
Code: [Select]dsrm failed:CN=cn=bob1,ou=workstations,dc=ourcompany,dc=com:The directory service can perform the requested operation only on a leaf object.
type dsrm /? for help.
How can I stop the for loop from processing the second line?

about that last error you get
Code: [Select]@echo off

for /f "tokens=1-3* delims=:" %%a in ('dsrm cn=bob1,ou=workstations,dc=ourcompany,dc=com -noprompt 1>nul ^|findstr "failed"') do (
if not "%%a" equ "" (
echo.%%a
echo.%%c
)
)
in for loop you need to escape characters so it must look like 1^>nul


back to last question,
the easiest way would be using some kind of counter like this:

Code: [Select]setlocal enabledelayedexpansion

set num=0
for /f "tokens=1,2 delims=: " %%a in (%tempout%) do (
if /i %%b EQU failed (
if !num! equ 0 echo "Error deleting %CN%"
set /a num+=1
set /a ErrCount+=1
) else (
echo Computer account deleted: %CN%
set /a ActCount+=1
)

if you want ask question about why i use !! insted of %% google delayed expansionOK, this makes sense and I made it all work (well, almost). I now understand how to escape certain characters - and that's a good thing. Here's my current code:

Code: [Select]:DeleteAcct
::Disable and flag the account if not already disabled
set CN=%1
if %MODE%==Prod (
for /f "tokens=2 delims=: " %%c in ('dsrm %CN% -noprompt 2^>^&1 ^|findstr "failed" ') do (
if /i %%c EQU failed (
echo "Error deleting %CN%"
echo "Error deleting %CN%" >>%errlog%
set /a ErrCount+=1
) else (
echo "Computer account deleted: %CN%" >> %actlog%
echo "Computer account deleted: %CN%"
set /a ActCount+=1
)
)
) else (
echo "Mode is %MODE% - not deleting, %CN% >>%inactlog%
)
goto :EOF
The problem now is that if the delete suceeds, the output in the for command is nothing and the code below it doesn't execute. Thus I get to confirmation of the delete. I can work around it by "assuming" success, but we all know where that gets us. Any thoughts on that?


In fact, this solution depends on failure string always containing the word 'failed' .I'm starting to think batch scripting may not be the best solution for this...

\\uSlackrdevcom, thanks for the assist. Here's where I landed.

  • I modified the script to assume a successful delete and clean up if it fails. So I increment the delete counter and decrement it if there is a problem.
  • I then saw a post about having dsrm delete the problem objects the correct way. So, I added the -subtree switch - which makes me nervous. So here's the final code (well the delete routine)


Code: [Select]if %MODE%==Prod (
echo "Trying to delete computer account: %CN%" >> %actlog%
echo "Trying to delete computer account: %CN%"
set /a ActCount+=1
for /f "tokens=2 delims=: " %%c in ('dsrm %CN% -subtree -noprompt 2^>^&1 ^|findstr "failed" ') do (
if /i %%c EQU failed (
echo "Error deleting %CN%"
echo "Error deleting %CN%" >>%errlog%
set /a ErrCount+=1
set /a ActCount-=1
) else (
echo "Computer account deleted: %CN%" >> %actlog%
echo "Computer account deleted: %CN%"
set /a ActCount+=1
)
)
) else (
echo "Mode is %MODE% - not deleting, %CN% >>%inactlog%
)
goto :EOF



All in all, a good batch file exercise!
3241.

Solve : i need a information about DOS batch script?

Answer» hello evry one
i just want to know how to make a DOS BATCH script file (.bat) run automatically ?

for example a make this simple code : Code: [Select]@ echo off
mkdir mydirectry so how to make it run automatically ? Look at

at /?
And that should help you. Please note that the computer must be on and logged in for programs to run automatically. Quote from: renalte16 on November 07, 2009, 07:13:30 AM
hello evry one
i just want to know how to make a DOS batch script file (.bat) run automatically ?

for example a make this simple code : Code: [Select]@ echo off
mkdir mydirectry so how to make it run automatically ?


C:\batextra>type runwithat.bat
Code: [Select]@ echo off

cd \
cd mydirectory

del myfile.txt
cd \
rd mydirectory

mkdir mydirectory

cd c:\mydirectory

echo hello > myfile.txt

dir
(I will schedule runwithat.bat with "At" or scheduled tasks and post back.)

Output:


C:\batextra>runwithat.bat
Volume in drive C has no label.
Volume Serial Number is F4A3-D6B3

Directory of C:\mydirectory

11/07/2009 12:52 PM .
11/07/2009 12:52 PM ..
11/07/2009 12:52 PM 10 myfile.txt
1 File(s) 10 bytes
2 Dir(s) 304,406,917,120 bytes free
Press any key to continue . . .
Volume in drive C has no label.
Volume Serial Number is F4A3-D6B3

Directory of C:\mydirectory

11/07/2009 12:54 PM .
11/07/2009 12:54 PM ..
11/07/2009 12:54 PM 10 myfile.txt
1 File(s) 10 bytes
2 Dir(s) 304,406,917,120 bytes free

C:\mydirectory>Following information from XP Help and Support section:

<<<"To schedule a new task
Open Scheduled Tasks.
Double-click Add Scheduled Task.
Follow the instructions in the Scheduled Task Wizard.
Notes

To open Scheduled Tasks, click Start, click All Programs, point to Accessories, point to System Tools, and then click Scheduled Tasks.
If you want to configure advanced settings for the task, select the Open advanced properties for this task when I click FINISH check box on the final PAGE of the wizard.
Confirm that the system date and time on your computer are accurate, because Scheduled Tasks relies on this information to run scheduled tasks. To verify or change this information, double-click the time indicator on the taskbar.
If you leave the password blank and you want the task to run when you are logged on, open the task. On the Task tab, select the Run only if logged on check box. The task will run at its scheduled time when the user who created the task is logged on to the computer.">>


C:\batextra>at 13:40 "C:\batextra\runwithat.bat"
ADDED a new job with job ID = 1

C:\batextra>at
Status ID Day Time Command Line
-------------------------------------------------------------------------------
1 Today 1:40 PM C:\batextra\runwithat.bat

C:\batextra>type runwithat.bat
@ echo off

cd \
cd mydirectory


del myfile.txt
cd \
rd mydirectory

mkdir mydirectory

cd c:\mydirectory

echo hello > myfile.txt


C:\batextra>cd ..

C:\>cd mydirectory

C:\mydirectory>dir
Volume in drive C has no label.
Volume Serial Number is F4A3-D6B3

Directory of C:\mydirectory

11/07/2009 01:40 PM .
11/07/2009 01:40 PM ..
11/07/2009 01:40 PM 10 myfile.txt
1 File(s) 10 bytes
2 Dir(s) 304,405,028,864 bytes free

C:\mydirectory>
3242.

Solve : cprompt?

Answer»

give command
net users
it will show all the user in LAN
also ADMIN
now for changing password of admin it will ASK for authentication for this
authentication off
what cmd is used?
can any one help please>>>>>>>>>>>>>>>please give reasons why

Quote

now for changing password of admin it will ask for authentication for this
authentication off

hmmmm

May be want to hack or change the others passwords ?Quote from: VIKRAM Varaprasad on November 07, 2009, 05:20:00 AM
May be want to hack or change the others passwords ?

yes, that is what I wondered. If so, the answer is NO.
There is the chance to do it, but we don't provoke you doing so.......
3243.

Solve : copy batch check drive?

Answer»

I want to have a batch file that copies from C to A, typical but the THING is with san disk and other usb drives it CHANGES the letter and instead of changeing it in the batch. Is there a way for it to go and see if its there if not go to the next letter.I am not familiar with batch but can't you just add a folder to the usb drive and have the batch search for the folder then copy the info if the folder is found.that would seem like more of a PAIN then anything. Then he would have to wait a good while till it found it then.

3244.

Solve : Set sub-variable...??

Answer»

I was RUNNING into some problems with set. I was trying to replace the word "Desktop" (without the quotes) with

"%userprofile%\Desktop (the quote at the front is needed).

Here is my code:
Code: [Select]set /p command=
"delims= " %%a in ("%command%") do set comma=%%a
if /i %comma%==copy set command=%command:desktop="%userprofile%\Desktop%
if /i %comma%==copy set command=%command%"
%command%
When I tried doing Copy Desktop\Messages.txt (which DOES exist) I get a file not found ERROR...

What am I doing wrong?

For /f missing from line 2.

Insert Echo %command% as line 4 to see what %command% is being set to, it looks slightly dodgy.

Try this as an alternative:
Code: [Select]Set /p command=Enter Command Path and Filename:

For /f %%a in ("%command%") do set comma=%%a

if %comma%==copy pushd %userprofile%

%command%

popd
Quote from: Dusty on April 10, 2009, 02:50:17 AM

For /f missing from line 2.

Insert Echo %command% as line 4 to see what %command% is being set to, it looks slightly dodgy.

Try this as an alternative:
Code: [Select]Set /p command=Enter Command Path and Filename:

For /f %%a in ("%command%") do set comma=%%a

if %comma%==copy pushd %userprofile%

%command%

popd
When I used FOR while doing the other commands, it worked just fine...But how does your code work dusty?Quote
But how does your code work dusty?

Well, I hope it works.

When it's run you would respond to the Set /p with copy desktop\messages.txt

What the destination path\filename is didn't appear in your original post.

The NEXT line simply sets %%a to the first entry in %command% which would be copy

The If command tests %comma% for copy and if true Pushd's the default directory to %userprofile% which is C:\Documents and Settings\Username

Then %command% is executed

Popd then returns the default directory to where it was before Pushd was executed.

Hope this helps and that I haven't made a FOOL of myself again Quote from: Dusty on April 10, 2009, 07:20:52 AM
Well, I hope it works.

When it's run you would respond to the Set /p with copy desktop\messages.txt

What the destination path\filename is didn't appear in your original post.

The next line simply sets %%a to the first entry in %command% which would be copy

The If command tests %comma% for copy and if true Pushd's the default directory to %userprofile% which is C:\Documents and Settings\Username

Then %command% is executed

Popd then returns the default directory to where it was before Pushd was executed.

Hope this helps and that I haven't made a fool of myself again
I'll try. But why did you change the FOR loop? Did I do it wrong.

EDIT: Doesn't work...I think it's because %userprofile% has spaces in it. I think the only way around it is for a sub-variable...Quote from: Helpmeh
EDIT: Doesn't work...I think it's because %userprofile% has spaces in it. I think the only way around it is for a sub-variable...

I don't understand why it's not working for you. Any time I run the script and enter Copy Desktop\Messages.txt the file is copied to the default directory which is C:\Documents and Settings\Dusty

Any time I run the script and enter Copy Desktop\Messages.txt d:\temp\ the file is copied to d:\temp\

Do you get the advisory message "1 File(s) copied"?

Quote from: Helpmeh
But why did you change the FOR loop? Did I do it wrong.

I think the only change I made to the For loop was to not include the "delims= ". Space is one of the default delimiters and therefore does not have to be specified. No, you didn't do it wrong, both methods produce the same result.

Returning to your original script Quote
set /p command=
"for /f delims= " %%a in ("%command%") do set comma=%%a
if /i %comma%==copy set command=%command:desktop="%userprofile%\Desktop%
if /i %comma%==copy set command=%command%"
%command%

This set Command to Code: [Select]"\messages.txtuserprofile" whereas what was wanted was Code: [Select]copy "c:\documents and settings\user\desktop\messages.txt"
Change the first If command line to
Code: [Select]If /i %comma%==copy set command=%comma% "%userprofile%\%command:~5%"
The second If command line is not required.

The entire script could now be:Code: [Select]set /p command=Enter Command Path\Filename

for /f "delims= " %%a in ("%command%") do set comma=%%a

if /i %comma%==copy set command=%comma% "%userprofile%\%command:~5%"

%command%
A shorter version could be:
Code: [Select]set /p command=Enter Command Path\Filename
if /i %command:~0,4%==copy set command=%command:~0,4% "%userprofile%\%command:~5%"
%command%




Quote from: Dusty on April 12, 2009, 10:42:53 PM
Returning to your original script
This set Command to Code: [Select]"\messages.txtuserprofile" whereas what was wanted was Code: [Select]copy "c:\documents and settings\user\desktop\messages.txt"
Change the first If command line to
Code: [Select]If /i %comma%==copy set command=%comma% "%userprofile%\%command:~5%"
The second If command line is not required.

The entire script could now be:Code: [Select]set /p command=Enter Command Path\Filename

for /f "delims= " %%a in ("%command%") do set comma=%%a

if /i %comma%==copy set command=%comma% "%userprofile%\%command:~5%"

%command%
A shorter version could be:
Code: [Select]set /p command=Enter Command Path\Filename
if /i %command:~0,4%==copy set command=%command:~0,4% "%userprofile%\%command:~5%"
%command%






What does the ~5 do in this case...I saw an example script when I first started scripting in batch using ~ and a number to cut off certain parts of a variable...and the file won't have the same length...Quote from: Dusty on April 10, 2009, 10:40:51 PM
I don't understand why it's not working for you. Any time I run the script and enter Copy Desktop\Messages.txt the file is copied to the default directory which is C:\Documents and Settings\Dusty

Any time I run the script and enter Copy Desktop\Messages.txt d:\temp\ the file is copied to d:\temp\

Do you get the advisory message "1 File(s) copied"?

I think the only change I made to the For loop was to not include the "delims= ". Space is one of the default delimiters and therefore does not have to be specified. No, you didn't do it wrong, both methods produce the same result.



I got a message stating that the file can't be found, secondly: Thanks, I didn't know that, and FINALLY: Sorry for the double-post...even though we both did Dusty


Edit: THANKS! It works GREAT!!!
3245.

Solve : /D:MM-DD-YYYY troubles .... for sorting data by year into folders?

Answer»

Trying to group about 374GB of data created over the last 9 years at C:\data into folders by year. Problem I have is that the xcopy /s/d:MM-DD-YYYY/y "/D"switch will grab all data on or after the date specified, and I cant seem to create a range to only grab say 01-01-2008 to 12-31-2008, so I have to have it perform a clean up after xcopying the data to the destination that will remove this newer data from the original SOURCE path so that the next xcopy routine can grab the next group of 01-01-2007 to 12-31-2007 data without passing the newer 2008 and 2009 data into the 2007 folder. ( Scratching my head on how to delete only this range of date/time stamped data after it is xcopied??? )

Below is an example of what I have so far, with explainations as to what I believe needs to happen in < > between each xcopy /s/d:MM-DD-YYYY/y routine.

Run from C:

xcopy c:\data\*.* c:\test1\2009\*.* /s/d:01-01-2009/y
>
xcopy c:\data\*.* c:\test1\2008\*.* /s/d:01-01-2008/y
>
xcopy c:\data\*.* c:\test1\2007\*.* /s/d:01-01-2007/y
>
xcopy c:\data\*.* c:\test1\2006\*.* /s/d:01-01-2006/y
>
xcopy c:\data\*.* c:\test1\2005\*.* /s/d:01-01-2005/y
>
xcopy c:\data\*.* c:\test1\2004\*.* /s/d:01-01-2004/y
>
xcopy c:\data\*.* c:\test1\2003\*.* /s/d:01-01-2003/y
>
xcopy c:\data\*.* c:\test1\2002\*.* /s/d:01-01-2002/y
>
xcopy c:\data\*.* c:\test1\2001\*.* /s/d:01-01-2001/y
>
xcopy c:\data\*.* c:\test1\2000\*.* /s/d:01-01-2000/y
rd data

This rd data is the final clean up to remove c:\data after all data was moved into the grouped years with subdirectory data tree intact

Problem I have is how do you delete only data with date/time stamp of on say 01-01-2009 or after for each year to avoid the "/D:MM-DD-YYYY" passing newer data into what should be only the older specified directory path. I also want to keep the "/S" switch to maintain the directory path structure for data moved into the correct year of date/time stamp.

Any suggestions or code solutions vs the path I am taking with this project to group data by year?

I am guessing that there may be a better way and I am really butchering the purpose of the xcopy command by creating an individual instruction set for each year.

((OR)) can this be achieved without destroying the original C:\data source location to have the mixed data at c:\data and the sorted by year c:\test1\(year) locations by being able to set a date/time stamp range of 01-01-year to 12-31-year ((if free space permitted!))

Thanks for your help in advance to the solution that you provide to my coding madness ... Quote from: DaveLembke on April 10, 2009, 03:08:07 PM

Trying to group about 374GB of data created over the last 9 years at C:\data into folders by year. Problem I have is that the xcopy /s/d:MM-DD-YYYY/y "/D"switch will grab all data on or after the date specified, and I cant seem to create a range to only grab say 01-01-2008 to 12-31-2008, so I have to have it perform a clean up after xcopying the data to the destination that will remove this newer data from the original source path so that the next xcopy routine can grab the next group of 01-01-2007 to 12-31-2007 data without passing the newer 2008 and 2009 data into the 2007 folder. ( Scratching my head on how to delete only this range of date/time stamped data after it is xcopied??? )

Below is an example of what I have so far, with explainations as to what I believe needs to happen in < > between each xcopy /s/d:MM-DD-YYYY/y routine.

Run from C:

xcopy c:\data\*.* c:\test1\2009\*.* /s/d:01-01-2009/y
<delete 2009 data so that next routine doesnt pass 2009 data to 2008. >
xcopy c:\data\*.* c:\test1\2008\*.* /s/d:01-01-2008/y
<delete 2008 data so that next routine doesnt pass 2008 data to 2007. >
xcopy c:\data\*.* c:\test1\2007\*.* /s/d:01-01-2007/y
<delete 2007 data so that next routine doesnt pass 2007 data to 2006. >
xcopy c:\data\*.* c:\test1\2006\*.* /s/d:01-01-2006/y
<delete 2006 data so that next routine doesnt pass 2006 data to 2005. >
xcopy c:\data\*.* c:\test1\2005\*.* /s/d:01-01-2005/y
<delete 2005 data so that next routine doesnt pass 2005 data to 2004. >
xcopy c:\data\*.* c:\test1\2004\*.* /s/d:01-01-2004/y
<delete 2004 data so that next routine doesnt pass 2004 data to 2003. >
xcopy c:\data\*.* c:\test1\2003\*.* /s/d:01-01-2003/y
<delete 2003 data so that next routine doesnt pass 2003 data to 2002. >
xcopy c:\data\*.* c:\test1\2002\*.* /s/d:01-01-2002/y
<delete 2002 data so that next routine doesnt pass 2002 data to 2001. >
xcopy c:\data\*.* c:\test1\2001\*.* /s/d:01-01-2001/y
<delete 2001 data so that next routine doesnt pass 2001 data to 2000. >
xcopy c:\data\*.* c:\test1\2000\*.* /s/d:01-01-2000/y
rd data

This rd data is the final clean up to remove c:\data after all data was moved into the grouped years with subdirectory data tree intact

Problem I have is how do you delete only data with date/time stamp of on say 01-01-2009 or after for each year to avoid the "/D:MM-DD-YYYY" passing newer data into what should be only the older specified directory path. I also want to keep the "/S" switch to maintain the directory path structure for data moved into the correct year of date/time stamp.

Any suggestions or code solutions vs the path I am taking with this project to group data by year?

I am guessing that there may be a better way and I am really butchering the purpose of the xcopy command by creating an individual instruction set for each year.

((OR)) can this be achieved without destroying the original C:\data source location to have the mixed data at c:\data and the sorted by year c:\test1\(year) locations by being able to set a date/time stamp range of 01-01-year to 12-31-year ((if free space permitted!))

Thanks for your help in advance to the solution that you provide to my coding madness ...
I know one POSSIBLE way...but I'm not experienced enough to actually do it. If after each line, you delete the files created after 01-01-YEAR (you already copied them to a different directory). It could be acomplished with FOR...I think Dave, maybe you should consider XXCOPY, which is like XCOPY on steroids, which has a free-for-personal-use version. It is designed to have similar command set to XCOPY.

There is also ROBOCOPY, a Microsoft admin tool, which, again, is designed to be be an easy transition from XCOPY, but I think for your problem as mentioned in this thread, consider this:

XXCOPY features include:

Quote
8. Select the range of file date

XXCOPY c:\ d:\backup\ /S /DA:1999-1-1 /DB:1999-6-30

The file range of Date betwen Jan 1 and Jun 30 of 1999.
/DA (On-or-After) and /DB (On-or-Before) bracket the date range.


http://www.xxcopy.com/index.htm

Quote from: Dias de verano on April 10, 2009, 04:56:52 PM
Maybe you should consider XXCOPY, which is like XCOPY on steroids, which has a free-for-personal-use version. It is designed to have similar command set to XCOPY.

There is also ROBOCOPY, a Microsoft admin tool, which, again, is designed to be be an easy transition from XCOPY, but I think for your problem as mentioned in this thread, consider this:

XXCOPY features include:

http://www.xxcopy.com/index.htm


It says it's compatible with XPSP3, as you may or may not know, I can't get that...can I still use XXCopy?Quote from: Helpmeh on April 10, 2009, 04:58:40 PM
It says it's compatible with XPSP3, as you may or may not know, I can't get that...can I still use XXCopy?

Compatible means it works OK with SP3. It doesn't mean you must have it.
Quote from: Dias de verano on April 10, 2009, 05:04:36 PM
Compatible means it works OK with SP3. It doesn't mean you must have it.

Ktry this code, it's not optimized, if you have lot's of small size files, it might run slow. i am not good at xcopy, so i use copy command instead.
Code: [Select]@echo off & setlocal enabledelayedexpansion
pushd c:\data\ || goto:eof

::get SYSTEM date format
set f=
for /f "skip=1 tokens=2-4* delims=(./-)" %%1 in ('echo.^|date') do (
set 1=%%1
set 2=%%2
set 3=%%3
for %%$ in (1 2 3) do if yy==!%%$! set f=!f!%%%%$
)
echo date format=%f%

::copy based on year modified
for /r %%a in (*) do (
for /f "tokens=1-3* delims=./- " %%1 in ("%%~ta") do set yy=%f%
set dest=%%~dpa
set dest=c:\test1\!yy!\!dest:%cd%\=!
if not exist !dest! md "!dest!" && echo folder !dest! created
echo copying %%a --^> !dest!
copy "%%a" "!dest!"
)
popd

WARNING: TRY ON TEST DATA FIRST. i am not responsible for any data lost.Thanks Dias and Reno ... I will give both of your solutions a try in the morning and see which one works better. The XXCOPY seems pretty straight forward with the ability to set range like I need. But I also am interested in checking out Reno's coded solution as well to see how well that works too.

Thanks for the effort of all who contributed...based on this info I think I should be all set now. Reno .... VERY Impressed with your solution...Works perfect and no need to delete data from the C:\data location.

Now off to sort 374GB of data after a successful test of about 50mb

Thanks sooo much !!!! Quote from: DaveLembke on April 11, 2009, 11:43:45 AM
Reno .... VERY Impressed with your solution...Works perfect and no need to delete data from the C:\data location.

Now off to sort 374GB of data after a successful test of about 50mb

Thanks sooo much !!!!
If you run into any problems later, feel free to ask.
3246.

Solve : How to escape from ampersand.?

Answer»

Is there any way to REPLACE the occurance of the ampersand character in a string in Dos?
Say I want to replace "&" with the string ampersand.
I've tried:
CODE: [Select]set str=%str:&=ampersand%

And it doesn't work. The string is truncated at the position of the ampersand and I get an error.they say that in DOS, you use carrot ^ to escape. but if you can use tools like sed (see my sig)
Code: [Select]C:\test>more file.txt
this is a line with & blah

C:\test>sed "s/\&/AMPER/" file.txt
this is a line with amper blah

Quote

they say that in DOS, you use carrot ^ to escape. but if you can use tools like sed (see my sig)
Code:

C:\test>more file.txt
this is a line with & blah

C:\test>sed "s/\&/amper/" file.txt
this is a line with amper blah
This requires an external utility which I was hoping top avoid, besides I don't want to change the occurrences of & in an entire file only a string in a batch file.
(but thanks for your reply anyway) Try this

Code: [Select]set "str=%str:&=ampersand%"

Hi-
Quote
Code:

set "str=%str:&=ampersand%"

Yes this works ,but I guess I should mention that I'm still working on getting the target to shortcuts on the desktop
and, while my batch file works for .lnk files, it also works for .URL files on the desktop as well..
Except for if the .URL file's target contains an ampersand.
Then the target returned from DecodeShortCut.vbs is truncated, so the substitution fails because there is no & to replace.

Code: [Select]@echo off
Set SHORTCUT=%~1
echo set WshShell = WScript.CreateObject("WScript.Shell")>DecodeShortCut.vbs
echo set Lnk = WshShell.CreateShortcut(WScript.Arguments.Unnamed(0))>>DecodeShortCut.vbs
echo wscript.Echo Lnk.TargetPath>>DecodeShortCut.vbs
set vbscript=C:\WINDOWS\system32\cscript DecodeShortCut.vbs
For /f "delims=" %%T in ( ' %vbscript% "%Shortcut%" ' ) do set target=%%T
del DecodeShortCut.vbs
Echo Shortcut %shortcut%
Echo Target %target%
set target=%target:?=questionmark%
set "target=%target:&%=ampersand%"
Echo Target %target%>target.txtIs there some way to catch this?
Like for example:
Code: [Select]@echo off
Set Shortcut=%~1
echo set WshShell = WScript.CreateObject("WScript.Shell")>DecodeShortCut.vbs
echo set Lnk = WshShell.CreateShortcut(WScript.Arguments.Unnamed(0))>>DecodeShortCut.vbs
set targetpath=Lnk.TargetPath
set "targetpath=%targetpath:&%=ampersand%"
echo wscript.Echo targetpath>>DecodeShortCut.vbs
set vbscript=C:\WINDOWS\system32\cscript DecodeShortCut.vbs
For /f "delims=" %%T in ( ' %vbscript% "%Shortcut%" ' ) do set target=%%T
del DecodeShortCut.vbs
Echo Shortcut %shortcut%
Echo Target %target%
set target=%target:?=questionmark%
set "target=%target:&%=ampersand%"
Echo Target %target%>target.txtDo you think this might work?Quote
Do you think this might work?
No I tested it and it does not work.
Somehow the call to:
Code: [Select]echo wscript.Echo Lnk.TargetPath>>DecodeShortCut.vbs
returns a string which is already truncated at the position of the &!!Quote from: nubia on April 12, 2009, 11:25:46 AM
No I tested it and it does not work.
Somehow the call to:
Code: [Select]echo wscript.Echo Lnk.TargetPath>>DecodeShortCut.vbs
returns a string which is already truncated at the position of the &!!

You cannot mix batch and vbs code in that way.
Quote
You cannot mix batch and vbs code in that way.
I see...so is it possible to add a line to DecodeShortCut.vbs that will do the replace?
I'm sorry but I know less of vbs code than I do of batch (which is, sad to say , not much).DecodeShortcut.vbs

Code: [Select]
Set WshShell = WScript.CreateObject("WScript.Shell")
shortcut = WScript.Arguments.Unnamed(0)
Set Lnk = WshShell.CreateShortcut(shortcut)
Target = Lnk.TargetPath
If InStr(Target,"&")>0 Then
Wscript.echo Replace (Target,"&","AMPERSAND")
Else
Wscript.echo Target
End If
set Lnk = Nothing


Batch file to use it

Code: [Select]
@echo off
Set Shortcut=%~1
set vbscript=C:\WINDOWS\system32\cscript DecodeShortCut.vbs
For /f "delims=" %%T in ( ' %vbscript% "%Shortcut%" ' ) do set target=%%T
Echo Shortcut %shortcut%
Echo Target %target%
Echo Target %target%>target.txt

Quote from: Dias de verano on April 12, 2009, 12:47:51 AM
Try this

Code: [Select]set "str=%str:&=ampersand%"


Would that work for precent signs too?
3247.

Solve : Batch pgm to add datetime to filenames, then save to other folder?

Answer»

Thank you in advance for any help with this.

As the name implies, I am a rookie with DOS so please bear with me. I have SEARCHED the forum for the last few days and have found pieces of of what I'm looking for, but have not been able to combine them into what I need.

What I need is a batch program that will do the following:
1. Select files all of the .txt files from folder 1
2. Add the date and time to the beginning of each of the selected filenames
3. Save the new files to folder 2
4. Remove the original files from folder 1

If there is a be sequence of steps, I'm open to suggestions. This process will be used to Archive text files of data that have been sent out via EDI. New .txt files are generated daily and will have the same file names as the day before.

I have seen the POST for Renaming a file to INCLUDE BOTH Date & Time Stamp, but it is only for one file. How do I get it to process all of the .txt files in the folder?

Thanks!

The for loop will work for you. Use the code you already found to name the file wrap it in a loop such as this:

Code: [Select]for /d %a in (\folder1\*.txt) do (

mv %a \folder2\newfilename.txt

)

REPLACE newfilename.txt with the filename you generated with the datetime stamp. Be careful to test this on a test directory - not the real data, plus you need a way to ensure the new files don't all have the same name.
Thanks for the quick reply.
I'm still struggling though for lack of understanding. Not quite sure how to "Wrap" in a FOR loop. Here is what I have:

@echo off

for /f "tokens=1-5 delims= " %%A in ( ' cscript //nologo TimeStamp.vbs ' ) do (
set dd=%%A
set MM=%%B
set YYYY=%%C
set hh=%%D
set mn=%%E
)

if %dd% LEQ 9 set dd=0%dd%
if %mm% LEQ 9 set mm=0%mm%
if %hh% LEQ 9 set hh=0%hh%
if %mn% LEQ 9 set mn=0%mn%

rename Customer01 "c:\test folder\temp\%yyyy%%mm%%dd%%hh%%mn%Customer01.txt"

End----

----------------
Here is what is in TimeStamp.vbs:

dd=day(date)
mm=month(date)
yyyy=year(date)
hh=hour(time)
mn=minute(time)
wscript.echo dd&" "&mm&" "&yyyy&" "&hh&" "&mn
------------------


How would I wrap this and set it so that it will take care of Customer01 --- CustomerXX?

Thanks!This may work but I can't stress enough how you have to try to understand why.

Code: [Select]@echo off

for /f "tokens=1-5 delims= " %%A in ( ' cscript //nologo TimeStamp.vbs ' ) do (
set dd=%%A
set mm=%%B
set yyyy=%%C
set hh=%%D
set mn=%%E
)

if %dd% LEQ 9 set dd=0%dd%
if %mm% LEQ 9 set mm=0%mm%
if %hh% LEQ 9 set hh=0%hh%
if %mn% LEQ 9 set mn=0%mn%

for %%A in (\folder1\*.txt) do (
move %%A \new_folder\%yyyy%%mm%%dd%%hh%%mn%%%~nxA
)

It relies on the code you posted earlier including the vbscript. Perhaps it can be replaced, but I didn't try. What I changed is rename -> move as you cannot change directories with a rename command.

I also added %~nxA to the end of the new filename. If you look at the help of the FOR command (FOR /?) you'll see that it replaces that with just the name of the file (no path info)

Hope this helps.uSlackr,

Thanks! This is working the way I need it to. I only have on little snag remaining....

in the live environment, the path contains a folder with a blank space (Program Files). I've tried using double quotes, but it doesn't seem to like them. Probably poor syntax on my part


Here is what worked in my test environment:

@echo off

for /f "tokens=1-5 delims= " %%A in ( ' cscript //nologo TimeStamp.vbs ' ) do (
set dd=%%A
set mm=%%B
set yyyy=%%C
set hh=%%D
set mn=%%E
)

if %dd% LEQ 9 set dd=0%dd%
if %mm% LEQ 9 set mm=0%mm%
if %hh% LEQ 9 set hh=0%hh%
if %mn% LEQ 9 set mn=0%mn%

for %%A in (c:\TestFolder\temp\*.txt) do (
move %%A c:\TestFolder\temp2\%yyyy%%mm%%dd%_%hh%%mn%_%%~nxA
)


I need to replace TestFolder with Program Files.

Thanks!USlacker,

Hey... I finally got the quotes set up and t's working!

Thank you so much for your help!

3248.

Solve : MS DOS Ping batch file?

Answer»

I'm sending a system to Brazil. One of the ISSUES with this system is that I have IP addresses that range from 192.168.0.1 through 192.168.0.12.

I can write individual commands to PING but when I do they run away, get stuck in a loop. I've tried to batch a few pings together but the first one loops.

I've been away from DOS programming for so long I don't remember the basics.

My style of programming is more to the function block and ladder LOGIC type applications. Any higher level geeks that can help me out?
Its not clear from this what you are trying to accomplish. Can you add further explanation?When you set up a network in INDUSTRIAL control the user tends to want to blame any outage on lack of communication between controllers. If there was a batch file that could be invoked to ping all of the addresses in the system that could be eliminated with the push from one single button.

I'm trying to write a batch file that will ping each address from the first address to the last, 192.168.0.1 through 192.168.0.14, with a single click of a button.


Try this:
for /l %i in (1,1,14) do ping 192.168.0.%i

3249.

Solve : Sleep command in Vista?

Answer»

Hi

I am using the code below to perform a 'sleep' in batch files using vista. It is saved as 'sleep.bat' in the System32 FOLDER:

choice /c 1 /d 1 /t 5 > nul

As it is this would sleep for 5 seconds, but I really need a way to make it variable by being able to run it as 'sleep 2', 'sleep 3' or whatever is required by just changing a number after it in another batch command.

When I had XP the Windows 2003 Resource Kit took care of this. I don't want to have more than ONE sleep file in the System32 folder, have a set of sleep files with different names and associated times or be running other batches or code to set and replace etc. if I can avoid it.

Does ANYONE have any ideas? Any help appreciated.


Thanks
some time ago, i think, macdad- did that:
here is code:

Code: [Select]@echo off
setlocal enableextensions

:SETUP
set sec=0
set /a sec=%1
set cout=0

:LOOP
set time_1=%time:~-4,1%
:ADD
set time_2=%time:~-4,1%
if not %time_1%==%time_2% (GOTO COUNT)
goto ADD

:COUNT
set /a cout+=1
if %cout% equ %sec% (goto :EOF)
goto LOOP

a little bit edited by me i think (i dont remember )

EDIT:

save this as sleep.bat and put to C:\windows\system32\
and you can use it by ex. Code: [Select]sleep 3
EDIT2:

if you dont want to put this to system32 just include this bat to you script and call it Does exactly what I need... Thanks devcom.
What's wrong with this?

Code: [Select]choice /c 1 /d 1 /t %1 > nulNothing. Yes this also works. Thanks.

As you might deduce from my handle my base is with MS Access. I can obviously see what difference the % makes, and get the idea of what devcoms code is doing (In the end I'm just happy it works), but if you could let me KNOW what the % does actually represent that would be useful for me.

Thanks both for your help...

%1 through %9 are command line arguments.


For example, if somebody invoked your batch like this:

Code: [Select]batch filename.txt /d /e

then %1 would be filename.txt, %2 would be /d, and %3 would be /e.

obviously these are different if you specify something else on the commandline.OK, I see. Thanks a lot for all the replies. Quote from: BC_Programmer on April 09, 2009, 06:04:38 PM

%1 through %9 are command line arguments.


For example, if somebody invoked your batch like this:

Code: [Select]batch filename.txt /d /e

then %1 would be filename.txt, %2 would be /d, and %3 would be /e.

obviously these are different if you specify something else on the commandline.

I want to make my own sleep command, but my code doesn't work.

Code: [Select]@echo off
if not "%2"=="/m" ping localhost -n %1 -w 1000 > nul & exit
ping localhost -n %1 -w %3 > nulI want it so if they type sleep 2 it will sleep for 2 seconds, but if they type sleep 2 /m 1500 It would sleep for 2*1500 miliseconds.

It just seems to ignore the /m and only runs the first part...why don't you enter echo commands that echo what %1 through %9 are?

EDIT:


just remembered something:


instead of "hard-coding" where the parameter is, use environment variables to store the various settings before you start executing.

you can use the SHIFT command- for example:


Code: [Select]
REM INIT the vars to 0...
SET MSWITCH=0
SET FNAME=

:START
SET GOTSWITCH=0
if %1!==! goto CONTINUE

REM TEST %1 here, for switches, filenames, etc.

if "%1"=="/m" SET MSWITCH=1 & SET GOTSWITCH=1
if "%1"=="/M" SET MSWITCH=1 & SET GOTSWITCH=1



if %GOTSWITCH%=0 set MCOUNT=%1

shift
GOTO START:

CONTINUE:

if %GOTSWITCH%=1 echo /m switch specified.
if %GOTSWITCH%=0 echo /m switch not specified.

echo count specified was %MCOUNT%

Quote from: BC_Programmer on April 10, 2009, 06:06:29 PM
why don't you enter echo commands that echo what %1 through %9 are?

EDIT:


just remembered something:


instead of "hard-coding" where the parameter is, use environment variables to store the various settings before you start executing.

you can use the SHIFT command- for example:


Code: [Select]
REM INIT the vars to 0...
SET MSWITCH=0
SET FNAME=

:START
SET GOTSWITCH=0
if %1!==! goto CONTINUE

REM TEST %1 here, for switches, filenames, etc.

if "%1"=="/m" SET MSWITCH=1 & SET GOTSWITCH=1
if "%1"=="/M" SET MSWITCH=1 & SET GOTSWITCH=1



if %GOTSWITCH%=0 set MCOUNT=%1

shift
GOTO START:

CONTINUE:

if %GOTSWITCH%=1 echo /m switch specified.
if %GOTSWITCH%=0 echo /m switch not specified.

echo count specified was %MCOUNT%

What???Quote

you can use the SHIFT command- for example:

That was the concept I was trying to get across.
3250.

Solve : What worning with my BAT script?

Answer»

i have 2 text file name: doc.txt and STRING.txt

Doc.txt
Code: [Select]hahah1
kikikik2
fefefefe3
anh3
gugugugu4
String.txt
Code: [Select]anh1
anh2
anh3
It was OK when i split my script to two part.

Code: [Select] findstr /xnc:%~1 doc.txt
echo %errorlevel%
and

Code: [Select] for /f %%i in (string.txt) do echo %%i
But when join 2 of them, i met the problem with %errorlevel%. Anybody can explain for me whats wrong in this case?

Code: [Select]@echo off
for /f %%i in (string.txt) do (
findstr /xnc:"%%i" doc.txt
if %errorlevel%==0 echo do nothing
if %errorlevel%==1 echo do something
)
Here is the picture
1. Using Google, study why we use "delayed expansion" in loops

2. Try this

@echo off
setlocal enabledelayedexpansion
for /f %%i in (string.txt) do (
findstr /xnc:"%%i" doc.txt
if !errorlevel!==0 echo do nothing
if !errorlevel!==1 echo do something
)
Thanks, Dias.

More question.
How can i insert a string in the end of a file without entering a new line.

needaddcata.txt
Code: [Select]41006200730065006E0063006500
43007500730074006F006D0065007200
4D00610069006E00740065006E0061006E0063006500
4F007400680065007200
520026004400
54007200610069006E0069006E006700

My code:

Code: [Select]@echo off
setlocal enabledelayedexpansion

for /f "tokens=3 delims= " %%i in ('reg query hkcu\software\microsoft\office\11.0\outlook\categories') do @echo %%i &GT; temp.txt
for /f %%i in (needaddcata.txt) do (
findstr /c:"%%i" temp.txt > nul
if !errorlevel!==1 echo %%i >> temp.txt
)
After my code run, the output file content:

temp.txt
730074006F006D00650072003B004D006100690 06E00740065006E0061006E00630065003B004D 0069007300630065006C006C0061006E0065006 F00750073003B004F0074006800650072003B00 50006500720073006F006E0061006C003B00500 068006F006E0065002000430061006C006C0073 003B005200260044003B0053007400610074007 50073003B005300740072006100740065006700 6900650073003B0053007500700070006C00690 06500720073003B00540069006D006500200026 00200045007800700065006E007300650073003 B0054007200610069006E0069006E0067003B00 5600490050003B00570061006900740069006E0 067003B000000
41006200730065006E0063006500
43007500730074006F006D0065007200

And if the output file was OK, how do i add that content in registry? because its require a hex.
reg add hkcu\software\microsoft\office\11.0\outlook\categories /v MasterList /t REG_BINARY /d " "


My script try to add some categories into MS Outlook "master category list". it just only add the MISSING category
Make sure you BACKUP for registry before doing anything.everyone pleaseeeee....