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.

1851.

Solve : How does one begin to use DOS?

Answer»

Hi, I am in giving away my old DOS based computer SYSTEM, to a very nice friend of the family. It's an IBM Personal System/2 MODEL 50.  It has been so long since i have used it that i am not sure if there is something seriously wrong with the system or not.  When booted up the only thing that comes to screen are some numbers, which read:
301
8602

162.
I have no idea what that means, all that is expected of this machine is to use the wordperfect5.0 which is already pre-loaded.  Please point me in the right direction.   thanksThose are error codes from the BIOS, so I SUSPECT the machine may not be all that healthy.  I don't have a reference, so I don't KNOW what errors you are getting, but I suspect at least the CMOS battery is dead and you've lost the disk settings...
Your CMOS battery is flat, your keyboard is missing or defective, and you have a video problem. Replace the CMOS battery (should be an oddball-looking pair of cells clipped somewhere, yank 'em and rig appropriate D-cell alkalines with a series diode to match the voltage), plug a known good keyboard in, and reseat all the internal cards and connectors, then see if it will boot without errors.

This box may be able to run Windows 3.1 - if it is a 386 model. Otherwise you can use Windows 2 v286 for the 286 models. I'm assuming it still has a hard drive sized between 16MB and 40MB.

You can mount DOS v6.22 (for 386 model) or v3.31 (for 286). Include a file navigator like PFM or DesqView and a decent text edittor like E88 or TED, and an old DOS version of WordStar or WordPerfect.I'm new at this also. Can anyone TELL me how view my computers history?

1852.

Solve : how do i erase h/d & reinstall xp??

Answer»

i want to get rid of the trojan ,and start over from scratch, but i dont know how i would run this first>http://vil.nai.com/vil/stinger/  but drastic to reload a sytem but here is the info>http://www.michaelstevenstech.com/cleanxpinstall.htmlJust boot the XP CD and format the DISK before you install, you'll get rid of anything on it.
If you have a floppy, search for all files on the system with file extension .WPA and copy them (preferably with their DIRECTORY paths) to the floppy disk. After you have re-formatted and re-loaded XP, copy those back where they CAME from and you may be able to dodge re-activation. Loading your virus killer and checking the floppy is also GOOD, enable your antivirus apps if possible before using the content of anything burned while you have an infection.

1853.

Solve : d:\>cd c:\program files\etc....can I do this??

Answer»

I am trying to go from:
d:\>
or
e:\>
or
z:\blah\blah>
(it doesn't matter which dir dos opens in)

to:
c:\program files\acad2000> dir /s/b *.dwg> filename.txt

all in ONE string.

Any advice would be usefull.




On your first line try
c:\program files\acad2000

you don't need the cd

this is what happened:

H:\>c:\program files\acad2000
'c:\program' is not recognized as an internal or EXTERNAL command,
operable program or batch FILE.

H:\>
may i ask what are you trying to do EXTRACT files run cd what...i'm not sure that you can, why don't you create a batch file called test.bat and put these command in
"
c:
cd programfiles/acad2000

"

running this batch file should put you in the right directory every time

1854.

Solve : windows does t setup?

Answer»

I have a 2000 IBM 600E Thinkpad. I got it from a friend and she tried to load Windows xp pro. Well she didn"t finish the setup and it will not load. I made a dos boot disk and tried to load basic windows 3.1 and the computer says that " Setup is unable to create the specified DIRECTORY on the specified drive" It says that I can CHOOSE a different path but I do not Know all that MUCH so I need some help.does it have a cdrom drive ....go in to  the bios f1 and CHANGE the boot sequence to boot from cdrom..what is the previous o/s on it...if it has none and this laptop with the right ram etc can handle winxp pro...its best to download a win98 disk format the hard drive and fdisk it ..

1855.

Solve : Imbedding a username and password in a bat file?

Answer»

I am executign a bat file that will zip contents to of a local folder to a remote server.  

The task doesn't complete, so I think I need to pass a username and password in the bat file that will grant ACCESS to the folder.  Does anyone know how to do this.

Below is the code for the bat file I am using.

c:
cd\
cd program files\winzip\
winzip32.exe -a \\142.123.45.67\Backup\3422.zip D:\Backup\3422
Del D:\Backup\3422
rem pause

Thanks

What happens when you manually type the commands?  That will guide you in figuring out what you need to put in the batch file.
Good thought.  When I manually type it it works fine.  What I am doing is calling this bat file in SQL SERVER.  I created a DTS package and the package runs the bat file.  When I execute the package it runs fine.  When I SCHEDULE the package, it uses a SQLSERVERAGENT account to run the package, that is when it fails, so I was thinking by IMBEDDING the CONNECTION and username and password intot he bat it might work, but thinking loudly about it now, I don't think so.  

I have to find another wayLook at AutoIt http://www.autoitscript.com/autoit3/, it's my SOLUTION to these kinds of issues.

1856.

Solve : Changing to Directories with long names - Win2K?

Answer»

Hi,
I need a batch file to change to a directory and execute a specific file from that directory.

The directory NAME contains spaces eg. all users.

I tried using cd "all users"  or cd all users but it fails.

Any idea how to make it work.

This should be working on windows 2000.

Regards
Arun.
Try using the complete path to the folder.Also use the DOS file name. For example, in windows you would SEE something LIKE c:\window\all users. In DOS it would be c:\windows\alluse~1.Using the LONG file name in quotes is the correct procedure.  I'm not sure why that doesn't work, because I have a BUNCH of batch files where it works fine.  Of course, if you're actually executing the command:

cd "all users"

... you do realize you have to be logged into the Documents and Settings folder, right?  How about trying:

cd "\Documents and Settings\All Users\"

... and see how it works.  That works on my 2K system.

1857.

Solve : Set dir contence as seperate strings?

Answer»

So for my robotics team I am making a program that will record match data on each team. I am RUNNING into a problem when I want to desplay all the teams scores at once. I am writing the scores in their own text file in c:\...\teams\%team number%\scr.txt and c:\...\teams\%team number%\ascr.txt. Currently I am using a loop to run through all the possable team numbers (1-5000) and using
Code: [Select]echo off
set /p color =<clr.txt
color %color%
title =View scores
cls
cd..
cd Teams
set teamnum=0
:loop
if not exist %teamnum% goto skip
cd %teamnum%
set /p ascr=< ascr.txt
set /p scr=< scr.txt
echo %teamnum%
echo.
echo Total        %scr%
echo Adverage %ascr%
echo ---------------------------------------------------
cd ..
:skip
set /a a=%teamnum%+1
set teamnum=%a%
if "%teamnum%" =="5001" goto end
goto loop
:end
echo.
echo.
pause
cls
cd ..
cd system
call home.bat

This takes somewhere between 5-10 minutes each time I run it, and I was wondering if there was a way that I could set the either use the %var:~#,#% or set %var#%=< dir (set each folder to a string) to SHORTEN the waiting time. Thank you so much!

EDIT: running on windows 7, but would like it to run on any windows OS.
also looking for a .bat -> .exe converter to get around this if it becomes a problem modifying it to work.
EDIT2: fixed the code (had wrong version up)It seems to me you need to sit down and really think about what needs to be done. Get the storage scheme right and worry about the code later. Do you really have 5000 teams? Or some smaller number? If you have more than a small number the scores are going to start scrolling off the screen, since showing each team's score uses 4 LINES of screen space. Why can't you have just one text file to hold all the data? Using separate folders like this is a very inefficient method, and is bound to be slow.

What does system\home.bat do?

Using your separate folders method can be speeded up a bit.

You seem to have one ascr.txt and one scr.txt in each team's folder, these files having one line which is a number?

See comments.

Code: [Select]echo off
REM is there really a Team zero?
set teamnum=0

set limit=5000

REM We will time how long it takes

set stime=%date% %time%

:loop

REM No need to keep going in and out of the folders
set foldername=Teams\%teamnum%
if not exist %foldername% goto skip

set /p ascr=< %foldername%\ascr.txt
set /p scr=<  %foldername%\scr.txt

REM I put it all on one line for neatness
echo Team %teamnum%: Total: %scr% Average: %ascr%

:skip

REM You don't need 2 variables here
REM set /a a=%teamnum%+1
REM set teamnum=%a%

REM You can do this
REM set /a teamnum=%teamnum%+1
REM or this
set /a teamnum+=1

REM Another way to compare numbers
REM See IF /? for these details
REM EQU - equal
REM NEQ - not equal
REM LSS - less than
REM LEQ - less than or equal
REM GTR - greater than
REM GEQ - greater than or equal

if %teamnum% GTR %limit% goto end

goto loop

:end

REM How long did we take?
set etime=%date% %time%
echo %limit% start %stime%
echo %limit% end   %etime%

I created 5000 (!) directories in a Teams folder and put an ascr.txt and a scr.txt containing random values in each one and then ran the above code and it took just over 35 seconds to read and display all the scores. Of course the earlier scores scrolled off the screen so I just copied the last 10 lines to show you.

You took 5 to 10 minutes?? What kind of machine?

Code: [Select]Team 4990: Total: 10  Average: 5
Team 4991: Total: 36  Average: 19
Team 4992: Total: 6  Average: 40
Team 4993: Total: 73  Average: 71
Team 4994: Total: 91  Average: 69
Team 4995: Total: 55  Average: 63
Team 4996: Total: 47  Average: 17
Team 4997: Total: 81  Average: 37
Team 4998: Total: 82  Average: 24
Team 4999: Total: 46  Average: 18
Team 5000: Total: 96  Average: 45
5000 start 04/03/2012 12:13:55.81
5000 end   04/03/2012 12:14:30.36

Quote from: Salmon Trout on March 04, 2012, 04:02:54 AM

It seems to me you need to sit down and really think about what needs to be done. Get the storage scheme right and worry about the code later. Do you really have 5000 teams? Or some smaller number? If you have more than a small number the scores are going to start scrolling off the screen, since showing each team's score uses 4 lines of screen space. Why can't you have just one text file to hold all the data? Using separate folders like this is a very inefficient method, and is bound to be slow.

What does system\home.bat do?

1) There are about 40 teams in each competition with numbers ranging from 0-5000.
2) home.bat is a menu page
3) Thank you for the one line recommendation.
4) I have to use 2 diffrent files for scr and ascr for the set /p VAR=< FILENAME command

Quote from: Salmon Trout on March 04, 2012, 05:24:32 AM
Using your separate folders method can be speeded up a bit.

You seem to have one ascr.txt and one scr.txt in each team's folder, these files having one line which is a number?

See comments.

Code: [Select]echo off
REM is there really a Team zero?
set teamnum=0

set limit=5000

REM We will time how long it takes

set stime=%date% %time%

:loop

REM No need to keep going in and out of the folders
set foldername=Teams\%teamnum%
if not exist %foldername% goto skip

set /p ascr=< %foldername%\ascr.txt
set /p scr=<  %foldername%\scr.txt

REM I put it all on one line for neatness
echo Team %teamnum%: Total: %scr% Average: %ascr%

:skip

REM You don't need 2 variables here
REM set /a a=%teamnum%+1
REM set teamnum=%a%

REM You can do this
REM set /a teamnum=%teamnum%+1
REM or this
set /a teamnum+=1

REM Another way to compare numbers
REM See IF /? for these details
REM EQU - equal
REM NEQ - not equal
REM LSS - less than
REM LEQ - less than or equal
REM GTR - greater than
REM GEQ - greater than or equal

if %teamnum% GTR %limit% goto end

goto loop

:end

REM How long did we take?
set etime=%date% %time%
echo %limit% start %stime%
echo %limit% end   %etime%

I created 5000 (!) directories in a Teams folder and put an ascr.txt and a scr.txt containing random values in each one and then ran the above code and it took just over 35 seconds to read and display all the scores. Of course the earlier scores scrolled off the screen so I just copied the last 10 lines to show you.

You took 5 to 10 minutes?? What kind of machine?

Code: [Select]Team 4990: Total: 10  Average: 5
Team 4991: Total: 36  Average: 19
Team 4992: Total: 6  Average: 40
Team 4993: Total: 73  Average: 71
Team 4994: Total: 91  Average: 69
Team 4995: Total: 55  Average: 63
Team 4996: Total: 47  Average: 17
Team 4997: Total: 81  Average: 37
Team 4998: Total: 82  Average: 24
Team 4999: Total: 46  Average: 18
Team 5000: Total: 96  Average: 45
5000 start 04/03/2012 12:13:55.81
5000 end   04/03/2012 12:14:30.36



Thanks for the respond, I like the set /a VAR+=1 that will HELP alot.
1) I like the one line suggestion a lot.
2) No there is not a team 0  thank you for point that out
3) I'm running it on my laptop (slow D:)


I did end up getting it to work last night. Thank you for your help! I'm ganna go through and check if Salmon Trout's runs faster, but here is what I did:
Code: [Select]echo off
set /p color=< clr.ghx
color %color%
Title =GHX - View
cls

start v1.exe
start v2.exe
start V3.exe
start v4.exe
start v5.exe

set a=0
set b=0
set c=0
set d=0
set e=0

cd ..
cd teams
cd %date:~10,4%
:wait
cls

if exist vc1.ghx set a=1
if exist vc2.ghx set b=1
if exist vc3.ghx set c=1
if exist vc4.ghx set d=1
if exist vc5.ghx set e=1
set /a ttl=%a%+%b%+%c%+%d%+%e%
if "%ttl%" =="0" echo 0%
if "%ttl%" =="1" echo 20%
if "%ttl%" =="2" echo 40%
if "%ttl%" =="3" echo 60%
if "%ttl%" =="4" echo 80%
if "%ttl%" =="5" echo 100%
if "%a%" =="1" if "%b%" =="1" if "%c%" =="1" if "%d%" =="1" if "%e%" =="1" goto show
REM the ping is to stop the flashing numbers
ping 127.0.0.1 >nul
goto wait

:show
cls
if exist v1.ghx type v1.ghx
if exist v2.ghx type v2.ghx
if exist v3.ghx type v3.ghx
if exist v4.ghx type v4.ghx
if exist v5.ghx type v5.ghx

if exist v1.ghx set v1=< v1.ghx
if exist v1.ghx set v2=< v2.ghx
if exist v1.ghx set v3=< v3.ghx
if exist v1.ghx set v4=< v4.ghx
if exist v1.ghx set v5=< v5.ghx
set vcom=%v1%%v2%%v3%%v4%%v5%
if "%vcom%" =="" echo No teams indexed



echo.
if exist v1.ghx del v1.ghx
if exist v2.ghx del v2.ghx
if exist v3.ghx del v3.ghx
if exist v4.ghx del v4.ghx
if exist v5.ghx del v5.ghx

if exist vc1.ghx del vc1.ghx
if exist vc2.ghx del vc2.ghx
if exist vc3.ghx del vc3.ghx
if exist vc4.ghx del vc4.ghx
if exist vc5.ghx del vc5.ghx
set /p nouse=Press Enter
cd ..
cd ..
cd system
call home.bat I used a bat->exe compiler to make it run without opening a window (that's why i used a exe)
here is v1.exe
Code: [Select]
echo off
cd ..
cd teams
cd %date:~10,4%
set a=1
:loop
if not exist %a% goto loop.break
cd %a%
set /p scr=< scr.ghx
set /p ascr=< scr.ghx
cd ..
echo %a% >>v1.ghx
echo. >>v1.ghx
echo Total %scr%>>v1
echo Average %ascr% >>v1
:loop.break
set /a b=%a%+1
set a=%b%
if "%a%" =="1001" goto exit
goto loop
:exit
echo 1 >>vc1.ghx
exit
here is v2.exe
Code: [Select]
echo off
cd ..
cd teams
cd %date:~10,4%
set a=1001
:loop
if not exist %a% goto loop.break
cd %a%
set /p scr=< scr.ghx
set /p ascr=< scr.ghx
cd ..
echo %a% >>v2.ghx
echo. >>v2.ghx
echo Total %scr%>>v2.ghx
echo Average %ascr% >>v2.ghx
:loop.break
set /a b=%a%+1
set a=%b%
if "%a%" =="2001" goto exit
goto loop
:exit
echo 1 >>vc2.ghx
exit
the rest (v3-v5.exe) follow the pattern until teams 0-5000 are covered

Any comments\suggestions?

BTW: can you open a 'SFX module' exe file without winRAR?

Thanks again for the help!

EDIT: ran Salmon Trout's code, and I think it's a problem with my computer because it took 4 min 
Code: [Select]5000 start Sun 03/04/2012 13:41:29.76
5000 end  Sun 03/04/2012 13:44:41.86
delete?
1858.

Solve : network bat question?

Answer»

I've been writing a bat FILE that maps a network drive after I log into a VPN network.  However, I've RUN into a snag and can't figure it out.  I execute the file, but it then asks me for my credentials, which I type in.  No luck.  However, when I use the windows shortcut WINDOWS-R, then type in the path to the prompt, it works.  The question why won't it work in DOS, but work in Windows?Please post the code you are using and if possible give us the errors that are coming up. The more information you give us, the better we can tailor the help to your specific problem.net use V: /delete
net use V: "\\server\folder\folder\folder"

%SystemRoot%\explorer.exe "\\server\folder\folder\folder"

it asks me for my ID and password, which I put in:

server\username
password

then it tries again, and eventually tells me I don't exist.First, are you CERTAIN that you have permissions to the folder you are mapping. One way to see what is happening is to make sure echo is on (echo on at the beginning of the batch) and then put > %userprofile%\desktop\log.txt at the end of each line then your desktop should get the log file that has everything that happens until you run into the problem.

You can also open a cmd prompt and type in the commands one by one until you find which one sparks the problem. You should see a "The command completed successfully" or "The network connection could not be found" for the first command. The second one will either give you ANOTHER, "The command completed successfully" or "The password is invalid for \\server\folder\folder\folder.

Enter the username for 'server': "
If the second one is popping up, then it means you don't have permissions to that folder. If you do in fact have permissions, then it may be due to the cmd prompt not recognizing the VPN connection. You can try to map the drive to a folder up or down a level and see if you have better luck. If you aren't able to access it at all, then it is the connection, or the cmd prompt not recognizing the connection. I'm not sure how to fix that, honestly. Your commands look fine otherwise.

1859.

Solve : Batch file to convert unicode text file to ANSI text file?

Answer»

I want a batch CODE that would convert my list of text files already SAVED as unicode to ANSI Type.

Any help on this is much appreciated.

Also, I thought a way could be to open the unicode text file and write it to an Ansi text file type, howere not sure if this is the right well because I do have
 a list of text files, i want to convert to Ansi text file type.

See the code below, it isn't giving me my result though....


echo off

$file = FileOpen("C:\Examplle.text", 0)  ; Open for Reading
$file1 = FileOpen("C:\Example.text", 1) ; Open for Writing


If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf


If $file1 = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

 
While 1
    $chars = FileRead($file, 2)
    If error = -1 Then ExitLoop
        If ($chars) <> "ÿþ" then
            FileWrite ($file1 , StringLeft ($chars , 1))
 
EndIf

Wend

FileClose($file)
FileClose($file1)


Many Thanks
http://www.robvanderwoude.com/type.php#Unicode
http://www.dostips.com/DtCodeSnippets.php#Snippets.UnicodeToAnsiAnd here is a nice little function you can call WITHIN your batch file if you are using a for loop to get a list of your text files you need to convert.
http://www.dostips.com/DtCodeCmdLib.php#Function.ToANSI Quote from: Mat51 on January 08, 2012, 02:35:27 PM


See the code below, it isn't giving me my result though....


I'm not SURPRISED. That isn't Windows batch/cmd code - it looks like some language you invented.




Quote from: Salmon Trout on January 08, 2012, 03:34:13 PM
I'm not surprised. That isn't Windows batch/cmd code - it looks like some language you invented.

I think it's some kind of BASIC; I'm not sure which, though.
1860.

Solve : Fixed width?

Answer»

The place I'm starting from is the first stepping stone to a more complex batch file.  What I want to have the batch file do at the moment is count from one input number to the second input number by 1.  I have it working to get the two numbers and can get it to count up.  the issue I run into is trying to zero pad the front of my numbers.  This is what I have right now.
Code: [Select]echo off
Title TG test
echo %DATE% %TIME%
for /l %%a in (%1,1,%2) do (
if /i %%a LSS 10 ( echo 00%%a)
if /i %%a LSS 100 ( echo 0%%a)
if /i %%a LSS 1000 ( echo %%a)
)

What I get when I run this as test.bat 1 10 is
001
01
1
002
02
2
so on and so forth.  What I would like is
001
002
003
....
010

Any help would be great.Not too difficult, you just want to use ELSE with your if testing. So:
Code: [Select]echo off
Title TG test
echo %DATE% %TIME%
for /l %%a in (%1,1,%2) do (
  if /i %%a LSS 10 (echo 00%%a) else (
    if /i %%a LSS 100 (echo 0%%a) else (
      if /i %%a LSS 1000 (echo %%a)
    )
  )
)I've tried that.  This is the output I get using that.
001 else (
01 else (
1
002 else (
02 else (
2
003 else (
03 else (
3
004 else (
04 else (
4
005 else (
05 else (
5
006 else (
06 else (
6
007 else (
07 else (
7
008 else (
08 else (
8
009 else (
09 else (
9
010 else (
10

I don't know how to get rid of the echo on the else.Check the revision. I removed the parenthesis when I shouldn't have. My bad.Got it with
Code: [Select]for /l %%a in (%1,1,%2) do (
  if /i %%a LSS 10 (echo 00%%a) else (
    if /i %%a LSS 100 (echo 0%%a) else (
      if /i %%a LSS 1000 (echo %%a)
    )
  )
)
Thank you so much.  Pad the number with a larger number of pad characters than you will need (can be any character, not just zero). Then select the rightmost N-1 characters using the syntax

%string:~-N%

The number is 1 more than the desired number width. Here we show 3 digits. Since we are in a loop we use delayed expansion and !var! instead of %var%

Code: [Select]echo off
setlocal enabledelayedexpansion
for /l %%a in (%1,1,%2) do (
  set num=00000000000000000000%%a
  echo !num:~-4!
)I'm gonna stay with the way Raven suggested since I'm using it on a large scale batch file.  The echo was just to get the initial number counter working.  I'm using a few xcopy, cd, and another program CALLS with the number in the loop.
Thanks anyways. Quote from: Salmon Trout on December 29, 2011, 02:16:00 PM

Pad the number with a larger number of pad characters than you will need (can be any character, not just zero). Then select the rightmost N-1 characters using the syntax

%string:~-N%

The number is 1 more than the desired number width. Here we show 3 digits. Since we are in a loop we use delayed expansion and !var! instead of %var%

Code: [Select]echo off
setlocal enabledelayedexpansion
for /l %%a in (%1,1,%2) do (
  set num=00000000000000000000%%a
  echo !num:~-4!
)
Your code should run much QUICKER.  And as I always say time is money.

But I wasn't sure if the O/P wanted numbers greater than 99 to be padded with a zero.
Too me it looks like they wanted
001
010
100
1000Lemming, I understood about why you used echo. I use the method I showed above in a variety of DIFFERENT batch scripts, including bulk renaming of files and it is just as effective as any other method.

It is more efficient, unless you are specifically doing the tests for other reasons and there is other processing involved with each test.

If not, and if you were wanting to set a variable for instance, you would just change it to

Code: [Select]echo off
setlocal enabledelayedexpansion
for /l %%a in (%1,1,%2) do (
  set num=00000000000000000000%%a
  set var=!num:~-4!
)
But this is more about efficient programming than anything, and showing you another way to accomplish the task you initially wanted done. If your personal preference is to use my originally posted method, then by all means feel free to use it. This is what I'm doing and it makes it a little easier to do the brute force way vs variable.  It is easier since I am very new to batch file writing.  I have also expanded the batch file to take in two numbers when being called

Code: [Select]TG_batch.bat 1 2

Code: [Select]echo off
Title TG batch
for /l %%A in (%1, 1, %2) do (
    if /i %%A LLS 10 (
        xcopy t:\!template t:\run\00%%A
        copy t:\!def\00%%A.atmo t:\00%%A\part1\00%%A.atmo
        run other program 1
        copy output.testcase ..\part2\input.dat
        run other program 2
    ) else (
    if......
    if......
)
This is for the most part what I am doing with the help initially from Raven.  The file structure is only set to run no more than 100 iterations so getting to 1000 was never a concern.
Since I am new I don't know how to correctly IMPLEMENT the smaller set of batch code with what I need it to do.
I am extactic to see the number of responses to this.  It is just that at the time I don't know how to correctly use the new supplied way.
Thank you all for your help.another way if you want to see the powers of 10

Code: [Select]echo off
setlocal enabledelayedexpansion
REM pad with spaces
set "padchar= "
REM pad with zeroes
set padchar=0
for /l %%a in (%1,1,%2) do (
set pad=& for %%b in (10000 1000 100 10) do if %%a lss %%b set pad=%padchar%!pad!
echo !pad!%%a
)
Quote from: lemming622 on December 29, 2011, 05:28:14 PM
This is what I'm doing and it makes it a little easier to do the brute force way vs variable.  It is easier since I am very new to batch file writing.  I have also expanded the batch file to take in two numbers when being called

Code: [Select]TG_batch.bat 1 2

Code: [Select]echo off
Title TG batch
for /l %%A in (%1, 1, %2) do (
    if /i %%A LLS 10 (
        xcopy t:\!template t:\run\00%%A
        copy t:\!def\00%%A.atmo t:\00%%A\part1\00%%A.atmo
        run other program 1
        copy output.testcase ..\part2\input.dat
        run other program 2
    ) else (
    if......
    if......
)
This is for the most part what I am doing with the help initially from Raven.  The file structure is only set to run no more than 100 iterations so getting to 1000 was never a concern.
Since I am new I don't know how to correctly implement the smaller set of batch code with what I need it to do.
I am extactic to see the number of responses to this.  It is just that at the time I don't know how to correctly use the new supplied way.
Thank you all for your help.
If you do it that way you have to replicate all your commands inside each IF ELSE.  Use the IF ELSE to SET a variable with the padded number then do all your commands.
1861.

Solve : How do you write a blank line to a file??

Answer»

I want to ADD blank lines to a file, but not sure how.

So like:

ECHO DERP >test.txt
echo >>test.txt
echo HERP >>test.txt

Would Make:

Derp
Echo is off
HerpIts not obvious, but do this
Code: [Select]echo Derp >test.txt
echo. >>test.txt
echo Herp >>test.txt
the '.' doesnt print, so just the newline is sent
Several CHARACTERS you can use to generate the blank line.
Code: [Select]ECHO SQUASH
ECHO;
ECHO:
ECHO,
ECHO.
ECHO=
ECHO+
ECHO[
ECHO]
ECHO/
ECHO\
ECHO MAN Code: [Select]E:\batch files\blank>blank.bat
SQUASH










MAN

E:\batch files\blank>

1862.

Solve : Need to move files and folders up one level.?

Answer»

Hi.
I need to move all folders, except one, up a level as outlined below.
Code: [Select]1
U:\_M_E_D_I_A_S_\t_e_s_t\incoming\New folder
U:\_M_E_D_I_A_S_\t_e_s_t\incoming\New folder (2)
U:\_M_E_D_I_A_S_\t_e_s_t\incoming\New folder (3)
U:\_M_E_D_I_A_S_\t_e_s_t\incoming\New folder (4)
U:\_M_E_D_I_A_S_\t_e_s_t\incoming\New folder (5)
U:\_M_E_D_I_A_S_\t_e_s_t\incoming\New folder (6)

2
U:\_M_E_D_I_A_S_\t_e_s_t\incoming
U:\_M_E_D_I_A_S_\t_e_s_t\New folder
U:\_M_E_D_I_A_S_\t_e_s_t\New folder (2)
U:\_M_E_D_I_A_S_\t_e_s_t\New folder (3)
U:\_M_E_D_I_A_S_\t_e_s_t\New folder (4)
U:\_M_E_D_I_A_S_\t_e_s_t\New folder (5)
U:\_M_E_D_I_A_S_\t_e_s_t\New folder (6)
If any one can start me of with a batch that's a bit more elaborate than...
Code: [Select]echo off
move U:\_M_E_D_I_A_S_\t_e_s_t\incoming\* U:\_M_E_D_I_A_S_\t_e_s_t\*
I would be eternally grateful. Please clarify: you want to create a new (EMPTY?) folder \incoming (or is it already created?) and then:

move the contents of \New Folder into \incoming
move the contents of \New Folder (2) into \New Folder

[...]

move the contents of \New Folder (6) into \New Folder (5) LEAVING \New Folder (6) empty

Is that correct?

Sorry for not making it clear,
I have edited a bit in OP to help, 1, is how it is now and 2, is how i would like it to be be; so move all folders out of "incoming" BACK up into "t_e_s_t" and have them not exist in incoming, but incoming has to remain... Hope you can see my screen captures...

This is before?



And this is after?




The before is correct as is the after, the only difference would be that the folders that are New Folder etc. could be called anything...At the command prompt:

Code: [Select]cd /d "U:\_M_E_D_I_A_S_\t_e_s_t\incoming" & for /f "delims=" %F in ('dir /b /ad') do move "%F" "U:\_M_E_D_I_A_S_\t_e_s_t"
In a batch script:

Code: [Select]cd /d "U:\_M_E_D_I_A_S_\t_e_s_t\incoming" & for /f "delims=" %%F in ('dir /b /ad') do move "%%F" "U:\_M_E_D_I_A_S_\t_e_s_t"Thanks that did the trick.More general batch file; you could save it on your path somewhere; or else save it in a folder and open a command window there.

Suppose you called it movefolders.bat, syntax would be (example):

movefolders "U:\_M_E_D_I_A_S_\t_e_s_t\incoming" "U:\_M_E_D_I_A_S_\t_e_s_t"

remember to provide full folder paths and use quote marks.

Code: [Select]echo off
set fromfolder=%1
set   tofolder=%2
if "%~1"=="" Echo Error! No folders specified & GOTO end
if "%~2"=="" Echo Error! Destination folder not supplied & goto end
If not exist %1 Echo Error! source folder %1 not found & goto end
If not exist %2 Echo Error! Destination folder %2 not found & goto end
Echo Move folders
echo From: %1
echo To:   %2
cd /d %fromfolder%
for /f "delims=" %%F in ('dir /b /ad') do (
echo Moving folder: %%~dpnF
move "%%F" %tofolder%
)
:end
pause

1863.

Solve : batch file for reading and coping strings within lines?

Answer»

Hi All,

I'm quite new to this, I want to achieve the following within my script,

1.read through each txt file in that folder
 2.loop through each txt file to find the string names in my dolist txt file
 3.if the txt file contains the string such as Daily Cost : 768 004, then print anything minus the Daily Cost
4.if the txt file contains the string such as Hello then printthe string in the next line
 5.the pint text should go to result txt. file

I tried this code;

echo off
if exist result.txt del result.txt
::for %%f in ('C:\Reservoir Management\script\*.txt')

do ( echo String match for %%f: >> result.txt
for /F "delims=" %%s in (dolist.txt)
do ( findstr "%%s" %%f >> result.txt ) )

but I' m getting an error, not even got passed the open folder, error Findstr cannot find %f, when runing the script.


Need your help please,

Thanks,
MatildaI think this is what you are trying to do but I am not sure.

Code: [Select]for %%f in ("C:\Reservoir Management\script\*.txt") do findstr /G:dolist.txt "%%f" >>result.txtHi  All,

here is my edited code
ECHO OFF
SET dolist=c:\miles\dolist.txt
SET searchFolder=C:\Reservoir Management\script\*.txt
SET resultFile=c:\miles\results.txt

DEL %resultFile%
ECHO .
ECHO Searching files, please wait...
FOR /F  %%i IN (%dolist%) DO CALL :FindMyString %%i
ECHO Search completed, see file %resultFile%

GOTO :EOF


:FindMyString
ECHO Search Results For "%1" >> %resultFile%
FINDSTR  %1 "%searchFolder%" >> %resultFile%
ECHO . >> %resultFile%
GOTO :EOF

however, my dolist  search is not returning the whole string like "Well name" the code is currently returning well and not name

really, what I want is within my dolist

if the well name exist within my search folder, then get or print any string minus the well name
if a mud type exist within my search folder then get or print the words in the next line.

Thank you

Here is what I think you should do.
POST a copy of you DoList file here and post an example of some of the text files you want to search and then shows us what you expect to be your end result.Thank you,

here is my dolist;
Well Name :
Midnight depth
Mud Type
Density
Cumulative Cost:
Daily Summary :


Here is my search text;
Daily Drilling Report
Well Name: ACA-804
Daily progress
Drilling Hours
Midnight depth
25/09/2011
Date Type
16/09/2010 BOP's Pressure test
Cumulative Cost:  768 098 900
19/09/2010 Gas Drill
19/09/2010 Ser.Co.Safety Mtg
25/09/2011 Sce Company meeting
Daily Summary :
Sailing to ACA-804 new location. Beacons calibration. Move to SHZ. Pressure
test KL, CL, Booster & Hyd Lines. RIW BOP f/ 911m to 954 m.
WellBore
Mud
Mud Type
Sea water
Density (...
1.030I also asked what you expected your output to be.Thank you

search result  should be in the result txt.

for  1.Well name, it should return text line minus the well name, hence it should return ACA-804 as seen in the search text
     2 Cumulative Cost, it should return text line minus the well name, hence it should return 768 098 900 as seen in the search text                                                                                                
     2.Mud Type it should return  stirng in the next line after Mud Type hence it will be sea Water.
     3. Density it should return string in the next line hence it will be 1,030
     5. Daily Summary  it should return  strings in the next 2lines.....

 there are multiple text files within the sub directory, so search will be done on all the text files.

Below is my current result.txt but like I said before my  return search string isn't complete

      Search Results For "Well"
C:\Reservoir Management\script\D.txt
C:\Reservoir Management\script\DD.txt
C:\Reservoir Management\script\DDD.txt
.
Search Results For "Midnight"
C:\Reservoir Management\script\D.txt
C:\Reservoir Management\script\DD.txt
C:\Reservoir Management\script\DDD.txt
.
Search Results For "Mud"
C:\Reservoir Management\script\D.txt
C:\Reservoir Management\script\DD.txt
C:\Reservoir Management\script\DDD.txt
.
Search Results For "Cumulative"
.
Search Results For "Daily"
C:\Reservoir Management\script\D.txt
C:\Reservoir Management\script\DD.txt
C:\Reservoir Management\script\DDD.txt
.Now you are confusing the heck out of me.  I thought you wanted the contents of the text files from your search to be output, not the file names.  I think I am going to TAP OUT on this one.  Hopefully someone ELSE will come along and be able to help you because I am not really understanding what you want.
Hello,

yes you are right, I want the contents of my search as an output.

Many Thanks,

MatildaUnfortunately, you have a fairly tall order you are trying to fill here. Your input does not neatly conform to your desired output, and the added hurdle of seperate lines makes things quite difficult. For one thing, you are definitely going to have a large amount of processing in the embedded FOR loop, including a lot of switches to turn on oand off so that you can accurately capture what you are wanting to capture. I'll see if I can put together something for you here:

Code: [Select]echo off
setlocal enabledelayedexpansion

for /f "delims=" %%A in ("c:\Reservoir Management\script\*.txt") do (
  set file=%%~dpnxA
  echo Daily Summary: >> sum.scrtmp
  REM set midnidep=0
  set mud=0
  set den=0
  set sum=0
  for /f "usebackq tokens=1* delims=:(" %%B in ("!file!") do (
    if /i "%%B"=="Well Name" (echo Well Name: %%C >> Wellname.scrtmp)
    if /i "%%B"=="Cumulative Cost" (echo Cumulative Cost: %%C >> CumulCost.scrtmp)
    if !mud! equ 1 (
      echo Mud Type: %%B >> mud.scrtmp
      set mud=0
    )
    if /i "%%B"=="Mud Type" (set /a mud=1)
    if !den! equ 1 (
      echo Density: %%B >> den.scrtmp
      set den=0
    )
    if /i "%%B"=="Density " (set /a den=1)
    if !sum! geq 1 (
      echo %%B >> sum.scrtmp
      set /a sum-=1
    )
    if /i "%%B"=="Daily Summary " (set /a sum=2)
    REM if !midnidep! equ 1 (
    REM   echo Midnight Depth: %%B >> midnidep.scrtmp
    REM   set midnidep=0
    REM )
    REM if /i "%%B"=="Midnight Depth" (set /a midnidep=1)
  )
  type Wellname.scrtmp >> temp.scrtmp
  REM type midnidep.scrtmp >> temp.scrtmp
  type mud.scrtmp >> temp.scrtmp
  type den.scrtmp >> temp.scrtmp
  type CumulCost.scrtmp >> temp.scrtmp
  type sum.scrtmp >> temp.scrtmp
  echo. >> temp.scrtmp
  type temp.scrtmp >> "c:\Reservoir Management\script\result.txt"
  del *.scrtmp
)

You will need to DELETE all of the "REM"s that you find in there if you are wanting the Midnight Depth in the result as well. Otherwise just delete the lines. The embedded code is setup like it is so that the processing happens like it should. Please let us know if you run into any issues. BTW, I tested this on the input that you gave and the result was this:


Well Name:  ACA-804
Midnight Depth: 25/09/2011
Mud Type: Sea water
Density: 1.030
Cumulative Cost:   768 098 900
Daily Summary:
Sailing to ACA-804 new location. Beacons calibration. Move to SHZ. Pressure
test KL, CL, Booster & Hyd Lines. RIW BOP f/ 911m to 954 m. Thanks Raven,

you are a life saver, it does work and I would like few more twiggs to it.

The code currently works for  the first text file in my directory, if you could get it to work for all the text files in that directory

see below search text;
Midnight depth
04/06/2011
04
1 302,10
DEV 1
1 924,00
Survey Data

The result is currently like
Well Name:  DAL753-4P
Midnight Depth: 03/06/2011
Mud Type: Spud mud
Density: 1,030
Daily Summary:
RIW 36" CP + DAT + PGB + BHA assy - Move ship, from SHZ to well center - Tag
sea
 I would like slight modification to the Mid night depth;
the next line string below the Midnight Depth: is actaually the date;
the Midnight Depth:should have the string above the survey data,
so in the result it should be

Well Name:  DAL753-4P
Date: 03/06/2011
Mud Type: Spud mud
Density: 1,030
Midnight Depth:1 924,00
Daily Summary:
RIW 36" CP + DAT + PGB + BHA assy - Move ship, from SHZ to well center - Tag
sea bed 1320 m/RT - Jet 36" CP to 1385 m/RT - Observe Soaking period -
Thank youQuick question for you, and an explanation to help you understand why. The question is "is the text following the midnight depth line standard or does it vary?" I.e. Is there a set number of lines that follow the midnight depth line before you actually get the true "midnight depth" figure you are LOOKING for? The reason I ask is because the program reads the text line by line. While it may seem simple to me and you to say, "the line above the survey data," the program no longer sees that line as existing at all. So I have to find something standard in a line above the midnight depth to look for instead of below it.Actually, I took some time, had a drink, and everything came to me (alcohol isn't always a bad thing!!!) In order to get your "last line" to work, all we have to do is have a lastline variable and set it appropriately. This will only work though if the midnight depth value ALWAYS resides in the line above the survey data. See minor changes below:

Code: [Select]echo off
setlocal enabledelayedexpansion

for /f "delims=" %%A in ("c:\Reservoir Management\script\*.txt") do (
  set file=%%~dpnxA
  echo Daily Summary: >> sum.scrtmp
  set mud=0
  set den=0
  set sum=0
  for /f "usebackq tokens=1* delims=:(" %%B in ("!file!") do (
    if /i "%%B"=="Well Name" (echo Well Name: %%C >> Wellname.scrtmp)
    if /i "%%B"=="Cumulative Cost" (echo Cumulative Cost: %%C >> CumulCost.scrtmp)
    if !mud! equ 1 (
      echo Mud Type: %%B >> mud.scrtmp
      set mud=0
    )
    if /i "%%B"=="Mud Type" (set /a mud=1)
    if !den! equ 1 (
      echo Density: %%B >> den.scrtmp
      set den=0
    )
    if /i "%%B"=="Density " (set /a den=1)
    if !sum! geq 1 (
      echo %%B >> sum.scrtmp
      set /a sum-=1
    )
    if /i "%%B"=="Daily Summary " (set /a sum=2)
    if /i "%%B"=="Survey Data" (echo Midnight Depth: !lastline! >> midnidep.scrtmp)
    set lastline=%%B
  )
  type Wellname.scrtmp >> temp.scrtmp
  type midnidep.scrtmp >> temp.scrtmp
  type mud.scrtmp >> temp.scrtmp
  type den.scrtmp >> temp.scrtmp
  type CumulCost.scrtmp >> temp.scrtmp
  type sum.scrtmp >> temp.scrtmp
  echo. >> temp.scrtmp
  type temp.scrtmp >> "c:\Reservoir Management\script\result.txt"
  del *.scrtmp
)
Thank you Raven,

Results are exactly what I want. except now the Cumulative Cost isn't working now. Also, I want the code to read all the text files in the directory ("c:\Reservoir Management\script\*.txt"). At the moment, its just the first text.

Thanks for your help and time , guess Santa payed the visit after all... Hi Raven,

the reason why cumulative cost is not picked is because within the text there are spaces;
 Cumulative Cost : 2 581 456; it does work if spaces were removed such as Cumulative Cost: 2 581 456


Matilda

1864.

Solve : create a file inside number of folders.?

Answer»

Hello every one 

I have a question , i tried to create a FILE with name test.mk in side number of folders.
And i m not successful in that can any one helps me in that , i use batch programing for that.

example :
name of the file want to create : test.mk

Locations :
c:\first
c:\second
c:\third
c:\four

I need to create a file with same name in 116 location that's y i want a script to create it.

Thanks for any help .Seeing how your directories are top level folders on the C: drive, and don't seem to follow any specific naming convention, I WOULD run a dir list on the c: drive, cut and paste the 116 directory names into notepad and then do some fancy search and replace operations.

What is test.mk? Does it contain data to be copied into each directory, or is this just dummy label?

More info is probably needed test.mk is a name of the dummy(blank) file which i need to be created inside the folders .

by the way the problem is solved , i use Perl script to solve it.

following 2 scripts works:
Quote

Script 1(we run this script and it calls second script)
Code: [Select]FILES= ("c:\first",
"c:\second",
"c:\third"'
"c:\four");
for $file(files)
{
    system("C:/Perl/bin/perl C:/script_two.pl $file");
}
Quote
script_two(it creates a blank file inside folders)
Code: [Select]use Fcntl; #The Module
use File::Find;
if($#ARGV != 0)
{
print "\nUsage: perl $0 <Root Directory>\n";
}
else
{
$dir = ARGV[0]; #The root directory given by the user
find(\&edits, $dir);
print "Success\n";
}
sub edits()
{
sysopen (FH, 'local.mk', O_CREAT, 0755);
close (FH);
}name each folder 1, 2, 3... and so on
use this code and replace ^name^ with the name of the file your TRYING to make

Code: [Select]echo off
set dirnum=0
:loop
if dirnum=116 echo done&pause&exit
set /a dirnum=%dirnum%+1
echo.>C:\%dirnum%\^name^
goto loop
1865.

Solve : How do I log the output from a .bat job.?

Answer»

Hi,
I'm planning writing a batch job to run every morning at 6:00 AM. I will be required to get the output from the job WRITTEN to a log file.

Any ideas on how to do this?

ThanksThere are 2 ways,
1] rewrite your batch to add '>>logfile' after every command - remembering to blank it at the start
2] run it as a parameter to command.com and redirect the output of command.com to your log :
command /c mybatch.bat > logfile

Good luck
GrahamHi Graham,
Thanks for the tips.

I'm not a DOS expert, so this question may sound a little basic to you.

1) How can I add the date and time to the log file name and

2) How can I direct the log file into a DIRECTORY (folder) so that I can keep a collection of their daily activities?

Thanks,
Les
Code: [Select]if not exist %date% (
md %folder%
)
SET folder=%date%
>>%folder%\%time%.txt

This sets the folder do the date, and then inside that folder it creates %time%.txtJacob
depending on your settings, %date% could contain / characters
I would amend your code a bit like this

Code: [Select]:: remove slashes
set folder=%date:/=_%
if not exist %folder% (
md %folder%
)
>>%folder%\%time%.txt
Baffled - you might like to play around with string slicing to put the date into 'military' format (yyymmdd) so that the folders list nicely alphabetically .... this will depend on your locale, in the uk, you would do
Code: [Select]:: reformat date
set folder=%date:~6,4%%date:~3,2%%date:~0,2%for US format, swap the 3,2 | 0,2
GrahamHi,
thanks for all your help.

I'm having difficulty with the writing to the file within a folder bit.

The code

md %folder%

works ok.

When I try to do the command

>>%folder%\%time%.txt

it fails to write ANYTHING. So I tried

>>fred2\fred.txt

and this worked. So I tried: -

>>%folder%\fred.txt

this failed to write anything.

Any ideas as to what I'm doing wrong?

ThanksDo the folder or file name have any spaces?

Try USING quote marks like this

>>"%folder%\%time%.txt"Hi,
Thanks again. That worked.

Can you tell me how to display comments including the date and time in the output log file which I'm creating?

Thanks Code: [Select]echo This is a comment >> logfile.txt
echo The date today is %date% >> logfile.txt
echo The time now is %time% >> logfile.txt
Thanks,
You're all geniuses.

It mow works perfectly.


Cheers...  There may be a problem caused if you echo output successively to a file called %time%.txt. This is because the system variable %time% contains the system time at the time the variable is read by the batch file. Obviously, as everybody knows, time does not stand still. So %time% changes.

Quote

C:\>echo %time%
10:14:45.42

As you can see, the time is expressed in hours, minutes, seconds and hundredths of a second

Consider the following

Code: [Select]echo off
echo Starting process >> %time%.txt
Process.exe
echo Finished process >> %time%.txt
Unless the process starts and finishes in less than 0.01 second, the two echo statements are going to output to 2 files with different names.


call your batch file mybatch.bat

Code: [Select]echo off
IF %1==logged goto :code
echo. >>logfile.log
echo %DATE% >>logfile.log
echo //START OUTPUT >>logfile.log
call %comspec% /c mybatch.bat logged >>logfile.log
echo //END OUTPUT >>logfile.log
exit
:code
[your code goes here]
try that
1866.

Solve : Creating a bootable CD with several boot options?

Answer»

I'm trying to create a bootable CD that BOOTS to a MENU. From that menu I would like to be able to BOOT from a choice of options. Is this possible?

ThanksMagicISO claims to be able to do this - SEE here also others here

Good luckI will check out the links, they look hopefull

thanks

1867.

Solve : Was wondering...?

Answer»

I was just wondering if there is any way a .bat file could kick a certain IP address that's connected to your wireless router off of it. If there is a way could some one post the code I would extremely appreciate it.Hi,

What are your trying to achieve???

Do you want to ban an IP address from your home router??? - this would be easier to ban it via the router's web GUI.

Or,

Do you want to open a batch file, input a IP address and then have the batch file remove that IP from your network. ie, not allow it any access at all. - I'm not sure if this is possible via batch.

If you've got a router you'd have to find a way to import commands to it (not sure if that possible not knowing the type of router you have), if this is a work based question and you've got a domain with Active Directory it can be archived, but with a VBScript.


Let use know what camp your in.

 

You didn't mention an OS, however if you have access to the netsh command try:

Code: [Select]netsh int ip delete xxx.xxx.x.x

Replace the x's with the IP address in question.

Good luck. Thanks for the HELP. And to answer any asked questions, I'm running on Windows XP Service Pack 2 Home Edition, what I'm trying to achieve is removing my neighbors from my router and hogging all of my bandwidth. SideWinder, Thanks for the line of code but sadly it did not work, it says "The following command was not found: int ip delete XXX.XXX.X.X".(I did replaced the X's with the IP)I may have been a bit hasty with netsh command. It can be helpful but maybe not in these circumstances.

Quote

what I'm trying to achieve is removing my neighbors from my router and hogging all of my bandwidth.

Can you not put some security on your network? WPA or WPA2 recommended but even WEP is BETTER than none at all.

Note: In many PLACES your neighbor can be charged with theft of services which is a felony. In the US, I'm sure it's against some provision or other of the Homeland Security Act.

Good luck.

I've tried time and time again to set up the wireless security but every time for some reason it messes up and ends up locking its self down and then I have to reset it.do you require the wireless features, or are you connecting to an available port on the router? If so you could simply disable the wireless portion of the router.The router is down stairs and I'm upstairs in my loft so that wouldn't work, if there was any working cable plug ins in my loft I would use those INSTEAD of wireless. Thanks for the suggestion though.Do you know which neighbors are stealing your connection? if so you could try to "block" your router from their wireless CARDS, with metal or something- It might not get rid of them entirely, but their signal will be drastically reduced.you could use MAC address filtering and then only the machines you've added will be able to connect to the router.

(it's what I use)

tbh, you do need some sort of sercurity other wise your open all sorts of nasty things!!!!

1868.

Solve : make a instalation log?

Answer»

i need to make a installation log file on my local computer i was hopeing to do it in batch  script. i am running windows xp pro. i am the ADMIN. if anyone knows of ANOTHER way of doing this plz let me know.

by installation log i mean when some one installs something that it will make a log of the user and what they installed and when.


thanks for the help.What do you mean by Installation Log file? Quote from: Carbon Dudeoxide on November 21, 2008, 10:17:36 PM

What do you mean by Installation Log file?

Quote
by installation log i mean when some one installs something that it will make a log of the user and what they installed and when.
Quote from: Jacob on November 22, 2008, 06:51:15 AM
Quote from: Carbon Dudeoxide on November 21, 2008, 10:17:36 PM
What do you mean by Installation Log file?

Quote
by installation log i mean when some one installs something that it will make a log of the user and what they installed and when.

Quote
« Last Edit: Today at 07:55:24 PM by chris hill »
Jacob, you are very knowledgeable in this area.....Not POSSIBLE, right?i think it can be done using registry but you must search there for keys
 if i will find somethink ill POST it here
1869.

Solve : How can i check the return result of "reg query" command??

Answer»

I can list all subkeys and values of an appointed registry key with "reg query" command?. for example: reg query hklm\SOFTWARE\CryptionDirectory /s

now, i want to CHECK the return result of "reg query" command, if some subkeys exist, execute "test1.exe", if no subkeys exist, execute "test2.exe".

how to write the batch file??

thanks.Hi,

You might be able to create a for loop, but as i know very little about them, I'd use a if statement;

You'd have to check for the keys individually using the /v switch in reg query. something like;


Code: [Select]reg query /v hklm\SOFTWARE\CryptionDirectory\install
if "%errorlevel%" GTR "0" (goto fail) ELSE goto pass

echo This shoud never be seen


:fail
echo unable to find key
start test2.bat
exit

:pass
echo Key's exist ok
start test1.bat
exit


I've never used reg query before, but I'd guess that if you looked for them individually you COULD use the %errorlevel% produced. If you looked for more than one at one time, I THINK you get unpredictable results.

I might well be wrong, but I thought I'd throw in my 2 cents. 


Hope it helps.


if errorlevel 1 actually means "if errorlevel is 1 or more".

the &AMP;& (success) and || (failure) operators might be useful here.

e.g.

reg query /v hklm\SOFTWARE\CryptionDirectory\install && goto yes


The subkey count is  uncertain, and i don't know the name of subkey, how can i do???Why do you want to do this?
if no subkey exists, the execute result of reg query is as following:

C:\Documents and Settings\linuxyf>reg query hklm\SOFTWARE\CryptionDirectory /s

! REG.EXE VERSION 3.0

HKEY_LOCAL_MACHINE\SOFTWARE\CryptionDirectory



if subkey  exists, the execute result of reg query is as following:


C:\Documents and Settings\linuxyf>reg query hklm\SOFTWARE\CryptionDirectory /s

! REG.EXE VERSION 3.0

HKEY_LOCAL_MACHINE\SOFTWARE\CryptionDirectory
    subkey1     REG_SZ  1
    subkey2     REG_SZ  2

I only want to know whether subkey exists or not under the "hklm\SOFTWARE\CryptionDirectory" in registry?

if exists, then execute test1.exe, or not, execute test2.exenot knowing 'reg query' all that well, you might have to output it a txt file and pull the lines that contain the reg keys names back in. Then you can say 'if the lies are blank do this...'


something like;

Code: [Select]echo off

rem outputing result of reg query to a txt file

reg query hklm\SOFTWARE\CryptionDirectory /s > C:\regOUTput.txt

rem bringing in line 4

setlocal enabledelayedexpansion
set count=0
for /f %%v in (c:\regOUTput.txt) do (
set /a count=!count!+1
if !count!==4 set /a reg=%%v
)


rem if line 3 is blank = no reg keys, run test1.bat

if "%reg%" == "" (start test1.bat) ELSE start test2.bat


This is untested and you'll have to play around with it to get it to work. I'd SUGGEST running the first line (outputting to a txt file) from a command prompt and then opening the file to see the results. Count the number of lines down and note the line number that the first result is on. (from what you've posted, I'd say line 4, but better to check)

You'll have to sub that number for the number 4 that I've used in the code above.

Let us know how you get on.
becase the subkey names are full path, so i meet requirement with following code:


echo off
cls

setlocal enabledelayedexpansion

for /f "tokens=2 delims=:" %%i in ('reg query hklm\SOFTWARE\CryptionDirectory /s
') do goto success 

echo no subkey!
pause>nul

:success
echo find key ok
pause>nul

1870.

Solve : DosNewbie got problem with fc command! please help....?

Answer»

set count
for /L %%i in (1,1,7) do (

   fc solutions\%%i.txt Othersolutions\%%i.txt /A >> result.txt

)

I wanna count the number of DIFFERENT files in two directory solutions and Othersolutions. But how do I KNOW that files are different? Does fc command return ANYTHING?After fc has run, the variable %errorlevel% will be ZERO if the files are the same, and nonzero if they are different.

Thanks, Dias. I can't find this INFORMATION anywhere else but here . Thanks again man.

1871.

Solve : zZoOoOmM effect?

Answer»

Is there a way in batch to make a zoom in or out effect?

Thanks for any help that you could offer,
Tan_ZaYou mean like ALT + ENTER on the Keyboard?No that does not zoom or make a zoom affect that just changes the batch FILE to full screen.

Tan_ZaSo what do you mean by Zoom Effect?Well so it looks like you are ZOOMING in on an object but you are not really.

Tan_ZaSo like from something to this?Yes kind of, but not with letters but with say with this (▓)

Tan_ZaNice symbol...



As far as I know, I don't know any tool that will increase the size of the text in Command Prompt.

Also, how do you save '▓' in a batch file? Notepad cannot save it...i used echo ▓>>a.txt
and then using the DOS editor
edit a.txt

it read it
put i dont know how to write it directly i made copy PASTE for it
it will be nice if i knew how to write simpols like that  No I know that symbol will not work but that is not what I meant, but any way if you could make it seem like you are zooming in that would be great.

Tan_ZaIs there an example you could show US?

1872.

Solve : Batch file with controlled user input?

Answer»

Hello, everybody. I'm new here, but I try to learn a few THINGS about creating batch files.
I'm trying to create a batch file in order to do some video encodes, but via CMD without a GUI.
So here is an example (it doesn't fully work of course:))

Code: [Select]ECHO OFF
cls
color 2

:question1
ECHO Select the path where x264.exe is located.
ECHO examples: C:\Program Files\megui\tools\x264 or D:\Encoding Tools
ECHO.
SET /p x264_path=
IF errorlevel 1 goto question2
IF errorlevel 2 goto end

ECHO.
:question2
ECHO Select the path and the name of the avs script. (without the .avs extension!)
ECHO e.g. D:\MyMovie\avisynthscript
ECHO.
SET /p avs_path_filename=
IF errorlevel 1 goto question3
IF errorlevel 2 goto end

ECHO.
:question3
SET /p bitrate=Select the video bitrate (kb/s):
IF errorlevel 2 goto question4
IF errorlevel 1 goto end

ECHO.
:question4
SET /p ref_frames=Select the number of reference frames (1-16, recommended 4):
IF errorlevel 2 goto question5
IF errorlevel 1 goto end

ECHO.
:question5
SET deblocking_strength=Set the deblocking strength and threshold (-6:-6, default -1:-1):
IF errorlevel 2 goto question6
IF errorlevel 1 goto end

ECHO.
set b-adapt_mode=2
set b-frames_number=3
set subme_mode=9
set TRELLIS=2
set psy-rd=0.1:0
set ME=umh
set me_range=32
set priority=BELOWNORMAL
set stats_path=%avs_path_filename%.stats

cls

ECHO ON
ECHO:Encoding 1st pass started on %date% - %TIME%
ECHO.
ECHO OFF

start "x264" /%priority% /b /wait "%x264_path%\x264.exe" --pass 1 --bitrate %bitrate% --stats "%stats_path%" --level 4.1 --keyint 240 --min-keyint 24 --ref %ref_frames% --mixed-refs --no-fast-pskip --bframes %b-frames_number% --b-adapt %b-adapt_mode% --b-pyramid --weightb --direct auto --filter %deblocking_strength% --subme %subme_mode% --trellis %trellis% --psy-rd %psy-rd% --partitions p8x8,b8x8,i4x4,i8x8 --8x8dct --vbv-bufsize 50000 --vbv-maxrate 50000 --me %ME% --merange %me_range% --threads auto --thread-input --sar 1:1 --progress --no-psnr --no-ssim --output "%avs_path_filename%_pass1.mkv" "%avs_path_filename%.avs"

ECHO ON
ECHO.
ECHO:Encoding 1st pass finished on %date% - %time%
ECHO:==============================================================================
ECHO:==============================================================================
ECHO.
ECHO:Encoding 2nd pass started on %date% - %time%
ECHO.
ECHO OFF

start "x264" /%priority% /b /wait "%x264_path%\x264.exe" --pass 2 --bitrate %bitrate% --stats "%stats_path%" --level 4.1 --keyint 240 --min-keyint 24 --ref %ref_frames% --mixed-refs --no-fast-pskip --bframes %b-frames_number% --b-adapt %b-adapt_mode% --b-pyramid --weightb --direct auto --filter %deblocking_strength% --subme %subme_mode% --trellis %trellis% --psy-rd %psy-rd% --partitions p8x8,b8x8,i4x4,i8x8 --8x8dct --vbv-bufsize 50000 --vbv-maxrate 50000 --me %ME% --merange %me_range% --threads auto --thread-input --sar 1:1 --progress --no-psnr --no-ssim --output "%avs_path_filename%_pass2.mkv" "%avs_path_filename%.avs"

ECHO ON
ECHO.
ECHO.
ECHO:Encoding 2nd pass finished on %date% - %time%
ECHO:==============================================================================
ECHO:==============================================================================
:end
What I'd like to do is for example when asked for the desired bitrate, to accept only numbers and have a default value for all the variables.
So the user can input his choice but if he wants, he could press for instance the letter D and automatically the default value would be entered.
Also I'd like to contain some values. for instance in the ref frames from 1-16 etc.

Thank you in advance!

PS1. Sorry for my English.
PS2. If these are answered somewhere, please point me there.You're asking for an awful lot from a language with a limited instruction set.

Quote

What I'd like to do is for example when asked for the desired bitrate, to accept only numbers and have a default value for all the variables

Without a third party program, you have to check the data entry after the fact:

Code: [Select]echo off
setlocal enabledelayedexpansion
set numflag=y
set /p bitrate=Enter bit rate:
for /l %%i in (0,1,19) do (
call set bit=%%bitrate:~%%i,1%%
if .%bitrate%==. set bitrate=192 & goto next
if .!bit!==. goto next
echo !bit! | findstr [0-9] > nul
if errorlevel 1 set numflag=n
)
:next
if %numflag%==y echo %bitrate% is numeric
if %numflag%==n echo %bitrate% not numeric

The code does not restrict alpha characters; only checks if the input is numeric; the length of the input is determined by the first space character or 20 characters, whichever comes first. The default bit rate is 192.

Setting defaults should be a little simpler:

Code: [Select]echo off
set bitrate=
set /p bitrate=Enter bitrate:
if .%bitrate%==. set bitrate=2400
echo %bitrate%

The default value is used when the user enters no value to the prompt.

The code snippets are designed to show method. Hope it gives you some ideas for your code.

Good luck.
Oh dear, chem4! Those long lines of code make this thread a scroll bar NIGHTMARE!!!
1873.

Solve : Split folders??

Answer»

Hey there,

I have a folder with over 4000+ files, and I'd LIKE to split that folder in other folders with each 100 files. So there should be 40 new folders with each 100 files of the main big folder (the one with 4000+ files). I have no idea how to do this, I THOUGHT about something like echo the 'DIR' command into a textfile, and then with 'FOR' command read out of the textfile all the names but then I'm stuck. Can ANYONE please help me creating such code?echo off
mkdir 1 |mkdir 2 |mkdir 3 |mkdir4 |mkdir 5 |mkdir 6 |mkdir 7 |mkdir 8 |mkdir 9 |Mkdir 10
mkdir 11 |mkdir 12 |mkdir 13 |mkdir 14 |mkdir 15 |mkdir 16 |mkdir 17 |mkdir 18 |mkdir 19 |Mkdir 20
mkdir 21 |mkdir 22 |mkdir 23 |mkdir 24 |mkdir 25 |mkdir 26 |mkdir 27 |mkdir 28 |mkdir 29 |Mkdir 30
mkdir 31 |mkdir 32 |mkdir 33 |mkdir 34 |mkdir 35 |mkdir 36 |mkdir 37 |mkdir 38 |mkdir 39 |Mkdir 40
:0aaa
set c=0
set /a d=%d%+1
for /F "tokens=1 delims=*" %%a in ('dir /a * /b') do ( 
  move %%a %d%
  set /a c=%%c%%+1
  if "%c%"=="100" Goto 0aaa
  )

i don thave time to test this, it might work . put it in a batch file inside the directory it only creates two folders with just nothing in it... hmmm weird. I'll try to debug it myself first.

Edit: I have no idea how to make this work, I don't get what's wrong 'cause the code seems good to mevbscript
Code: [Select]On Error Resume NEXT
Set objFS = CreateObject("Scripting.FileSystemObject")
strFolder = "c:\test\test"
Set objFolder = objFS.GetFolder(strFolder)
iCounter=0
dirCounter=1
If Not objFS.FolderExists(dirCounter) Then
objFS.CreateFolder(CStr(dirCounter))
End If
For Each strFiles In objFolder.Files
If strFiles.Name <> "moveFiles4000.vbs" Then
WScript.Echo "Moving " & strFiles.Name
objFS.MoveFile strFiles.Name,dirCounter & "\" & strFiles.Name
iCounter=iCounter+1
If iCounter = 100 Then
    dirCounter=dirCounter+1
    objFS.CreateFolder(CStr(dirCounter))
iCounter=0
End If

End If
Next
diablo416, did you even try that code?

1874.

Solve : Batch file to run Telnet command that looks up a list?

Answer»

hi there. . I need some help automating a script.

This will be for multiple devices located in a hospital that i will need to terminal to. Each device in a room has a static IP.

I need a batch file called tel.bat or something that would do this

c:\Tel 454

the 454 being any room number i need to telnet to at taht time

i want the batch file to look up that room number on a list and match it to an ip then telnet to it. im assuming comma DELIMITED format exported from excel. so it would be like

454,172.1.1.1
455,173.1.1.1

etc on the list.

how do i do this? im TIRED of LOOKING up hundreds of these ip addresses of these each day..

thank you in advance.
Quote

i want the batch file to look up that room number on a list and match it to an ip then telnet to it. im assuming comma delimited format exported from excel. so it would be like

454,172.1.1.1
455,173.1.1.1

If Excel quotes each of the fields in the comma SEPARATED file, the code can modified to take that into account.

The snippet below uses the above file labeled room.csv

Code: [Select]echo off
set /p rm=Enter Room Number:
for /f "tokens=1-2 delims=," %%i in (room.csv) do (
if %rm%==%%i telnet %%j
)

If needed the code can be modified to LOOP should the user enter an incorrect room number.

Good luck.
1875.

Solve : Close the current program with a batch file?

Answer»

I'd like a way, if possible, to close the current running program through a batch file.
I don't think the kill.exe (run the kill eh?) tool can do this as the program to be CLOSED will vary.
It doesn't need to be fancy, it just needs to close whatever is running, which will be the only visible window.

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

For example, if you have notepad OPEN, taskkill /im notepad.exe will close it.Taskkill ALSO doesn't work for my needs, as as far as I am aware the program itself needs to be specified.
I can't specify the program as it will vary.
By the way, this isn't homework, although it is starting to SOUND like it huh? Quote

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

Is everyone getting PARANOID?

I doubt you can do this in batch. In fact even using the Windows Shell, you can only kill Explorer windows. One solution would be to use Word (don't ask) which can enumerate the open windows and more importantly close them.

Code: [Select]Set wd = CreateObject("Word.Application")
Set colJobs = wd.Tasks
For Each job In colJobs
If job.Visible = True And job.Name <> "Program Manager" Then
colJobs(job.Name).Close
End If
Next
wd.Quit

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

Good luck. Wow, that was more effective than I thought, I neglected to close what I had open because for some for some reason I expected it to fail, things like this usually don't work for me.
That's great, just what I need.
Thanks a lot Sidewinder!
1876.

Solve : DOS - copy most recent created folder?

Answer»

I am creating a BATCH file which should, among other, copy from a known path the most RECENT folder.

ThanksWelcome to the CH forums.

You have not defined what you mean by "most recent folder."  This could mean the most recently created folder or the most recently accessed or the folder which has most recently had files added/amended.  However....

Modify the paths to suit your requirements and try this:

CODE: [Select]echo off & setlocal
cls

set knownpath=c:\windows\system32\

for /f "delims=" %%a in ('dir /ad /od /b "%knownpath%"') do (
    set name=%%a
)

md "d:\temp\%name%"

copy "%knownpath%%name% d:\temp\%name%\"


This will not copy sub-folders.

Good luck.Thank you very much it was very helpful.
BTW one typo in this line
copy "%knownpath%%name% d:\temp\%name%\"

should be

copy "%knownpath%\%name%" "d:\temp\%name%\"
I disagree about the typo, %knownpath% is already set to C:\Windows\System32\ - ADDING ANOTHER backslash should not be necessary.  However, I should have wrapped the source and destination paths/filenames individually in double quotes.

e.g. copy "%knownpath%%name%" "d:\temp\%name%\"

Thanks for coming back with your comments.

1877.

Solve : Enter in batch file?

Answer»

Hi!

I am USING a batch file to call and run a simple program on a series of files.

However, when this programs ends what he needs to do with the first file, I receive the message 'Press Return to Exit', and my batch job STOPS here.

I can't find the command to 'Press return' so that the job may continue.

Can anybody help me?

ManukaWelcome to the CH forums.

Without viewing your script it's hard to advise but try this on the line where your program is called/executed:

Echo. | program_name {any parameters}

Good LUCK Well well, that works perfectly!
Thanks a lot!...

I got by with it by just leaving a heavy book on the Enter key while taking my break, but it feels less dirty that way!!!
Quote from: Manuka

I got by with it by just leaving a heavy book on the Enter key while taking my break,

ROFLMAO - that sure is a REAL good work around.

Thanks for COMING back to report success.

Good luck.
1878.

Solve : Have a batch file enter text for you?

Answer»

Hi GUYS,

Im new here and to batch FILES, i was trying to write an easy batch file that would flush my pc's DNS. The way i do it now would be to go to the command window and type ipconfig /dns. Im not SURE if this is correct but this is what im thinking. Please correct me where i know im wrong

echo off
echo This will Flush your DNS
pause
c:\windows\system32\cmd.exe
type ipconfig /dns

echo on

Thanksyou don't need to start cmd, it starts automatically for a batch
you only need one line:

Code: [Select]type ipconfig /dns
in a Batch file.
or to get the effect you SEEM to be going for:

Code: [Select]Echo off
echo this will flush your DNS
pause
ipconfig /dns
I've got a batch file I use just for this. (we had issues a while back and the DNS needed to be flushed)

I don't have it with me, but it was something along the lines of.....

Code: [Select]echo off
cls
echo.
echo.
echo.                            Pressing a KEY will flush your DNS
echo.
echo.
echo.
pause>nul
ipconfig /flushdns

ping localhost>nul

ipconfig /registerdns

echo.
echo.
echo.           DNS is now flushed. Please see above for any errors
echo.
echo.
echo.
pause
exit

hope it helps.thanks for the info, im a noob and have allot to learn. Where do you reccommend that I start? I have done a bunch of google searches and found some dos command pages but im not sure how to use them. Thanks

1879.

Solve : Emilware....This is your post?

Answer»

I tried responding to this PM however Emilware's mailbox is full. <sigh>

Quote

hey Sidewinder
i'm tring to create a batch file that searches and replaces text in files .src and .dat.
this is the code i'm using
echo on
echo in progress
setlocal enabledelayedexpansion
for /f %%x in ('dir /a:-d /s /b C:\transfer\*.txt') do (
   for /f "tokens=* delims=" %%i in (%%x) do (
      set input=%%i
      set input=!input:bob=emil!
      set input=!input:smith=mark!
      set input=!input:peter=kevin!
      echo !input! >> %%x.chg
               
               
           
               
   )

set oldname=%%x
set newname=%%x.chg
ren !newname! !oldname!

)

endlocal   

i'm having a problem changing the name of the file that gets CREATED BACK to original name .
the file that gets created has a extension .chg and i need to loose that extention.
can you help
Please i spent 3 day on this i get nowhere.

Emil,

I prefer not to answer PM, but rather try and help out on the public boards. This gives even the casual user a chance to learn from the posting.

Quote
Please i spent 3 day on this i get nowhere

It got you here and we're somewhere. Nowhere is to the left!

Code: [Select]echo on
echo in progress
setlocal enabledelayedexpansion
for /f "tokens=* delims=" %%x in ('dir /a:-d /s /b C:\temp\*.txt') do (
   for /f "tokens=* delims=" %%i in (%%x) do (
      set input=%%i
      set input=!input:bob=emil!
      set input=!input:smith=mark!
      set input=!input:peter=kevin!
      echo !input! >> "%%x.chg"
   )
   ren "%%x" "%%~nxx.old"
   ren "%%x.chg" "%%~nxx"
)

The snippet labels the original file with an old extension and labels the NEW file with the original name.

Good luck. thank you for your help. this works great and sorry about sending u PM. i'm new to this.
like i said this works but i have an other problem. when new file gets created and the lines are being copied for some reason it skips lines starting with   ;FOLD and  ;ENDFOLD  .Is there a way to FIX that?
this is example of the file that i'm tring to change.

;FOLD ; *** Timer Start SW ***;%{PE}%R 4.1.16,%MKUKATPBASIS,%CCOMMENT,%VNORMAL,%P 2:*** Timer Start SW ***
;ENDFOLD
$TIMER[3]=0
$TIMER_STOP[3]=FALSE
;FOLD ; **********************;%{PE}%R 4.1.16,%MKUKATPBASIS,%CCOMMENT,%VNORMAL,%P 2:**********************
;ENDFOLD

;FOLD PTP lap110 CONT Vel= 100 % PDAT11 Tool[15]:Car-Zero Base[6]:car-0 extTCP;%{PE}%R 4.1.15,%MKUKATPBASIS,%CMOVE,%VPTP,%P 1:PTP, 2:lap110, 3:C_PTP, 5:100, 7:PDAT11
$BWDSTART = FALSE
PDAT_ACT=PPDAT11
BAS(#PTP_DAT)
FDAT_ACT=Flap110
BAS(#FRAMES)
BAS(#VEL_PTP,100)
PTP Xlap110 C_PTP
;ENDFOLD

;FOLD PTP sw164w11625013 PDAT26 SPOT Gun= 2 RETR CLS ACTIVE= 1 Tool[15]:Car-Zero Base[6]:car-0 extTCP;%{PE}%R 4.1.11,%MKUKATPSPOT,%CSPOT,%VPTP,%P 1:PTP, 2:sw164w11625013, 3:, 5:100, 7:PDAT26, 10:2, 12:#FIRST, 14:#CLO, 16:0, 18:1, 20:0, 22:0, 24:1, 25:NORMAL
$BWDSTART = TRUE
PDAT_ACT=PPDAT26
BAS(#PTP_DAT)
FDAT_ACT=Fsw164w11625013
BAS(#FRAMES)
BAS(#VEL_PTP,PPDAT26.VEL)
S_ACT.GUN=2
S_ACT.PAIR=SDEFAULT.PAIR
S_ACT.RETR=#CLO
S_ACT.CLO_TM=1
S_ACT.PGNO1=11625013
S_ACT.PGNO2=SDEFAULT.PGNO2
S_ACT.PRESS1=SDEFAULT.PRESS1
S_ACT.PRESS2=SDEFAULT.PRESS2
S_READY=FALSE
PTP Xsw164w11625013
USERSPOT(#SPOT, S_ACT)
WAIT FOR S_READY
;ENDFOLD

The sw164w11625013 must be change to sw164w1100625013. I must insert 00 after 11.
If there is a way just to modify original file by inserting 00 after sw164w11 insted of creating a new file, then that would work too.
I tried writing VBS but with out wildcard i cant get it to open and change all files with extension .SRC and .DAT in the folder.

Code: [Select]Const ForReading = 1
Const ForWriting = 2
Const FileIn = "C:\transfer\test.txt"
Const FileOut = "C:\transfer\test.txt"  '<== Change to prevent overwrite of original file

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(FileIn, ForReading)

strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, "bob", "emil")

Set objFile = objFSO.OpenTextFile(FileOut, ForWriting)
objFile.WriteLine strNewText
objFile.Close

PLease help me if u can.
thanks
By default FOR /f skips lines with a semicolon at the start.  For them to be read, a different end of line (eol) character must be assigned in the delims block. Choose a suitable character that does not appear in the lines you wish to process. In this example I have used the character

for /f "[email protected] tokens=* delims=" %%i in (%%x) do (

Quote
I tried writing VBS but with out wildcard i cant get it to open and change all files with extension .SRC and .DAT in the folder.

This should eliminate your need for a wildcard:

Code: [Select]Const ForReading = 1
Const ForWriting = 2

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set f = objFSO.GetFolder("c:\transfer")
Set fc = f.Files

For Each fs In fc
If objFSO.GetExtensionName(fs) = "SRC" Or objFSO.GetExtensionName(fs) = "DAT" Then
Set objFile = objFSO.OpenTextFile(fs.Path, ForReading)
strOldText = objFile.ReadAll
objFile.Close

strNewText = Replace(strOldText, "bob", "emil", 1, -1 ,1)    'First replace use strOldtext
strNewText = Replace(strNewText, "smith", "mark", 1, -1, 1)  'Subsequent replace use strNewText
strNewText = Replace(strNewText, "peter", "kevin", 1, -1, 1)

Set objFile = objFSO.OpenTextFile(fs.Path, ForWriting)
objFile.WriteLine strNewText
objFile.Close

Set objFile = objFSO.CreateTextFile(fs.Path & ".old")
objFile.WriteLine strOldText
objFile.Close
End If
Next

The replace function is case insensitive. Same situation applies as with the batch code: original file gets labeled with an old extension; Changed file has same label as original file.

Good luck. Thanks SIDEWINDER

YOU REALY KNOW YOUR STUFF
This works great 
Its lot faster than batch.
This is the best search and replace.
Thanks
1880.

Solve : FOR... IF variable-PC name is off-line get next name from text file - problem?

Answer»

I need help with the following problem:

I want the batch file to run a query on the Scheduled Tasks of all computers that
A) are listed in the text file "computers.txt" and
B) at the time of running the SCRIPT - they are online.

If a computer is off, the FOR loop would pick the next computer name from the text file.

I use PING to check whether the computer is online and use the error level after the response to decide to go ahead with the scheduled task check or pick the next PC.

Here is the code, that I am using, it works, but I was unable to make the script to go the next computer name in case the computer is offline and it runs ALL commands on the offline computer which of course results in errors anyway and it SLOWS the whole script down unnecessarily in case of 60 computers.

===========================================
set errorlevel=0
for /f "DELIMS==" %%A in (computers.txt) do (
     ping -n 1 -w 1 %%A
     if %errorlevel%==0 (
          schtasks /query /s %%A /fo table /nh>>result.log
          schtasks /delete /s %%A /tn defrag_c /f>>result.log
          )
     )
===========================================

I think, some kind of ELSE statement is missing here I just don't KNOW how to intervene with the FOR statement using ELSE of an IF statement.

In this example I had two computer names in the file "computers":
pc1
pc2

and here is the result of running the batch file in the current state:

=============================================================
D:\ADATA\My Files\Batch\Scheduled Tasks>runsetup.bat

D:\ADATA\My Files\Batch\Scheduled Tasks>set errorlevel=0

D:\ADATA\My Files\Batch\Scheduled Tasks>for /F "delims==" %A in (computers.txt) do (
ping -n 1 -w 1 %A
 if 0 == 0 (
schtasks /query /s %A /fo table /nh 1>>result.log
 schtasks /delete /s %A /tn defrag_c /f 1>>result.log
 )
)

D:\ADATA\My Files\Batch\Scheduled Tasks>(
ping -n 1 -w 1 pc1
 if 0 == 0 (
schtasks /query /s gkkglenfile /fo table /nh 1>>result.log
 schtasks /delete /s gkkglenfile /tn defrag_c /f 1>>result.log
)
)

Pinging PC1 [192.168.0.58] with 32 bytes of data:

Reply from 192.168.0.58: bytes=32 time<1ms TTL=128

Ping statistics for 192.168.0.58:
    Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 0ms, Average = 0ms
ERROR: The specified task name "defrag_c" does not exist in the system.

D:\ADATA\My Files\Batch\Scheduled Tasks>(
ping -n 1 -w 1 pc2
 if 0 == 0 (
schtasks /query /s pc2 /fo table /nh 1>>result.log
schtasks /delete /s pc2 /tn defrag_c /f 1>>result.log
)
)
Ping request could not FIND host pc2. Please check the name and try again.
ERROR: The network path was not found.
ERROR: The network path was not found.
D:\ADATA\My Files\Batch\Scheduled Tasks>
=============================================================

I need help here!
The syntax for the errorlevel check is in error. Errorlevels are not numeric values that can be checked arithmetically. The actual compare is the value you declare and above.

Code: [Select]set errorlevel=0
for /f "delims==" %%A in (computers.txt) do (
     ping -n 1 -w 1 %%A
     if not errorlevel 1 (
          schtasks /query /s %%A /fo table /nh>>result.log
          schtasks /delete /s %%A /tn defrag_c /f>>result.log
          )
     )

This should fix you up; the errorlevel is checked for not 1 or greater (meaning zero) and you should not need an else clause in your code.

Good luck. Sidewinder,

Thank you very much for the elegant solution, it works!

(and also thanks for the info on the nature of errorlevel!)

Geza

1881.

Solve : Inserting EOF in a batch file?

Answer»

I want to make a batch file that erases all the contents in a .txt file.

I was thinking about making a new file with the same name, but can't get it to insert the EOF character in the file, so the user doesn't have to.

Is there a way of doing this?...or maybe an easier way to erase the contents.

Thanks beforehand

Two-eyes

just TYPE 00>C:\folder\Yourfile.txtWindows txt files do not have an eof character, if by that you mean ctrl-z ASCII 26.

On modern OSes, the EOF character doesn't actually end a file - the size of the file is EXPLICITLY stored in the filesystem, and the contents can be anything.

On older systems the file size was only stored with a certain level of PRECISION, and the EOF character was used on text files to determine where in the last block of data the file ended.

In certain cases when dealing with text files or reading data from a "character device", the Microsoft MS-DOS shell (COMMAND.COM) or operating-system utility programs would historically append an ASCII control-Z character to the end of a disk file (though the basic kernel MSDOS.SYS file write CALLS never appended a control-Z). This was done for backward compatibility with some of the peculiarities of CP/M, since the CP/M file system only recorded the lengths of files in terms of how many 128-byte "RECORDS" were allocated. The MS-DOS filesystem has always recorded the exact byte-length of files from its very first version.

In Windows and DOS you can blitz a text file by just echoing a cr + lf to overwrite it thus:

Code: [Select]echo.>Yourfile.txt

Quote

I want to make a batch file that erases all the contents in a .txt file.

Could you explain why you can't just delete the text file?
the "00>c:\folder\myfile.txt didn't work" ... "00 is not an internal or external command"
The "echo. > myfile.txt" worked like a charm (although I can't say i perfectly understood what you said Dias  )
Thanks very much.

Y'all a great community: 1hour from post I get an answer.
ThanksAbout the Quote
Quote
I want to make a batch file that erases all the contents in a .txt file.

Could you explain why you can't just delete the text file?

I only want to remove the contents not the file. I will be writing new information on the file.  I tried to save the name and create a new file (temp), delete the older one, then change the name of temp.txt.  But i needed to show that i wanted and empty temp.txt, i wanted to insert ^Z and couldn't find a way to do that.
Hope you understood my long sentence. umm- just use > instead of >> when you want to delete it. > will overwrite the entire contents of the file, after which you can use >> to append more.
1882.

Solve : Beginner syntax question?

Answer»

I'm trying to copy all the files within a tree to another folder.

I can't get this to work. I have the folder "main" and within the folder I have the folders "tree" (where the files are) and "new" where I want to MOVE the files too. The .bat FILE is in the "main" folder.

Code: [Select]FOR /R tree %%P IN (*.*) DO COPY %%P new
I have no experience with DOS and I am wondering if I put in the variables correctly. Thanks in advance.If tree and new are the actual directory names, then the code will work. The new directory must be a subfolder of main.

You're not doing anything destructive, but if you have any doubts change copy to echo and see what will happen without actually doing anything.

Good LUCK. The system cannot find the file specified.

I'm running Windows XP if that makes a difference.I can't see your system, so are tree and new the actual directory names? Try using full path names for both the source directory and the target directory. This will eliminate any confusion as to where the batch file needs to look.

The new directory needs to exist prior to running your batch code. Copy does not make directories.

 

If tree and new are placeholders (variables) for directory names, they need to be enclosed in % symbols.

Good luck. YEAH tree and new are the directory names and I am now using full path names and it does not even run. The directory new already exists.This is turning into a chat room.

Quote

I have the folder "main" and within the folder I have the folders "tree" (where the files are) and "new" where I want to move the files too

Is this your directory structure:

Main
|
|__tree
|__new

There are other variations of the for command that might help here:

Code: [Select]echo off
for /f "tokens=* delims=" %%p in ('dir tree /s /b') do (
copy "%%p" new
)

 It WORKED!!! Thank you so much!!!
1883.

Solve : Output Echoed Text to File??

Answer»

Is it possible to output the echoed text (and any error MESSAGES) to a FILE?  I have a batch file that runs a java PROGRAM on multiple, and this batch file takes several hours to execute.  Some of my filenames are incorrect, and I get an error message (along the lines of 'Cannot find file').  Unfortunately, because I am RUNNING so many files, I can't tell which file that message is referring to (most of them work, it's just a few of them that do not work).

Is there any way to output the messages to a file, so I can look at it once the batch is finished?To redirect the output of a batch, do this

>logfile CMD /c mybatch

This creates a new instance of the shell and runs the specified command, all of the output of this is echoed to logfile

GrahamGot it.  Thanks!

1884.

Solve : Want to get todays date - 1 day value?

Answer»

hi...

i know how to to CURRENT date VALUE but i don know how to get a value of today's date minus 1 day.

i wan to get yesterday's date.

appreciate all yr helpuse set /a

set /a d=%d%-1
What's %d%? 

For me, echo %date% in Command Prompt is 01-Jul-08
So... set /a d=%date:~0,2% would give me 01

And then set /a yesterday=%d%-1 would give you yesterday's date.

However, it will say 00 instead of 30  why are you guys using DOS to do date arithmetic ? Its time to move on

OP. Use the next better LANGUAGE that M$ provides you, out of the box
Code: [Select]WScript.Echo DateAdd("d", -1, Now)

save the above as yesterday.vbs on the command prompt
Code: [Select]c:\test> CSCRIPT /nologo yesterday.vbs
many thx for all yr respond.

on the WScript thingy, u r saying it is out of box?  cant locate it in my PC/server. still on Win2000 & server is Win2003.
sorry...  kindly ignore my earlier respond.  got it!

again, many2 thx for your help.  now JEZ need to further improve on getting the information out of the result...

1885.

Solve : Batch file for Text File Read "surround" and Write?

Answer»

I have some simple text files that contain the file paths for folders and sub folders.  My current batch file creates the folder with a list of the file paths.  This is the command I am using to make the files:

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

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

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

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

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

The program that takes this file as an input can be particular about how it takes in a list of paths.  I can do this in VBA, however, I would rather not use excell for a rather simple operation if at all possible.

Thanks for the help.

Try this:

Code: [Select]ECHO off
cls

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

New_File1.txt should contain

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

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

Try this:

Code: [Select]echo off
cls

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

New_File1.txt should contain

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

Good luck.

Dusty,

Thank you, that works perfectly!    I am only going to add a few things so as to create a temp file that can be deleted and to create a new file each time.  This is to create a Search.pro file for ProEngineer so that it can find exactly where it needs to look for all of the parts of an assembly each time AUTOMATICALLY when a file is opened.  It'll save a lot of time for people importing new assemblies to their computer so that they can keep their standard Config.pro file and simply create new search.pro files when they open an assembly.  Long story with the ProEngineer side of things, but needless to say this will make my life a lot easier.

Thanks again for your help!
SEBNN

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

Code: [Select]echo !TrialFile >TrialFile.txt
dir /ad /s /b >>TrialFile.tmp
echo off
cls

for /f "Delims=" %%a in (TrialFile.tmp) do (
echo "%%a" >>TrialFile.txt
)
del .\TrialFile.tmp

Like I said, it works great and I have tested it multiple times.  Also, as an explanation, the ! in the code is to indicate to ProEngineer that the CHARACTERS following it are a comment and to write SOMETHING other than a blank line when the file is cleared for the first run.Thanks for coming back to report your success and post your coding.

D.

1886.

Solve : copy names & info from disk drives to a .txt file?

Answer»

would the fsutil command return excess information?
Code: [Select]fsutil fsinfo volumeinfo C:\   (or d, or E...)
thanks for the help..Sidewinder..!! it works nice under Admin accounts..
the only thing is that when i try to use this driveinfo.vbs in a guest account on WIN xp pro it gives me this error:
E:\driveinfo.vbs(7, 1) MICROSOFT VBScript runtime error: Permission denied: 'GetObject'

and it also wont follow through by copying the drives infos over to the report.inf
is there anyway at all to make this script work propperly in a guest account..


Quote from: Sidewinder on June 28, 2008, 07:21:56 PM

gumbaz,

This script is self-contained, no need for any batch files or supporting VBScripts.

Code: [Select]Const ForAppending = 8

strComputer = "."

Set objArgs = WScript.Arguments
Set fso = CreateObject("Scripting.FileSystemObject")
Set wmiServices  = GetObject ("winmgmts:{impersonationLevel=Impersonate}!//" & strComputer)
Set wmiDiskDrives =  wmiServices.ExecQuery ("SELECT * FROM Win32_DiskDrive")

For Each wmiDiskDrive In wmiDiskDrives
    Set wmiDiskPartitions = wmiServices.ExecQuery( _
    "ASSOCIATORS OF {Win32_DiskDrive.DeviceID='" _
         & wmiDiskDrive.DeviceID & "'} WHERE AssocClass = Win32_DiskDriveToDiskPartition")   

    For Each wmiDiskPartition In wmiDiskPartitions
        Set wmiLogicalDisks = wmiServices.ExecQuery _
            ("ASSOCIATORS OF {Win32_DiskPartition.DeviceID='" _
             & wmiDiskPartition.DeviceID & "'} WHERE AssocClass = Win32_LogicalDiskToPartition")
        For Each wmiLogicalDisk In wmiLogicalDisks
        If wmiLogicalDisk.Caption = UCase(objArgs(0)) Then
        Set tx = fso.OpenTextFile(wmiLogicalDisk.Caption & "\report.inf", ForAppending, True)
          tx.Writeline("     Drive: " & wmiLogicalDisk.Caption)
          tx.Writeline("     Model: " & wmiDiskDrive.Model)
          tx.Writeline("     Type:  " & wmiDiskDrive.Description)
          tx.Writeline("     Vol:   " & wmiLogicalDisk.VolumeName)
          tx.Close
          End If
        Next 
    Next
Next

All previous instructions concerning passing the drive letter on the command line with the colon apply here also.

Get a copy of Scriptomatic. Not only can it help you write your scripts in VBScript, Perl, JScript or Python, but you can learn about the WMI classes.

Good luck 


Quote
is there anyway at all to make this script work propperly in a guest account..

As far as I know, only local Administrators have permission to ACCESS WMI. You could try using the runas command or perhaps Group Policy.

 

PS. Glad to hear the script is working for you.

what is the  runas command..??
what does it do..??
how to use it in my case..??Runas is a utility that allows you to run jobs under another user's credentials.

Type runas /? at a commnad prompt for full details.

Runas is a security breach in that passwords must be shared. Check out Group Policy which may offer a better solution.

Question: why does the guest account need to run this script?

 WELL basically im making a batch app to log what kind of devices get plugged into my public PC and then dump the infos into a file for later viewing. but I want it to work on my guest account though.. Quote from: gumbaz on July 01, 2008, 08:42:44 PM
well basically im making a batch app to log what kind of devices get plugged into my public PC and then dump the infos into a file for later viewing. but I want it to work on my guest account though..
the problem is how are you going to log anything if the guy plugs in and out the device before you execute your script? And when running such "monitoring" mechanism, why would you want to run it as guest, if you are the administrator? makes no sense.

USBs, CD and any kind of removable devices can be logged by utilities already created to do such stuff. If you want to do it from scratch, you may want to try configuring your PC to log such events (if possible) and write scripts to query the logs. Or you could write a script that MONITORS removable devices and run it as a service.
1887.

Solve : Rename file with old date?

Answer»

Hello,

I want to rename my text file with previous date e.g.

Today(19-Nov-2008)..I have created a report file 10_Weeks_Report.txt, now I want to rename this file with suffix as 10 weeks old date i.e. 10 Sep,2008. means 10_Weeks_Report_10-Sep-2008.txt.

Is it possible??

Thanks in advance.One way of course is the most direct:

Code: [Select]ren 10_Weeks_Report.txt 10_Weeks_Report_10-Sep-2008.txt

I suspect however you want to calculate dates.  Batch language has no way of doing date and time arithmetic. You could use any of the Windows script languages, but many people seem to think that scripting is too close to PROGRAMMING. Uggh!

I've never use the FDATE utility, but I've seen it recommended on these boards. Good luck.  Here is a batch script COMBINED with VBS which will do date calculations returning today's date or adding or subtracting a number of days.  It's set to subtract 70 days, the ten weeks period asked for, but could be set to any number, or the number could be entered as a variable.

The majority of this was written by dias de verano then hacked around by me.

Code: [Select]:: Dias de verano.

echo off
cls


:: Create/run vbs file (extracts date components) & set variables..
:: -------------------------------------------------------------------
:start
set vbsfile=%temp%\newdate.vbs
echo Newdate = (Date()-70)>%vbsfile%
echo Yyyy = DatePart("YYYY", Newdate)>>%vbsfile%
echo   Mm = DatePart("M"   , Newdate)>>%vbsfile%
echo   Dd = DatePart("D"   , Newdate)>>%vbsfile%
echo   Wd = DatePart("WW"  , Newdate)>>%vbsfile%
echo   Wn = DatePart("Y"   , Newdate)>>%vbsfile%
echo   Ww = datepart("W"   , Newdate)>>%vbsfile%

echo Wscript.Echo Yyyy^&" "^&Mm^&" "^&Dd^&" "^&Wd^&" "^&Ww^&" "^&Wn>>%vbsfile%

FOR /F "tokens=1,2,3,4,5,6 delims= " %%A in ('cscript //nologo %vbsfile%') do (
        set Year=%%A
        set Month=%%B
        set Day=%%C
        set Week#=%%D
        set Weekday#=%%E
        set Day#=%%F
)
del %vbsfile%

for /f "Tokens=%month%" %%A in (
  "Jan Feb Mar Apl May Jun Jly Aug Sep Oct Nov Dec") do (
   set alfamonth=%%A
)

for /f "Tokens=%weekday#%" %%A in (
  "Sun Mon Tue Wed Thu FRI Sat") do (
   set alfaday=%%A
)

::                    [Environment Variables are:
::                     %Year%     in the format yyyy
::                     %Month%    in the format m or mm
::                     %Day%      number of the day in month in the format d or dd
::                     %Week#%    in the format w or ww (range 1 thru' 52)
::                     %Weekday#% day number in week in the format w
::                                     (range 1 thru' 7, day#1 is Sunday)
::                     %Day#%     day number in the year in the format d thru ddd
::                                     (range 1 thru' 366)
::                      %alfamonth%  month in the format Jan Feb....etc
::                       %alfaday%  day in the format Sun Mon....etc]

echo New-Year is %year%        New-Month is %month%/%alfamonth%        New-Day is %day%/%alfaday%

set newdate=%day%-%alfamonth%-%year%

ren 10_Weeks_Report.txt 10_Weeks_Report_%newdate%.txt

Good luck

1888.

Solve : THIS COULD BE THE FIRST LOGICAL QUESTION THUS FAR.?

Answer»

i have spent a good amount of time reading about variables and their commands okay everything is going great then all the sudden


this is the expaination to get me to note pad.
i just learned through trial the difference between external/internal commands
so i already know you can type NOTEPAD in the start run window
why all this MAX\..........
SINCE I just learned i could type notepad and get notepad i thought i would try the exact command befow to see if that worked also

no go nota  error comes up and says can't find "start"
this kind of directions has caused to bother the #$# out of you
so since i know i can just type notepad i will go about my business and learn to create a batch file
ruby



To run Microsoft Windows programs or files use the START command. The below example would run Windows Notepad.

START /MAX NOTEPAD

You can also specify the direct location of the file by typing the below command.

START /MAX C:\Windows\NOTEPAD.EXE

*Windows USERS who have a different directory (e.g. Windows 2000 users) would need to substitute WINNT or the name of their directory in place of Windows in the above example.

start /max is so notepad.exe will start maximized, Enter start/? at the command prompt to display the Start parameters.

Quote from: RUBY02 on June 30, 2008, 09:07:25 PM

no go nota  error comes up and says can't find "start"

Your PATH variable must be wrong.

What do you see if you type PATH at the prompt?
okay i have the image in paint "screenshot"
i can't get it to copy i thuoght maybe i could make a copy and paste it here no go could you explain how to get those shots to people in the forum?

i wanted to show you when i type in the word path what is in the line wait its the same line in the variable be bk

if you hang ten(toes)
i was trying to get gnu c++ going and i couldn't because the DGJPP vvariable was wrong the rhide kept telling to shut down
this is an exaple of what i did
i realize that it is wrong now this is how much i have grown in this process
%PATH%
C:\DJGPP\rhid15ab\.ENV

DJGPP
C:\DJGPP\rhid15ab\BIN

this is what is there also
Path
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\QuickTime\QTSystem\;C:\DGJPP\rhid15ab\bin\rhide.exe

hang this is MIRACLE that i even got the path command to work i am so excited i can type commands and they work.."some"
thanks rubyYour last entry should read

C:\DGJPP\rhid15ab\bin

The PATH variable should ONLY contain folder names.

the first time i typed the first example
start\max\.....dadada
the second time i type the longer version
start\max\notepad.exe....dadad.
neither worked
now you said to press start\ then i assume press enter okay it didn't burp on me but it seem to change ...now when you say paremeter or start
what exactly are you saying
how many paremeters are their so are you saying in order to get this command to work you have to be in the "start paremeter"

when i press just start i am in (cmd) system32 window
another window pops up "a new window"
then i type start\ (with the \
i get my programs folderpops up ready for me to look through the folders

okay this is what is happening and has been my problem all along no i thought i did
=====================================================
i have my cmd window open and i have my start run "general" open what does not work in one i try the other

both know the just the single word notepad nothing else

cmd KNOWS start and start\
if i INCLUDE max\ ...........no go nata nota

i realized the max\ was to maximize the window unfortunatly this is the amazing thing i can just about tell you what all these commands functions are and i can tell you what the purpose of the folders are for
i know you have commands that ASK the computer to preform tasks such as
i know fdisk i have used it, that command workd just about anywhere accept the engine of my car.
chkdsk i have used it it works at the cmd prompt
i know other folders just contain settings or paremeters for programs
i have learned way more than i can preform my problem has been like i said
all these months i am using the examples to a tee this is another example
that if i didn't know just notepad works i would have been here all week making dos disks, booting from a disk, you name it
like i spent all day reading external internal commands naturally to me in the med field external is outside the body so i am assuming because the explaination does not take you where they are the system 32 folder and show you them.  i assumed they were on a special disk, i made on from the site, i made one from 98 because this disk had no "dos commands" then i find out after two weeks i turn here and i find out xp is not a dos program "THAT WAS A SCREAM" SO ANYWAY YOU GUYS HAVE GOT ME THIS FAR DON'T PITCH IN THE COMPUTER YET. I AM MAKING PROGRESS I HAVE THE COMMANDS WORKING I JUST NEED TO FIGURE OUT HOW TO GET TO THEM FOR INSTANCE IS I TYPE DIR
I GET TO LOOK AT THE DIR BUT I CAN'T GET TO THE FILES IN THE DIR.
I CAN GET TO THE WINDOWS FOLDER BUT NOT TO ANY OF THE DIRECTORIES I NEED A PUSH

WHY WHY NOT JUST  TYPE NOTEPAD AND BOOM WHY ALL THE OTHER STUFF IF WOULDN'T HAVE KNOW THE ALTERNATIVE I WOULD BE A MESS RIGHT NOW
RUBY
Your English is not good enough for us to help you.
I AM SORRY ABOUT THE ENGLISH. I AM USED TO WRITING REPORTS(MEDICAL).  I AM NOT USED TO ASKING FOR ADVICE IN  NOR AM I EQUIPED WITH THE LINGO OF THE COMPUTER WORLD.  I WANT TO LEAVE MEDICAL AND START PROGRAMMING.  I HAVE MADE A MESS HERE BECAUSE I THINK I AM A GENIUS.?)  I COULD ASK FOR HELP  IN MEDICAL ABRIEVIATIONS.  IT'S HARD FOR ME SPELL.  THE MEDICAL PROFESSION WAS TEXT MESSEGING ON PAPER WAY BEFORE COMPUTERS.  I WILL GET IN THE GROOVE.  I ASSUME YOU CAN UNDERSTAND BECAUSE YOU ARE IN THE COMPUTER WORLD. I HAVE BEEN GETTING AHEAD OF MYSELF AND TEND TO RUN ON. PEOPLE USUALLY DON'T GET BACK TO YOU. I WILL BE MORE BRIEF. AND ASK ONE QUESTION AT A TIME  YOU GUYS ARE GOOD ABOUT GETTING BACK TO THOSE WHO ARE LOST.  I WAS MERELY, MAKING A POINT ABOVE, FOR THE REASON I COULD NEVER USE MY COMPUTER PROMPT OR THE COMMANDS.
I WAS ASKING WHY ALL THE COMMANDS WHEN NOTEPAD WOULD HAVE BEEN SUFFIENT.
THANKS FOR TRYING
RUBY
1889.

Solve : error message : C2471?

Answer»

I got the error message C2471 "cannot update program database"
While i try to COMPILE c++ file through makefile.

Do any one knows why this error comes ?error is solved.

for solving it you have to clean and rebuild the code again, the error comesout because old .pdb file is not deleted.

Hence clean or delete the .pdb file and again rebuild code issue gets resolve.

Thanks
MSDN gives this as the CAUSE:


       There is a limit of 4096 modules (.OBJ files) in a PDB file.
       The file also has a total size limit of approximately 64 MB.


    There is a vc90.pdb and a vc90.idb in the debug directory that's
under the library's directory with its source files.  There are 56
object files in the debug directory, vc90.pdb's size is 1540 KB.


1890.

Solve : rename files Incrementing by 1?

Answer»

i have 2000+ files that i have to rename starting with 001.tif. Can anyone help me please?If you start at 001.tif and you have 3 characters in the filename you will run out at 999.tif.

so what if i started at 00001.TIF. how would do that?What order do you want them named in? THE FILES ARE NAMED HY67EBD.TIF   AND I NEED TO RENAME TO 0000001.TIF
                                    HY68EDU.TIF                                              0000002.TIF
                                    HY69BUE.TIF                                              0000003.TIF
                                    HT54FDN.TIF                                              0000004.TIF
                                    BFGRY57.TIF                                               0000005.TIF
                                    BD84HDD.TIF                                              0000006.TIF
                                    HND85JM.TIF                                              0000007.TIF
                                    JKD84HF.TIF                                               0000008.TIF
                                 ALL THE WAY TO                                         ALL THE WAY TO
                                     HF834JV.TIF                                               0002000.TIF



That LIST starting HY67EBD.TIF and ending HF834JV.TIF, is that in date order or size, or what? Ascending or descending?

its a hexadecimal number and i just need to remane them in numerical orderthose aren't the exact files but they are numbered like that in order.You mean they have a filename which is a hexadecimal number, they are in ascending order without any gaps, and you want them renamed so that the lowest hex number is renamed 0000001.TIF and the highest hex number gets the name 0002000.TIF?from which position to which position are the hex numbers. The max for a hex number is F. There are G, J, U ETC in your file name so they are not hex.
Quote from: ghostdog74 on July 01, 2008, 09:19:45 PM

from which position to which position are the hex numbers. The max for a hex number is F. There are G, J, U etc in your file name so they are not hex.


Yes, I was wondering about that too.
Quote from: Dias de verano on July 02, 2008, 12:04:13 AM
Quote from: ghostdog74 on July 01, 2008, 09:19:45 PM
from which position to which position are the hex numbers. The max for a hex number is F. There are G, J, U etc in your file name so they are not hex.


Yes, I was wondering about that too.

well,maybe you could start the ball rolling without considering whether they are hex numbers. Just a normal file listing will do for a start. I want to know what order he wants the source list to be. I'm not a batch file floozy, I need to be wooed.
Quote from: Dias de verano on July 02, 2008, 05:48:33 AM
I'm not a batch file floozy, I need to be wooed.

Post of the year!!!

1891.

Solve : Batch file For loop File in Directory?

Answer»

Hi,

 I need to be able to loop the files in a directory and for each one append it to a path variable, I keep getting close but no cigar. Could someone help? here is what I have so far:

Code: [Select]:noEnvReset
set MY_CLASSPATH=
FOR %%f IN ( "%MY_DIR%\lib\*.jar" ) DO CALL :process "%%~f"
goto end

:process
if "%MY_CLASSPATH%"=="" set MY_CLASSPATH=%1
set MY_CLASSPATH=%MY_CLASSPATH%;%1
GOTO:EOF

:end
echo %MY_CLASSPATH%
If I take the conditional "if" out of the "process" sub-routine it builds the path fine but then dies at the end with:

Code: [Select]and was unexpected at this time.
If I leave the conditional in it just dies with the same error. Any help would be appreciated. Cheers.I've resolved this temporarily by passing the process sub-routine the names of all the paths using %~sf but would appreciate it if anyone had any better ideas. Cheers.I couldn't figure out why the call was necessary, so why not let the for do all the work, and get rid of the PESKY leading semi-colon after all the fireworks are over.

Code: [Select]echo off
:noenvreset
set my_classpath=
for /f "tokens=* delims=" %%f in ('dir /s /b /a-d "%MY_DIR%\lib\*.jar"') do (
call set my_classpath=%%my_classpath%%;%%~f)
)
set my_classpath=%my_classpath:~1%
echo %my_classpath%

This is not necessarily a better IDEA, just an alternative to what you came up with.

Good luck. 

you really don't like delayed expansion, do you, Sidewinder?
Quote from: DIAS de verano on November 19, 2008, 11:53:38 AM

you really don't like delayed expansion, do you, Sidewinder?


!DUE to unforeseen circumstances, the RESPONSE to this post has been delayed!

 

Thanks a lot for the help. It appears to work.

I will try and work out what the *censored* all these slashes and such mean at a later date, thanks again.
1892.

Solve : Run bat as admin?

Answer»

i have made a bat file, but it requires admin rights.
what should i do?
i don't want to hack the PC to run as admin, i just want to ask the user to run in admin, LIKE in vista
i have to right CLICK and PRESS run as admin, and the the MESSAGE prompts up saying continue?
i wanna get that message, but with out right clicking and pressing run as admin.
any idea?you might want to post this in the Microsoft Windows forum.

1893.

Solve : Increment variabile?

Answer»

Hi,

Why in this batch file the count  variabile doesn't increment ?
I want to put each line from a file in SEPARATE file .

Code: [Select]if "%1"=="" goto :ERROR
set count=0


for /f "tokens=* DELIMS= " %%a in (c:\IN\%1) do (
set count=%count%+1
  echo %%a > c:\in\%1_DIR\%count%
)

:ERROR

Thank you,
Bogdan

becouse VARIABLES in for and if COMMANDS ned to be in ! no in % and you must use setlocal at start


Code: [Select]setlocal enabledelayedexpansion
if "%1"=="" goto :ERROR
set count=0


for /f "tokens=* delims= " %%a in (c:\IN\%1) do (
set count=!count!+1
  echo %%a > c:\in\%1_DIR\!count!
)

:ERRORIt's OK now , but it's create file name like that "0+1", "0+1+1", "0+1+1+1" ...   
The variabile count it's interpretate as string.

BogdanBecause you need

set /a count=!count!+1

Yes ... it's working .
Thank everybody .

Bogdan

1894.

Solve : i want make a simple game in dos?

Answer» http://odn.t35.com/gamelatest


REALMS OF *censored* VERSION E

beyond roh , wont be done for a while.. but heres a demo, in a moded version of ROH

a few new commands, lots more areas.. alot of changes

- go back in time
- game time
- sleep
- updated everything
- load
- 120+ areas
- Game reliant on files generated during install.
- Generates 120 files originally but in 1 year game time there will be an additional 16000+ per year (game time)

- the loop goes to :XILE in every single area now, this made it easyer to add a single line of code for many areas
- the if statements have been replaced by a single for statement and a generic file for commands
room commands are HANDLED by another file v%rmid%

the improvements in this game from the last version make it more playable, there is 3 continents and a castle/homes , i dident add enemys/items but that will be in BEYOND ROH

http://odn.t35.com/gamelatest
I've been working on simalar lines ~ Here = my atempt:
Going Batty
~~~~~~~~~~~
You can write programs on your computer that end with  .BAT  (short for batch).
The following program:
   cd windows
   win
Would Change the current Directory to  windows  and then run  Windows 3.
Just enter both lines into the  Edit  text editor and save as  win.bat.
With the  echo  command you can print to the screen. Would you like an
adventure? Here is how to start one: Make a directory called  advent
   md advent
Then make a directory called  door  in it.
        cd advent
        md door
should do it! Now enter this into the text editor:
   echo off
   echo You cannot go this way.
Save it as  north.bat  into the  advent  directory. 
For  east.bat  you could have:
   echo off
   echo You see a door and go through it.
   cd door
        look
So you want pictures! They can be saved as self-extracting files with the
Graphwork  program but here we shall use a text file. A word processor
such as  WordPerfect 5.1  has a drawing mode. It is BETTER at making castles
as these do not have slopes. Save as a text file called  castle.txt.
        echo You see a beautiful castle!
        pause
   cls
   type castle.txt
Will wait for a key press, clear the screen and show your castle.
Save it as  look.bat
We are not stuck with one word commands. The line of a batch file:
   edit %1
would start  edit  and it would load the file with the
name you gave as a second word. So if we make the file that contains:
        %1
and call it  go.bat  we can use  go north  or  go east .
Start your adventure in the  advent  directory and try and find the castle.
We can use more than two words and open the door with a key.
But that is for next time.
Okay, this is a bump but this post fits in the topic. I know I haven't been doing much programming, and I certainly haven't worked on EDS as planned. Now I am finally ready to upload EDS V5. It is still in written with the DOS script, and I'm not sure how pleased anyone will be with this update. Don't expect many new FEATURES or any quests, but theres defanatley some new stuff thrown in it. Heres, a piece from the ReadMe.txt:
Quote
-IN THIS VERSION-

--BUG FIXES

--NEW STUFF
+----Forrests added:
  +----100
  +----150
  +----200
  +----500
  +----1000
+----A second random monster, same chance of attack
+----At top of stats box, your level is displayed
+----Status update after dieing
+----You can buy a print out of your stats in the store
+----New shortcuts to start in Window or Full Screen modes
+----New room in dungeon search

--OTHER STUFF
+----Skill limit; 1000

And, well, to actually try stuff out, you will just have to download it I guess. Please tell me what you think. I disparately need ideas for it now.

Oh and also, if you have an account already, then the die count thing wont work. Sorry.

[recovering disk space -- attachment deleted by admin]
1895.

Solve : need help.?

Answer»

i have downloaded bash shell for windows from http://www.steve.org.uk/Software/bash/
and keep all the FILES in side c:\bash folder ,now i have  TRIED to run make file form cmd.exe

makefile is LIKE

Code: [SELECT]SHELL=/bash/bash.exe

test:
echo "testing file"
when i execute this file  , i got an error : Quote

"/c: /c: No such file or directory"


can any one helps me how it works ?the slash direction in Windows is opposite to Linux Quote
the slash direction in Windows is opposite to Linux

I know i use the opposite one only , still it returns error. Code: [Select]SHELL = C:\bash\bash.exe
test:
echo "testing"

makefile works well now
thanks for the help
1896.

Solve : How To Share Folder in read ONLY in Batch file Support XP?

Answer»

How To Share FOLDER in read ONLY in Batch file Support XP

echo off
NET share TEST=C:\TEST

you can see in picture.



Help me PLZ. Help me PLZ. As you found out, net share does not have any parameters for permissions. Try using the CACLS utility or the xcacls utility.

Either of them can modify the access CONTROL lists.

Good luck.

1897.

Solve : Extract strings from inside .txt files?

Answer»

Hi,

I have hundreds (SOON to be thousands) of .txt files with the filename OR_00000001.txt, OR_00000002.txt and so on. These files all consist of one single row with fixed length fields.

I'm intrested in two fields inside those files; the first one in position 1, length 10 chrs and the second field in position 35, length 12 chrs.

How do extract the content in those fields from all files and put into a file called OR.txt?

Your best best would be to USE a utility DESIGNED for just such a requirement....

Microsoft give LogParser away for free : http://www.microsoft.com/downloads/details.aspx?FamilyID=890cd06b-abf8-4c25-91b2-f8d975cf8c07&DisplayLang=en

It is very very good
Graham Quote from: swede on November 19, 2008, 08:33:36 AM

Hi,

I have hundreds (soon to be thousands) of .txt files with the filename OR_00000001.txt, OR_00000002.txt and so on. These files all consist of one single row with fixed length fields.

I'm intrested in two fields inside those files; the first one in position 1, length 10 chrs and the second field in position 35, length 12 chrs.

How do extract the content in those fields from all files and put into a file called OR.txt?



if %variable% is a line of text, e.g. extracted using FOR, then a substring is defined as %variable:~a,B% where a and b are numbers: a is the offset from the start, [0 is the beginning], and b is the NUMBER of characters.

So the first 10 characters would be %variable:~0,10%

and the 12 characters starting at position 35 would be %variable:~34,12%


1898.

Solve : MS DOS batch file renaming folder using date?

Answer»

How can I get a batch file to rename a folder USING YESTERDAY's date as the new folder name? This must be a homework QUESTION! It seems to be popping up everywhere.

You need to

1. Find out today's date.
2. If the day number is greater than 1, subtract 1 from it. Keep the month and YEAR number the same. Go to step 8.
3. If the day number is 1, subtract 1 from the month.
4. If last month was 4, 6, or 11, make the day number 30
5. If last month was any of the others except 12 or 2, make the day number 31.
6. If last month was 12, make the day number 31, and the year number 1 less.
7. If last month was 2, check if the year is a leap year. If yes, make the day number 29. If no, make it 28.
8. Assemble the day,  month and year numbers into your local date format. Pad with zeroes as required.
9. Use this STRING to rename the folder.


1899.

Solve : COPY,CREATE?

Answer»

I've got a big problem:

I have to analyze several files and I want to do some automatism:

There are 7 subdirectories, in these subs there are several files,
I need from each directory one file, it's called f.e. 6006011A1_db.txt in the NEXT folder 6006021A1_db.txt and so on...so I can copy them like _db.txt(9 question mark for each letter) right?
So my AIM is I need to copy these files from each subdirectory to an output directory and put them together to one file in the order of the BOLD number...

Is that possible?
this is my code:

Code: [Select]ECHO on
md OUTPUT
xcopy ?????????_db.txt ..\OUTPUT /E
copy .\OUTPUT\?????????_db.txt NEW.txt /E

PAUSE
I dont want to copy the directories only the files in the subs...
then with all copied files I want to create one file in order of the number...

THANKS for answers...

1900.

Solve : uninstalling.....?

Answer»

how to UNINSTALL a PROGRAMME using Ms DOS?echo off
RD "C:\Program Files\%NAME%
pause

You need to set what %NAME% Will Be.This does not properly uninstall Windows programs, since registry entries will be left untouched. UB, you should really use the Windows Add/Remove Programs applet in Control Panel.If you must use CMD, START "" "C:\Program Files\Program Name\uninstall.exe"