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.

8651.

Solve : %~dp0?

Answer»

Hi,

I'm a novice at this at DOS...I'm required about once a year to look at it...so please explain in very simple terms...

I have some code in front of me :
set CONVERT=%~dp0

I've read something about it finding a PATH...but don't quit follow it...
The .cmd it is part of is in the following folder:
D:\prog\pdms\v10.0\plot\convert

So my first question is what does this do set "CONVERT=%~dp0" ?

- -----------------------------------------------------------------------------

I also have this :

CALL "%TEMP%\%~nx1.pdf.cmd"

I understand the call part and %TEMP% is a stored variable (expanding to a folder)...
It's this part that I don't understand :
\%~nx1.pdf.cmd
There are other .cmd in the folder and I think this is refering to one..
So I think it's only this part that is of interest:
\%~nx1.

- -----------------------------------------------------------------------------

And finally this :
-sOutputFile="%~dpn1.pdf"

Particulaly :
%~dpn1

Hope someone can help

Regards
neil

%0, %1 to %9 are "replaceable parameters". %0 is a special one - it expands to the name of the batch file itself.

%1 is the first parameter passed to the batch file from the command line or from another batch, %2 is the second one, and so on up to %9 (the highest possible).

THUS if you type

mybatch.bat cat dog "HORSE and cart" then in mybatch.bat, when it runs, %1 will expand to cat, %2 will expand to dog, and %3 will expand to "horse and cart"

The parameters can be modified using the same variable modifiers as FOR variables, for full documentation see the FOR help which you get by typing FOR /? at the prompt

They relate to files so that if %1 is a filename then %~d1 is a DRIVE e.g. C: and %~p1 is the path, %~n1 the name, %~x the extension. They can be combined e.g. %~dpnx1

for example %~dp0 contains the drive and path of the batch file itself





8652.

Solve : Issue with Replacable Parameters?

Answer»

The batch below is one for a school assignment.

@echo off

echo On %DATE% at %TIME% the %1% drive on the %computername% computer has:
dir |find "bytes free"

Upon execution, everything runs fine.

The only issue I have is with first line at %1%. After that none of my other text APPEARS, except the %COMPUTERNAME% which executes as "COMPUTERNAME".

I'm guessing there is an issue with the %1%, I'd appreciate the help. @echo off
rem Author: Meagan Parsons
rem Date: 2/10/2011
rem Name: freespace.bat
rem Purpose:

echo On %DATE% at %TIME% the %1% drive on echo the
echo %COMPUTERNAME% computer has

dir |find "bytes free"

I changed it up a bit and GOT all my INFORMATION to display. But I'd REALLY like to have the first two lines on 1 line. Is there a limit to the # of parameters/variables I can have on 1 line?
This may help:

Code: [Select]@echo off
for /f "tokens=3" %%i in ('dir %1 ^| find /i "bytes free"') do (
echo On %DATE% at %TIME% the %1 drive on %COMPUTERNAME% computer has %%i bytes free
)

Pass the drive LETTER on the command line. ( Ex. scriptname c: )

Good luck.
Quote from: mparsons12 on February 10, 2011, 07:24:36 AM

I'm guessing there is an issue with the %1%, I'd appreciate the help.

Replaceable parameters only have ONE percent sign, preceding the digit, e.g. %1
8653.

Solve : BATCH job failing to start?

Answer»

I have dozens of batch jobs that RUN during the weekend. A lot of them run at the same time.
At the end of each batch job I have the following line:

CALL %BATCH%\SETLEVEL.BAT %ERRLEVEL%

Basically, all jobs call SETLEVEL.BAT which does some cleaning up and stores the error level of the running job in its appropriate log file.

I'm not an expert in OPERATING systems but my question is this:

Is it possible that mutliple jobs call SETLEVEL.BAT at the same time but the call fails on one of them? I'm noticing in my log files that the log ENTRIES entered by SETLEVEL.BAT are MISSING. It's as if some jobs don't make the call above. Yet, the operating system shows no error message anywhere.

Thanks !


add a pause command at the end and tell me if there are any errors and tell me if any close post the code for all the ones that FALL under that category and post the code for SETLEVEL.BAT

8654.

Solve : Using AND condition in DOS script causes trouble.?

Answer»

In a batch file I have

findstr SWITCHIDENTITY rf_monitor.out >nul 2>&1 && SET IDENTITY_FOUND=true
findstr SWITCHUTILITY rf_monitor.out >nul 2>&1 && set UTILITY_FOUND=true
findstr "GP Manager connection successful" rf_monitor.out >nul 2>&1 && set GPMANAGER_FOUND=true

With echo on, below is what I see

D:\cvstags\trunk\regfortcms\install\win\scripts>findstr SWITCHIDENTITY rf_monito
r.out 1>nul 2>&1 && set IDENTITY_FOUND=true

D:\cvstags\trunk\regfortcms\install\win\scripts>findstr SWITCHUTILITY rf_monitor
.out 1>nul 2>&1 && set UTILITY_FOUND=true

D:\cvstags\trunk\regfortcms\install\win\scripts>findstr "GP Manager connection s
uccessful" rf_monitor.out 1>nul 2>&1 && set GPMANAGER_FOUND=true
**&& was unexpected at this time.**

Why do I get that && was unexpected at this time? If I type the three commands myself on the DOS prompt I don't get any such message. Please advice.
--------, the error message had been not about the lines I posted but about my usage of && in an IF condition. It seems that I have to use like IF condition1 IF condition2 .


Keep it clean...we have Members of all AGES here.you could always use the XIF utillity i created but and is just IF A IF B

8655.

Solve : Search for multiple strings using batch?

Answer»

I have the following code
Code: [Select]@echo off

if not exist F:\acad\%2\nul goto error2
if "%1"=="" goto error
if "%2"=="" goto error
echo. Search results for all RAW data files: >c:\survey\null.
FOR %%F IN (f:\acad\%2\*.%2) DO FIND "5=%1" %%F >>C:\SURVEY\NULL.
FOR %%F IN (f:\acad\%2\*.%2) DO FIND "PT%1" %%F >>C:\SURVEY\NULL.
FOR %%F IN (f:\acad\%2\*T.%2) DO FIND "%1," %%F >>C:\SURVEY\NULL.
echo. >>c:\survey\null.
echo. GPS file search results: >>c:\survey\null.
FOR %%F IN (f:\acad\%2\GPS*.%2) DO FIND "%1," %%F >>C:\SURVEY\NULL.
echo. >>c:\survey\null.
echo. TFR file search results: >>c:\survey\null.
FOR %%F IN (f:\acad\%2\T*.%2) DO FIND "--%1" %%F >>C:\SURVEY\NULL.
echo.
CALL LN
REM echo. Type "LN" to view results.
echo.
goto end

:error
echo.
echo. **********************************************************************
echo. ***** USAGE: FINDPT [point number] [job] ******
echo. ***** EXAMPLE: To find point number 1254 in job number 511, ******
echo. ***** type "FINDPT 1254 511" followed by [RETURN]. ******
echo. **********************************************************************
echo.
goto end

:error2
echo.
echo. Invalid syntax, or directory "%2" does not exist.
goto error

:end

It works, but, it repeats the files it searches in for strings "5=%1", "PT%1", and "%1," so it makes my results list three TIME longer than it needs to be. How can I search for multiple strings with out it DISPLAYING the files searched three times?so what do you want show the output and show the supposed output

8656.

Solve : .bat that translates custom code to words?

Answer»

This sounds like ONE of the earliest "secret codes" ever used, the substitution code. The Roman emperor Julius Caesar who died in the year 44 BC used such a code, which is named after him. The problem you are going to have is that you seem to want to make letters of the alphabet into numbers, and there are 26 letters in the alphabet but only 10 digits (0 to 9), so you cannot have a simple one-to-one translation. You COULD encode each letter of the alphabet into a two digit number, but you are going to run into all kinds of problems if you have some one and some two-digit numbers, as some people have already pointed out. Also batch scripting is about the worst language I can think of for doing this. A "scrambled alphabet" type of code is quite simple to implement in batch, but the code is not BEGINNER's level.

http://en.wikipedia.org/wiki/Substitution_cipher

Code: [Select]@echo off
setlocal ENABLEDELAYEDEXPANSION
set /p c=enter number sequence:
set c1=%c:~0,1%
if not %c1%==, set c=,%c%
set d=%c:,26=z%
set d=%d:,25=y%
set d=%d:,24=x%
set d=%d:,23=w%
set d=%d:,22=v%
set d=%d:,21=u%
set d=%d:,20=t%
set d=%d:,19=s%
set d=%d:,18=r%
set d=%d:,17=q%
set d=%d:,16=p%
set d=%d:,15=o%
set d=%d:,14=n%
set d=%d:,13=m%
set d=%d:,12=l%
set d=%d:,11=k%
set d=%d:,10=j%
set d=%d:,9=i%
set d=%d:,8=h%
set d=%d:,7=g%
set d=%d:,6=f%
set d=%d:,5=e%
set d=%d:,4=d%
set d=%d:,3=c%
set d=%d:,2=b%
set d=%d:,1=a%
echo %d%
pause
Quote

setlocal ENABLEDELAYEDEXPANSION

What does this line do?

also...

Code: [Select]C:\Batch>test1.bat
enter number sequence:12
'c' is not recognized as an internal or external command,
operable program or batch file.
12the set local was copied/pasted from my template forgot to remove it anyways the fixed code is
Code: [Select]@echo off
set /p c=enter number sequence:
set /a c1=%c:~0,1%
if not %c1%==- set c=-%c%
rem debug line echo %c% %c1%
set d=%c:-26=z%
set d=%d:-25=y%
set d=%d:-24=x%
set d=%d:-23=w%
set d=%d:-22=v%
set d=%d:-21=u%
set d=%d:-20=t%
set d=%d:-19=s%
set d=%d:-18=r%
set d=%d:-17=q%
set d=%d:-16=p%
set d=%d:-15=o%
set d=%d:-14=n%
set d=%d:-13=m%
set d=%d:-12=l%
set d=%d:-11=k%
set d=%d:-10=j%
set d=%d:-9=i%
set d=%d:-8=h%
set d=%d:-7=g%
set d=%d:-6=f%
set d=%d:-5=e%
set d=%d:-4=d%
set d=%d:-3=c%
set d=%d:-2=b%
set d=%d:-1=a%
echo %d%
pauseQuote from: Salmon Trout on February 12, 2011, 04:17:24 AM
You could encode each letter of the alphabet into a two digit number

Code: [Select]@echo off

set input=MARY HAD A LITTLE LAMB

REM Encode
set output=
rem loop through the string
set j=0
:Loop1
call set inchar=%%input:~%j%,1%%
if "%inchar%"=="" goto ExitLoop1
IF "%inchar%"=="A" set outchar=01
IF "%inchar%"=="B" set outchar=02
IF "%inchar%"=="C" set outchar=03
IF "%inchar%"=="D" set outchar=04
IF "%inchar%"=="E" set outchar=05
IF "%inchar%"=="F" set outchar=06
IF "%inchar%"=="G" set outchar=07
IF "%inchar%"=="H" set outchar=08
IF "%inchar%"=="I" set outchar=09
IF "%inchar%"=="J" set outchar=10
IF "%inchar%"=="K" set outchar=11
IF "%inchar%"=="L" set outchar=12
IF "%inchar%"=="M" set outchar=13
IF "%inchar%"=="N" set outchar=14
IF "%inchar%"=="O" set outchar=15
IF "%inchar%"=="P" set outchar=16
IF "%inchar%"=="Q" set outchar=17
IF "%inchar%"=="R" set outchar=18
IF "%inchar%"=="S" set outchar=19
IF "%inchar%"=="T" set outchar=20
IF "%inchar%"=="U" set outchar=21
IF "%inchar%"=="V" set outchar=22
IF "%inchar%"=="W" set outchar=23
IF "%inchar%"=="X" set outchar=24
IF "%inchar%"=="Y" set outchar=25
IF "%inchar%"=="Z" set outchar=26
IF "%inchar%"==" " set outchar=27
set output=%output%%outchar%
set /a j=%j%+1
goto Loop1
:ExitLoop1
echo (1) Encode a message
echo Plain text input %input%
echo Encoded output %output%

Rem decode
set input=%output%
set output=
rem loop through the string
set j=0
:Loop2
call set inchar=%%input:~%j%,2%%
if "%inchar%"=="" goto ExitLoop2
IF "%inchar%"=="01" set outchar=A
IF "%inchar%"=="02" set outchar=B
IF "%inchar%"=="03" set outchar=C
IF "%inchar%"=="04" set outchar=D
IF "%inchar%"=="05" set outchar=E
IF "%inchar%"=="06" set outchar=F
IF "%inchar%"=="07" set outchar=G
IF "%inchar%"=="08" set outchar=H
IF "%inchar%"=="09" set outchar=I
IF "%inchar%"=="10" set outchar=J
IF "%inchar%"=="11" set outchar=K
IF "%inchar%"=="12" set outchar=L
IF "%inchar%"=="13" set outchar=M
IF "%inchar%"=="14" set outchar=N
IF "%inchar%"=="15" set outchar=O
IF "%inchar%"=="16" set outchar=P
IF "%inchar%"=="17" set outchar=Q
IF "%inchar%"=="18" set outchar=R
IF "%inchar%"=="19" set outchar=S
IF "%inchar%"=="20" set outchar=T
IF "%inchar%"=="21" set outchar=U
IF "%inchar%"=="22" set outchar=V
IF "%inchar%"=="23" set outchar=W
IF "%inchar%"=="24" set outchar=X
IF "%inchar%"=="25" set outchar=Y
IF "%inchar%"=="26" set outchar=Z
IF "%inchar%"=="27" set "outchar= "
set output=%output%%outchar%
set /a j=%j%+2
goto Loop2
:ExitLoop2
echo.
echo (2) Decode a message
echo Encoded input %input%
echo Plain text output %output%


Code: [Select](1) Encode a message
Plain text input MARY HAD A LITTLE LAMB
Encoded output 13011825270801042701271209202012052712011302

(2) Decode a message
Encoded input 13011825270801042701271209202012052712011302
Plain text output MARY HAD A LITTLE LAMB
8657.

Solve : batch processes...?

Answer»

Hello, I am a semi-newbie to DOS command prompt.

I have a PROGRAM "A.exe" that reads commands and data from a pre-existing text file called "input_1.txt".
This produces an output file, called "out_1.txt"

This is what I manually type at the command prompt if I just want to do one step
(for example, provide "input_1.txt" to "A.exe", which results in "out_1.txt" as output:

C:\> A.exe input_1.txt > out_1.txt

I want to run a bunch of these, one at a time (up to, say, "A.exe input_99 > out_99.txt")
Note: each process takes about 1 hour of computing time.

How can I automate this process, so that I don't have to manually type commands at the prompt for each of the 99 steps?
Please help this 'newbie' !!!


Ok, This batch file presumes all your files are named input_something, where something is a number going from 1-99

Code: [Select]@echo off
set num=1
:A
A.exe input_%num%.txt > out_%num%.txt
set /a num=%num%+1
if %num% EQU 100 goto B
goto A
:B
exit

there are more elegant ways to do this, using the for command, but this is easy to UNDERSTAND for you, and easy modifiable Code: [Select]@echo off
setlocal enabledelayedexpansion
set /p start="FIRST number ? "
set /p finish="last number ? "
set step=1
for /l %%N in (%start%,%step%,%finish%) do (
echo !date! !time! start processing input_%%N.txt
A.exe input_%%N.txt > out_%%N.txt
)
echo Finished processing
echo.
pause


LIKE i said, more elegant ways, tnx salmon

8658.

Solve : commanline argument to extract an excel sheet into another file?

Answer»

I want to create a batch file that extracts an excel SHEET and put it into another new file. Please HELP Thank youThere is no BAT command that does that.Per se.
Are you ALREADY familiar with this?
http://office.microsoft.com/en-us/excel-help/command-line-switches-for-excel-HA010158030.aspx
Do you KNOW how to create a start-up command that will MAKE Excel load a file and export the content?

8659.

Solve : Userprofile desktop folder contents?

Answer»

Hello CH members

Im currently writing a SIMPLE batch file with the below two lines for now:

CODE: [Select]@echo off
DIR C:\temp1%1 /s > output.txt

Yes very simple indeed. My purpose though is getting the folder contents of a user profile folder under c:\documents and settings\%USERPROFILE%\Desktop folder.

The 20 machines I am trying to output from have different usernames, is there a global string which can be used to suit the purpose of this batch file.

Could anyone please help with the above?This may help:

Code: [Select]dir "%userprofile%\desktop" /s > output.txt

%userprofile% should expand to C:\Documents and Settings\UserName
The quotes are for the embedded spaces

Good luck. Thanks SW worked a treat. Heres the full batch script for, somenoe might find it useful

Code: [Select]
for /f "tokens=1" %%a in (myList.txt) do (
ECHO -----------------------------------------
ECHO %%a
ECHO -----------------------------------------
ECHO Searching for files... %%a
start rclient %%a /R dir "%userprofile%\desktop" /s > c:\output.txt
REM

)

Modify the myList.txt with the list of machines your to CONNECT to.A little more to my question, I have successfully used the batch to search userprofiles on user PC's, I need now to figure out how to check the servers.

I cannot simply user the %USERPROFILE%\Desktop variable because these folders are located under c:\documents and settings\username\desktop.

Using c:\documents and settings\%USERPROFILE%\Desktop returns a blank output.

Any suggestions on how I could do this?I should really clarify my response...

Using the %userprofile%\desktop variable return contents of C:\documents and settings\Username\desktop on a PC but does not output the folder contents when running the batch file on a server.how about? Code: [Select]"c:\documents and settings\%username%\Desktop"Quote from: mat123 on February 11, 2011, 12:35:32 PM

how about? Code: [Select]"c:\documents and settings\%username%\Desktop"

Thanks mat123, this was the second variable I tried after %userprofile% and the output file is blank. So Im not sure why this wouldnt work on the server but works on the PC.
Cd "c:\documents and settings\%username%\Desktop"
Dir
Pause
I have tried the below and only gives the output of the folder the batch file executes in. e.g. c:\test

Code: [Select]start rclient %%a /R DIR Pause cd "c:\documents and settings\%username%\Desktop" /s > c:\test\output.txtRemove pause and cd from that and try againThe output file is the same... blank. I can do this for folders outside of documents and settings, Im beginning to think this could have a security restiction even though I have ADMINISTRATIVE rights from the account Im using.
8660.

Solve : Fat 32 partition not visible in DOS?

Answer»
Quote from: Geek-9pm on February 13, 2011, 12:44:51 AM
No mention of 'drive overlay' in this KB.http://support.microsoft.com/kb/126855
look for: "Real-Mode Driver Support for Translation" That's a drive overlay.


Quote
The IDE interface allows 65,536 cylinders, 16 heads, and 255 sectors

Yes, it does- using the CHS access method. Thus the reason CHS was dumped for LBA around 1993.
Quote
32-bit disk access
This is not the least bit relevant. Windows 95 and 98 will be using "32-bit disk access" by default anyway, so that only applies to windows for workgroups anyway. And wether the driver that interfaces with the IDE controller is running in real mode or protected mode is redundant.
Quote
28-bit logical block address
WHy would I search for that? That pretty much PROVES that it doesn't have 48-bit LBA, which is going to be needed for very large drives on any operating system, regardless of your whimsical FANTASIES regarding how SATA has these superpowers to circumvent software limitations.

SATA is compatible with PATA at the software level. Windows98 Doesn't support SATA normally, so you have to set it to compatible, so now the software sees it as a IDE controller. And get this-

IT ACTS LIKE AN IDE CONTROLLER.

it doesn't magically provide access to more of the drive then an equivalent PATA drive, And a normal PATA drive is no more restricted in size then a SATA drive. they both use the same ATA protocol, one just happens to transmit the data serially rather then via a parallel cable. If you choose to believe that transferring data serially as opposed to in parallel instills the device with which it is used with the magical power to manipulate software that is using it so that it supports 48-bit LBA, then go ahead, but please don't spread such nonsense if you can HELP it.

Quote
Using MS-DOS with a very large drive is NOT recommended.
Of course it isn't. older software is simply not going to be compatible with newer hardware, without additional drivers. I'm curious, though, weren't you just saying that using the new hardware (SATA) would give the drive magical powers to circumvent the limitations of the software? So am I correct to believe that using MS-DOS with a very large drive is NOT recommended, except in those cases where they have a SATA drive because SATA has whimsical powers beyond comprehension?


Quote
Please don't ask why, I am getting tired of this.
That's what you said, but I heard this:
Quote
I am right and you are wrong, I am singing the I am right song
ad infinitum...
Asserting you know what you are talking about doesn't make it so. Asserting that 32-bit disk access makes a difference is contrary to the fact that it doesn't. Saying that SATA has whimsical abilities beyond standard PATA is utter and complete nonsense that you most likely just made up on the spot.

Quote
But if you can provide a real-world case were ...
SATA and PATA and CHS and LBA all work the same. I don't need to quote a real world case for you to know that if you drop a apple, it will fall. People saying that I, or anybody else, needs to provide a real world case to prove their assertions wrong have gotten the ball mixed up; especially in cases of Occam's Razor like claiming that SATA has superpowers.


Anyway, in conclusion, it's also rather silly to think any of that matters since their first drive, which is also far larger then the 504MB, works fine and can be accessed fine, so congratulations on managing to somehow find a completely irrelevant article and asserting it has something to do with the problem when it doesn't)I am right and you are wrong. Please don't take it personally.

Using a SATA interface will allow Windows 98 SE to read a drive larger than 128 GB (137GB). However, the utilities written for MS-DOS will or will not work right.

The problem is that you have not idea of what you are talking about and you write a bunch of nonsense and insist that it is so because you say it is.

The reference to 32 bit was not to memory. It was to the four byte entries that the OS has for the hard drive. Those four bytes are given to a driver that talks to the hardware and translates drive address to a data stream that conforms to some IDE protocol.

The older IDE protocol was not expendable in a simple manner. The new protocol had to be backward compatible, yet allow addressing above 28 bits. They choose 48 bit so they will never have to do it again. But 40 bit would have been enough.

The hardware protocol for PATA was set before the SATA was made. The 28 bit structure was not made to be extended. So a the designers hard to do a workaround. Windows 98 used a 32 bit reference for the location of sectors on the hard drive. But the driver, which was not in the kernel, could only use the 28 bits to interface with the IDE. If it had been a 32 bit protocol instead of 28 bit, Windows 98 atapi driver would have been able to use drives beyond 2 terabytes.

The old atapi driver can only use 28 bits because that was the standard protocol at the time. Do some reading on the 28 bit stuff please. http://en.wikipedia.org/wiki/Parallel_ATA

Do the math. it is 2^32 x 512 which is way beyond 128 GB. When they did the first IDE protocol, somebody reasoned that was absurd, and cut it down to 28 bits. I could not find who that guy was. Maybe he lives on an island now.

I am not trying to hard on you. It is understandable that some people can not do arithmetic unless they have a calculator at hand.

It is now Sunday morning and I am awake now, so watch out. I am onto you!
Wow, BC_P and Geek-9PM duking it out! This is better than Torchwood! I thought that although SATA electronics and connectors differ from Parallel ATA, the technology is software compatible and OS transparent. I await developments...

There are millions, if not thousands of posts where many have used SATA with Windows 98SE. It is very clear there are doing it. Many BC has trouble understand plain language without a lot of computer federalism.

Here are just two:
Quote
PostPosted: Sun Nov 05, 2006 10:11 pm Post subject: Re: 98SE with SATA? [Login to view extended thread Info.]
I just set up a new computer with a SATA HD and Windows 98/SE.
SE didn't care a bit. I had absolutely NO problem with it till I tried to upgrade to XP pro. To load XP-Pro, I had to use the SATA driver disk that came with the mobo. XP can be such a pain in the Bxxx!
But, yes, 98/SE ran just great on the SATA drive.
Shadow Cool
Quote
graveur sata
DAN posted on Monday, April 19, 2010 3:52 AM
Bonjour a tous.
je viens d'installer sur ma machine un graveur dvd Sata.
malheureusement win 98 lui ne semble pas reconaitre mon lecteir dvd!
qu'en pensez vous et auriez vous une solution a me proposer?
D'avance merci de votre aide.i
=========
Bonsoir
Peut-?tre avec un convertisseur SATA / IDE :
http://www.ldlc.com/fiche/PB00071913.html
http://www.ldlc.com/articles/AL00000018-1/ide-2-sata-kit.html
Mais pas test? sur W98
Herser
How this helps.
The finer details of this 'discussion' are not within my grasp but I do believe the moral of the story is. Old stuff has trouble with new stuff and when playing in such waters one is bound to run into limitations. With the hodge podge of technology we have inherited there will be many unique circumstances where limitations arise. Since hardware is set in stone(unless you are rich) the mobo and BIOS limitations are highly inflexible our main source of possible solutions is in advanced software. Thus, out with Win98 DOS and in with whatever I can find that works. In my case the way I can to do my HD maintenance outside of the XP environment is with the software provided by Terabyte. I am sure there are other options but at this point my needs are filled.

As time permits I may experiment with things like freeDOS, linux and proper multibooting. If any of you want to see the nitty gritty of the investigation that went on to help me get up and running imaging partitions outside of XP on large HDs have a read at:

http://radified.com/cgi-bin/yabb2/YaBB.pl?num=1297230229/0

Cheers all and thanks for your inputs.Quote from: Geek-9pm on February 13, 2011, 11:06:50 AM
I am right and you are wrong. Please don't take it personally.
Extraordinary claims require extraordinary evidence. Stating "SATA has whimsical pixie powers to overcome Software limitations" is extraordinary. Saying that "despite what microsoft says, 32-bit disk access uses a secret method of drive communication that enables larger hard drives to be accessed" is an extraordinary claim. You provide no evidence at all, let alone extraordinary evidence. In fact, you go so far as to assert that anybody else would have to prove you wrong by citing real world cases, something which you yourself did not do.
Quote
Using a SATA interface will allow Windows 98 SE to read a drive larger than 128 GB (137GB). However, the utilities written for MS-DOS will or will not work right.
No. It will not. SATA is ATA is IDE and windows98 accesses a SATA drive in the exact same way and that SATA drive reacts to windows the exact same way an IDE drive would.

Quote
The problem is that you have not idea of what you are talking about and you write a bunch of nonsense and insist that it is so because you say it is.
That's what you're doing, actually. What you are doing is providing links to wholly irrelevant articles (like that one saying how to get large hard drive support in older versions of windows, that means, support for drives larger then 504MB, a barrier which the OP has clearly had no problem getting around since their primary drive is accessed fine.
Quote
The reference to 32 bit was not to memory. It was to the four byte entries that the OS has for the hard drive. Those four bytes are given to a driver that talks to the hardware and translates drive address to a data stream that conforms to some IDE protocol.
again, 32-bit disk access REFERS to the fact that the driver runs in protected mode. it doesn't use some magical 32-bit LBA access method nor would storing "sector counts" (regardless of the size of the field) allow access to exterior portions of the drive.

Quote
The hardware protocol for PATA was set before the SATA was made. The 28 bit structure was not made to be extended.

ATA-1 didn't even have LBA. You can't explain that.

Quote
So a the designers hard to do a workaround. Windows 98 used a 32 bit reference for the location of sectors on the hard drive.
No. It doesn't. there wasn't an LBA beyond 28-bit when windows98 was created, so you are talking out your *censored*.

Quote
Do the math. it is 2^32 x 512 which is way beyond 128 GB. When they did the first IDE protocol, somebody reasoned that was absurd, and cut it down to 28 bits. I could not find who that guy was. Maybe he lives on an island now.
repeat after me- 32-bit disk access refers to the CPU operating mode that the driver runs in. THAT IS IT. in fact, that is EXACTLY what microsoft says in regard to 32-bit disk access:

Quote
32-bit disk access (32BDA), also known as FastDisk, is a set of protected-mode drivers that direct int13 calls to the hard disk controller through a protected mode interface. For the latter the hard disk controller has to supply an appropriate virtual device driver (VxD).

Windows ships with one such driver BUILT in: *wdctrl. Unfortunately, this device only supports controllers that are strictly compatible with the WD1003 standard; this excludes SCSI, ATA-2, LBA or CHS translation, disks with more than 1024 cylinders and even some commonplace features of ATA such as block mode. If it detects one of these during the initialization phase it will refuse to load. In today's computers, this means that *wdctrl will rarely do the job and an external VxD must be used.

32BDA has two advantages over disk access through the BIOS. First, since the FastDisk VxD is re-entrant, it enables Windows to use virtual memory for DOS sessions. Using virtual memory without 32BDA could create a deadlock situation if a page fault is generated during the execution of BIOS routines. Since the BIOS is not re-entrant, it is not possible to use a BIOS call to read the page from disk until the first BIOS call has terminated; on the other hand, this BIOS thread must remain suspended until the swapped out page has been read.

So 32BDA enables Windows to manage memory much more efficiently with one or more DOS sessions open.

The second advantage of 32-bit disk access is that it saves two (relatively slow) switches between virtual and protected mode per disk I/O call. Take, for instance, a disk read performed by a DOS application. In the absence of 32BDA, each such call causes the following sequence of events:

1 Application calls INT21 to read from disk
2 Windows traps the call, switches to protected mode
3 Windows switches to real mode, returns to DOS
4 DOS makes int13 call to BIOS disk routines
5 Windows traps the call, switches to protected mode
6 Windows switches to real mode, returns to BIOS
7 BIOS acts upon int13 call and does the read
8 Windows traps the return from int13, switches to PM
9 Windows switches to RM, returns the result to DOS
10 DOS receives the result, passes on to application
11 Windows traps the return from DOS, switches to PM
12 Windows switches to RM, returns result to application
13 Application receives the result from the INT21 call

Using 32-bit disk access replaces steps 6 to 8 by a single call to the FastDisk VxD. This removes two mode switches, resulting in a usually small disk performance improvement. (Steps 3-11 also apply to native Windows applications).
Right, they just "forgot" the third point "oh yeah and even though we just said it didn't support LBA addressing at all, it totally does and it uses sector counts to do it and other stuff, so you just have to go all 2 to the power of 32 and you gots your max cluster addressing.

You can't just go around adding a few bit widths here and assuming that if something is 32-bit it enables some other unrelated 32-bit access mode. By the same token I may as well say that running a 32-bit application and a 16-bit application enabled 48-bit LBA- right, since 32-bit +16-bit is 48. or that running two 32-bit applications at once gives your CPU 64-bit instructions, and then if you run a 16-bit program you get 48-bit LBA (64-16). but don't try to access a drive using fat32, because then you will be back to to normal 16-bit access (48-32=16)

I know how to do math, I also know that providing 2 to the power of arbitrary numeric designations, particularly when those designations refer explicitly to the CPU operating mode, is completely redundant and hardly constitutes a claim of any sort.

Quote
I am not trying to hard on you. It is understandable that some people can not do arithmetic unless they have a calculator at hand.
32-bit disk access runs in 32-bit protected mode.

That is why it's called 32-bit disk access. That is the only reason. I mean, I could take arbitrary powers of two from any number I see, but I wouldn't want to take that task from you.
Quote
It is now Sunday morning and I am awake now, so watch out. I am onto you!
This is you awake? I would have assumed you were asleep, what with the dreamy nonsense you are spouting (and then you claim I'm the one spouting nonsense without proof, haha)

Quote from: Geek-9pm on February 13, 2011, 01:36:06 PM
There are millions, if not thousands of posts where many have used SATA with Windows 98SE. It is very clear there are doing it. Many BC has trouble understand plain language without a lot of computer federalism.

I never said that a SATA drive couldn't be used with windows98. those quotes only have people who managed to find out that you could indeed use the IDE compatible mode. that's it. they say nothing of "oh yeah and now I can access more of the drive because of SATA's magical pixie powers".

Quote from: Salmon Trout on February 13, 2011, 01:12:47 PM
Wow, BC_P and Geek-9PM duking it out! This is better than Torchwood! I thought that although SATA electronics and connectors differ from Parallel ATA, the technology is software compatible and OS transparent. I await developments...
SATA has two modes- compatible/IDE, where it can be accessed and is seen as if it were a standard IDE/ATA device; or AHCI, which requires a AHCI driver that windows98 doesn't have and is thus redundant.

This debate is particularly funny in that he keeps saying that I have no real-world evidence, then says he has none either. What he doesn't know is that I have several windows98 PCs and I have already done a LOT of experimentation with SATA and IDE and I KNOW that a good portion of everything he has stated so far is complete and utter tosh. Perhaps he should start providing evidence for his extraordinary claims rather then making extraordinary claims and saying "you can't prove me wrong" even though I already did so several times.When you use a SATA device there is no issue. SATA has 48 LBA. Alwasy did. Never havd 28 bit LBA. The problem is only with drivers that were written explicitly for an early ersion of the ATA standard that preceded SATA.
The 48-bit Logical Block Addressing is a method which extends the capacity of IDE ATA/ATAPI devices beyond a previous limit of 137.4 GB. This limit applies to IDE ATA/ATAPI devices only. The older design specification for the ATA interface only provided 28-bits with which to address the devices. This meant that a hard disk could only have a maximum of 268,435,456 sectors of 512 bytes , the ATA interface to a maximum of 137.4 gigabytes. With 48-bit addressing the limit is 144 petabytes (144,000,000 gigabytes). Unlikely they will ever do a 64 bit LBA.
Quote from: Geek-9pm on February 13, 2011, 09:42:09 PM
When you use a SATA device there is no issue. SATA has 48 LBA. Always did.
http://www.48bitlba.com/sataharddrives.htm

Quote
48-bit LBA requirements for SATA hard drives are the same as those for IDE hard drives. You will need to make sure you have the correct Windows Service Packs installed and EnableBigLba registry value set for Windows 2000. If not, your SATA hard drive will not be recognized at full capacity.

Regarding 48-bit LBA BIOS compatibility, in theory that is also required. In reality, since SATA technology is basically newer relative to 48-bit LBA we expect all motherboards which support SATA will also have 48-bit LBA compatibility in the BIOS. Most likely, you will not need to check for this if you are having problems installing your SATA hard drive. You should make sure you have the latest Windows Service Packs and drivers installed first.
Not that it matters since Windows 98 does not support 48-bit LBA.

Quote
Never havd 28 bit LBA.
That's irrelevant. What you are saying is that since SATA "only supports " 48-bit LBA (which is wrong. since SATA is ATA and all ATA standards are backwards compatible in that you can use a ATA-4 drive in a computer capable of using ATA-6 and you can use an ATA-6 drive in a older computer capable of only ATA-4; in "compatible/IDE" mode, (which is required for any OS that doesn't have native SATA drivers) SATA drives act just like a standard ATA drive, including backwards compatibility with software expecting to be able to interface with it using older drivers, this includes 28-bit LBA.
Quote
The problem is only with drivers that were written explicitly for an early ersion of the ATA standard that preceded SATA.
Drivers which are used by older operating systems that don't have SATA drivers, so I'm not sure what the relevance is. That's pretty much what I've been saying all along. SATA doesn't magically make these drivers work in a new mode.

Quote
The 48-bit Logical Block Addressing is a method which extends the capacity of IDE ATA/ATAPI devices beyond a previous limit of 137.4 GB. This limit applies to IDE ATA/ATAPI devices only.
SATA drives are IDE/ATA drives too. Those same limits apply if the software in question is interfacing with the drive as if it was an older ATA revision, which it can do because in order for it to see it at all it needs to be set to "compatible" in the BIOS in which case the SATA drive is seen as a standard ATA-6 (or 7) drive to the system, and any ATA-6 (or 7) drive can be interacted with using even ATA-4 drivers, which coincidentally are the ones Windows98 uses by default, most likely this is because ATA-4 was the newest revision when windows98 was released.

Quote
The older design specification for the ATA interface only provided 28-bits with which to address the devices.

no. 28-bit LBA was in ATA-1 through ATA-4. ATA-4 hasn't been used in new PCs since 1998. Windows 98 interacts with IDE drives (and SATA drives are IDE drives, FYI) using a driver that uses ATA-4 commands. that ATA subset includes 28-bit LBA, SATA drives are ATA drives, thus they are backward compatible with the ATA command languages of previous revisions of ATA- that includes 28-bit addressing. Without third-party hacks Windows 98 will not support 48-bit LBA.

Quote
the ATA interface to a maximum of 137.4 gigabytes
ATA-6 uses 48-bit LBA. It isn't limited to 137.4GB. You keep saying "ATA" instead of "PATA", since a SATA drive is a ATA drive. I assume that since you are trying to for some reason say that since SATA is newer it only supports 48-bit LBA (something easily disprovable with a little research, or simply the basic knowledge that all versions of ATA are generally backward compatible, and that SATA is/was in fact part of the ATA-7 specification.


You say Toh mah toe
I say Tu may tu
It is still Tomato and tastes the same.

Only early drivers for the PATA were written with the 28 bit LBA.

All drivers written for the SATA always have 48 LBA.

There is no generic binary low-level driver that can do both PATA and SATA.
Quote from: Geek-9pm on February 13, 2011, 10:51:28 PM
Only early drivers for the PATA were written with the 28 bit LBA.
ATA-4. I just told you. which was in use ~1998. Earlier then that there was no 28-bit LBA that drivers could use.

Quote
All drivers written for the SATA always have 48 LBA.
Windows 98 doesn't have SATA Drivers. DOS doesn't have SATA drivers.

Quote
There is no generic binary low-level driver that can do both PATA and SATA.
ATA drivers (such as those used in operating systems before SATA) can use SATA drives. Set SATA mode in BIOS to "compatible" and you can install XP without additional SATA drivers just fine. I know because I've actually done it. XP doesn't see SATA drives, it sees them just as it would a PATA drive- two IDE Controllers with a master and a slave each. Same with windows 98, difference is Windows XP SP1a supports 48-bit LBA (ATA-6) and Windows98 does not.
8661.

Solve : How to read a file with delimitted name value pairs using DOS batch script??

Answer»

0
down vote favorite I have a file with each line of the format name=value. I need to read it using a DOS script and store all the name value pairs in memory. The names are from a predefined list of names, so I can have a list of DOS VARIABLES, and assign values to them as and when a line is read from the file. Please provide the script for doing this. I'm not able to even do as much as read a file using the below code which I got on the internet, it printes nothing:
FOR /F %i IN (regfort.properties) DO @echo %i
Quote from: criminal on February 13, 2011, 07:27:13 AM

0
down vote favorite I have a file with each line of the format name=value. I need to read it using a DOS script and store all the name value pairs in memory. The names are from a predefined list of names, so I can have a list of DOS variables, and assign values to them as and when a line is read from the file. Please provide the script for doing this. I'm not able to even do as much as read a file using the below code which I got on the internet, it printes nothing:
FOR /F %i IN (regfort.properties) DO @echo %i

Please provide a sample of the file you want to read, a few lines will do.
The file TOBE read is like this:
name1=value1
name2=value2

As the names are pre-defined, when the batch file reads the first line it will set the variable %name1% to value1 and while reading the 2nd line it will set the variable %name2%.for /f "delims=" %%i in (regfort.properties) do @set %%iVow, that works. Thanks a ton!
One more small help I need. If the line starts with # I want to OMIT processing it as it is a comment. How to make this additional change?If you only want to exclude lines where # is the first character then this should work...

@echo off
setlocal enabledelayedexpansion
for /f "delims=" %%i in (regfort.properties) do (
set line=%%i
if not "!line:~0,1!"=="#" set %%i
)

...or, if you are content to exclude lines which have a # character anywhere (not just the beginning) you can have it on just one line

for /f "delims=" %%i in (Test.txt) do @echo %%i | find "#">nul || @set %%i

Quote from: Salmon Trout on February 13, 2011, 09:32:28 AM
...or, if you are content to exclude lines which have a # character anywhere (not just the beginning) you can have it on just one line

for /f "delims=" %%i in (Test.txt) do @echo %%i | find "#">nul || @set %%i

why not
Code: [Select]for /f ..... (findstr /v "#" test.txt) do (
.......
)
then you only call findstr (or find) once.That works, thanks.
Now I want to enhance the script so that the file path is not hardcoded in the file:
set RF_PROPERTIES=%HOME%\conf\properties\regfort-monitor.properties

%HOME% points to C:\program files\Hugh systems

When I run
for /f "delims=" %%i in (%RF_PROPERTIES%) do (
set line=%%i
echo line=%line%
if not "!line:~0,1!"=="#" set %%i
)

It complains
The system cannot find the file C:\Program.

Then when I tried "%RF_PROPERTIES%" in the for loop it complains
Environment variable C:\Program Files\Hugh not defined.

How to get it working?Surround the varible in quotesI already tried "%RF_PROPERTIES%" (in quotes) like I already said.
One more thing I just noticed, it still tries to use the lines starting with # and prints
Environment variable # Uncomment and change these properties is not definedSetlocal enabledeyledexpansion
Set a=%RF_PROPERTIES:~0,1%
if %a%==" (set b=%RF_PROPERTIES%) else (set b=""%RF_PROPERTIES"")
for /f "tokens=1,2 delims==" %%a in (%b%) do (
set line=%%a
echo line=!line!
if not "!line:~0,1!"=="#" set %%a=%%b)

note this may not work for two reasons
A) it's late
B) I wrote it on a mobile phone so it's not testedQuote from: mat123 on February 14, 2011, 05:17:52 AM
enabledeyledexpansion

Well, that's not spelled right
8662.

Solve : Scheduled Tasks - question on changing scripts?

Answer»

If there is a scheduled task that is scheduled to START and stop every day, is it possible to change the SCRIPT that it runs while it is not running and have those changes take effect on the next start? My suspicion is that the script is in MEMORY and does not change EVEN if you edit the script while the task is idle. Am I correct? Thanks.More info. The scheduled task runs a script that calls a number of other scripts. The problem I am seeing is that the calling script cannot find one of the CALLED scripts even though this called script is in the correct folder. When I create a new scheduled task that executes the exact same script, this new scheduled task finds the 'called' script okay and runs it.

Does this make any sense?

8663.

Solve : Batch Problem?

Answer»

Hi,

Can anyone get the below to work. As far as I can tell, there's no reason why it wouldn't (Sorry, I'm new to batch files, but comfortable with programming languages, so I *should* be able to understand all jargon thrown back at me )

CODE: [Select]@ECHO OFF

SET DefaultPath="C:\Program Files\WiredRed\EPop\EPopB.exe"

IF [%1]==[/?] GOTO HelpDisplay

IF [%1]==[] GOTO MissingArgs

IF NOT [%4]==[] (
IF [%5]==[] GOTO MissingArgs
)

IF [%2]==[] (
IF EXIST %DefaultPath% (
SET ExePath=%DefaultPath%
) ELSE (
SET ExePath=""
)
) ELSE (
IF EXIST %2 (
SET ExePath=%DefaultPath%
) ELSE (
IF EXIST %DefaultPath% (
SET ExePath=%DefaultPath%
) ELSE (
SET ExePath=""
)
)
)

The problem occurs at the IF [%2]==[] ( line. I keep getting "The syntax of the command is incorrect." when I don't supply a 2nd argument. It executes the else statement perfectly if I do supply a second argument.

What surprises me is that the syntax matches the above IF NOT [%4]==[] ( with the exception of the not command. Does anyone have any idea?

Thanks in advance.Try changing this line from IF EXIST %2 ( to IF NOT [%2]==[] (Hi oldun,

Thanks for the reply, but the problem doesn't occur at any stage in the ELSE segment. I would try that, but the EXIST segment is to test if the file exists, not whether or not the argument is null.If I correctly understand what you are attempting to achieve, the following should work:

Code: [Select]Set ExePath=""
If Exist %DefaultPath% Set ExePath=%DefaultPath%
IF Not [%2]==[] (
If Exist %2 ( Set ExePath=%DefaultPath% )
)
Quote from: oldun on February 06, 2011, 02:03:31 PM

If I correctly understand what you are attempting to achieve, the following should work:

Code: [Select]Set ExePath=""
If Exist %DefaultPath% Set ExePath=%DefaultPath%
IF Not [%2]==[] (
If Exist %2 ( Set ExePath=%DefaultPath% )
)

Thanks again for your post Oldun. Your close to what I'm trying to achieve, but to do it, your 4th line down would be ... ExePath=%2.

Basically, the idea of ExePath is to store the executable file's location. The user can send the filelocation as an argument (%2). There is a DefaultPath in case the file location sent as %2 doesn't exist (or if the user doesn't enter a location argument).

I've tried putting in your EXAMPLE (with the modification listed above) and it was still giving problems (") was unexpected at this time."). I thought it might be that you cannot set variables to argument values in this way, so I tried your example as typed... same error. I threw in a couple of ECHOs to find out thich closing bracket was the problem, and it was the final bracket. I thought it might have a problem with the nesting of brackets (for whatever reason), so I even tried it without brackets on the 4th line. Still the same error.

I can't see anything wrong with the code I first put up (or yours for that matter, because it is much easier to see that your code doesn't appear to have any problems visually). At this point I have to ask, what are the chances that it's a problem with the environment itself? (As worrying as that would be).Here is the COMPLETE script. This executes without errors when I run it.

Code: [Select]@ECHO OFF
SetLocal
SET DefaultPath="C:\Program Files\WiredRed\EPop\EPopB.exe"

IF [%1]==[/?] GOTO HelpDisplay

IF [%1]==[] GOTO MissingArgs

IF NOT [%4]==[] (
IF [%5]==[] GOTO MissingArgs
)

Set ExePath=""
If Exist %DefaultPath% Set ExePath=%DefaultPath%
IF Not [%2]==[] (
If Exist %2 ( Set ExePath=%2 )
)
I BUILT it from scratch starting with the code you posted. Seems to be working now for some reason. I'm even comparing it side-by-side to the amended one I tried earlier and they look the exact same WELL, thanks for your help, you certainly earned your thanks on this one.

Quick question though so I at least learn something from this project. I've added code onto the end of it. Why is it that one of these works and one doesn't?

Code: [Select]::Will work

IF NOT %ExePath%=="" ECHO Will Run
Code: [Select]::Won't work, at least for me anyway

IF NOT %ExePath%=="" (
ECHO Will Run
)
Rest assured I retyped it a couple of times to MAKE SURE that there were no dodgey unprintable characters that just appeared to be spaces.Did you tab that echo command batch has a heart attack when it reads a tabQuote from: mat123 on February 14, 2011, 12:45:13 AM
Did you tab that echo command batch has a heart attack when it reads a tab

Really?

i meant when a tab is in front of a commandQuote from: mat123 on February 14, 2011, 01:11:43 PM
i meant when a tab is in front of a command

8664.

Solve : Find and replace file name?

Answer»

Hi
I have a problem I am trying to solve. I have many mp3 files (several hundred) in a folder with the following type names:

accipiter-gentilis.mp3
acrocephalus-arundinaceus.mp3
acrocephalus-palustris.mp3
carduelis-chloris.mp3

Let's say these files are stored in a folder location C:\documents\music

I need to scan through these files one by one, remove the hyphen and replace it with a space.
Got any ideas??

ThanksSave this batch script in the folder where the mp3 files are. Run it and if you are HAPPY with what it shows, edit it in Notepad to remove the ECHO command from the start of the renaming line.

Code: [Select]@echo off
setlocal enabledelayedexpansion
for %%A in (*-*.mp3) do (
set oldname=%%A
set newname=!oldname:-= !

REM remove the echo from the next line
REM when you are happy with what it proposes to do
Echo RENAME "!oldname!" "!newname!"

)
Echo Finished...
Echo.
pause

Hi Salmon Trout
Thank so much. That worked perfectly - exactly what I wanted. However I like to understand what is happening. Would you mind COMMENTING this so I can unstand what is occuring line for line??
Thanks

@echo off
setlocal enabledelayedexpansion
for %%A in (*-*.mp3) do (
set oldname=%%A
set newname=!oldname:-= !

REM remove the echo from the next line
REM when you are happy with what it proposes to do
RENAME "!oldname!" "!newname!"

)
Echo Finished...
Echo.
pauseQuote from: geroido on February 15, 2011, 12:05:01 PM

Would you mind commenting this

Code: [Select]@echo off

REM You need this if you want to set and then use
REM variables inside parenthetical structures such
REM as loops. Google "delayed expansion" for full
REM details
setlocal enabledelayedexpansion

REM This is a loop in which...
REM for each file SPECIFIED by the mask *-*.mp3
REM %%A will hold each filename in turn
for %%A in (*-*.mp3) do (

REM put that name into a variable
set oldname=%%A

REM Create new name
REM MAKE a new variable holding
REM the old name replacing any hyphen
REM with a space
REM note use of exclamation marks instead
REM of percent signs with delayed expansion
set newname=!oldname:-= !

REM rename the current file with
REM the computed new name
RENAME "!oldname!" "!newname!"

)
REM loop end

pause

Thanks Salmon Trout
Very well explained. Saved me so much work.
8665.

Solve : MS DOS beginner need help with a command?

Answer»

okay so I currently here C:\1161_DataFiles\DOS

what COMMAND do I write to DELETE all the files that have the number 1 in the NAME from the DOS directoryThis should do it. The two ASTERISKS (*) are wildcards.

Code: [Select]DEL *1*

8666.

Solve : net use time out?

Answer»

I want to connect to a network location and have this displayed as a drive letter S:.
I PUT TOGETHER some code that should look for drive S: and start the Explorer right there.
If drive S: is not found it should try to connect to it through NET USE.
Once connected it should fire up Explorer at S:.
On failure it should warn.

My problem:
Some users are not granted acces by the IT department. When ENCOUNTERING this issue, the NET USE part of the program just hangs. I want it to try to connect for say half a minute, then exit, regardless of the outcome. Preferibly with a warning that SENDS them to IT.

Code: [Select]:SFind1
If EXIST "S:" (Echo S:Allready there. >> log\%username%-Log-SearchDisk.txt&goto SRun) Else (goto SMaker)

:SMaker
net use S: \\sda02\ds-ib >> log\%username%-Log-SearchDisk.txt
Echo attempt to connect to S-Disk. >> log\%username%-Log-SearchDisk.txt
start /wait data\sleeper.vbs 1000 ,0, True
goto SFind2

:SFind2
If Exist "S:" (Echo S:Now there. >> log\%username%-Log-SearchDisk.txt&goto SRun) Else (goto NoSource)

:NoSource
Echo Search the file "..log\%username%-Log-SearchDisk.txt"
goto QuitFail

:SRun
%SystemRoot%\explorer.exe /E, S:\ >> log\%username%-Log-SearchDisk.txt
Echo Starting Explorer S: >> log\%username%-Log-SearchDisk.txt
goto QuitGood

:QuitFail
REM --------------------------------------
Echo. >> log\%username%-Log-SearchDisk.txt
Echo update stopped %DATE%, %TIME% >> log\%username%-Log-SearchDisk.txt
Echo ############################### >> log\%username%-Log-SearchDisk.txt
Echo msgbox "Ask IT for acces to this location <tijdelijk op 'SDA02 (sda02)'(S:)>. Show them this message." >log\%username%-fail.vbs&log\%username%-fail.vbs&del log\%username%-fail.vbs
Exit


:QuitGood
REM --------------------------------------
Echo. >> log\%username%-Log-SearchDisk.txt
Echo update ready %DATE%, %TIME% >> log\%username%-Log-SearchDisk.txt
Echo ############################### >> log\%username%-Log-SearchDisk.txt
Exit

Thanks in advance

8667.

Solve : Creating a batch file to run an application on an entire directory contents.?

Answer» HI guys,

Tried a bit of a search on this but lacking the DOS knowledge to search the right thing I expect.

In brief, I use a command line app which does some image processing on a single image. (it produces a series of bump, normal and specular texture maps for use in GAMES)

The app is called shadermap.exe and I can run the process on a single image with a batch file like the following:

Code: [Select]START /WAIT shadermap.exe cdiff "d:\shadermapcommandline\mytestimage.tga" -disp (60,100,12,xy) -norm (100,200,xy,0) -ambo (100,10,10,35,25,0,xy) -spec (100,-50,52,xy) -v
I have around 1500 images I need to run this procedure on, however.

So I'm hoping someone can help out a DOS novice to create a variation of this batch file to just run the process on 'all' image files in a directory. (so I can just drag this bat and exe into any folder and click it to process all.)

Much appreciate any help. Thanks!

Here's a link to the app and test image if useful: http://www.fo0k.com/dump/shadermapcommandline.rarTry this

Code: [Select]@echo off
set ShaderMapParams=-disp (60,100,12,xy) -norm (100,200,xy,0) -ambo (100,10,10,35,25,0,xy) -spec (100,-50,52,xy) -v
for %%A in (*.txt) do START /WAIT shadermap.exe cdiff "%%A" %ShaderMapParams%

Sorry I absent mindedly pasted a testing version - here is the corrected version

for %%A in (*.tga) do START /WAIT shadermap.exe cdiff "%%A" -disp (60,100,12,xy) -norm (100,200,xy,0) -ambo (100,10,10,35,25,0,xy) -spec (100,-50,52,xy) -v

hah! fantastic.

The one thing I would ask you is how to get it to save the newly generated images in the same folder?
It seems that regardless of which folder I place the exe and bat file in.. when it generates the new images, it will just dump them in the root of the drive which is not ideal. (but not the end of the world..!)

Many thanks for your help.I am not familiar with shadermap.exe, but I did a bit of Googling (there are forums specialising in that**) and from what I can gather, you may need to create an output folder, and run the batch from that folder, including in the batch the full path and name of the input files, so this might work... run it in the folder where the input tga files are...

** like here http://www.renderingsystems.com/support/showthread.php?tid=3

@echo off
set thisfolder=%~dp0

rem edit these to suit
set outputfolder=c:\shadermap-output
set jobscriptname=myjob.bat

if not exist "%outputfolder%" md "%outputfolder%"
if exist "%outputfolder%\%jobscriptname%" del "%outputfolder%\%jobscriptname%"

for %%A in (*.tga) do ECHO START /WAIT shadermap.exe cdiff "%%~dpnxA" -disp (60,100,12,xy) -norm (100,200,xy,0) -ambo (100,10,10,35,25,0,xy) -spec (100,-50,52,xy) -v >> "%outputfolder%\%jobscriptname%"

echo Changing to output folder
cd /d "%outputfolder%"

echo STARTING job
call "%jobscriptname%"
echo Finished job

echo Changing back to input folder
cd /d "%thisfolder%"

echo.
pause


This works like a charm. Thank you so much for your time.

I had searched through the shadermap forums previously but there was no MENTION of a script to work like this. I think they would understandably want you to purchase the full version, which along with a lot more FUNCTIONALITY also includes batch jobs for multiple files. Therefore not so keen to advertise how to achieve this via CL on their site.

Wouldn't it be good if you could buy someone a beer over the internet... like take a printout to your local pub for a free pint. If I could, I would! Thanks again , Salmon!
8668.

Solve : dashes in batch file?

Answer»

Hello, can anyone explain me what these dashes means and do in this line from batch file?

if -%1 == - GOTO error1
:error1
ECHO please write file name

When I write only batch file name in prompt line (WINDOWS Vista) without any other file and run it, I GET the message 'please write file name'.
I would like to know how these dashes work and where can I use it.The dash is so you can test for a blank parameter. You COULD use any character. Often PEOPLE use quotes before and after, or whatever.

if [%1==[ echo parameter is blank
if "%1"=="" echo parameter is blank
if $%1$==$$ echo paramter is blank
if cat%1==cat echo parameter is blank



Thank you for timeliness. Really helped me ))

8669.

Solve : Bach file for internet explorer?

Answer»

Hi all

I am opening 100 urls to see if they are accessible or not. I decided to make batch FILE to do this. I can open urls through batch file by

start iexplore.exe www.google.com

but i want SOMETHING else.

I want my batch file to generate a file which can TELL me that which links were opened and which were not opened. In other words my batch file can catch 404 eroor and display it in a text file.

Regards
SaraIt WOULD be better to use ping and check errorlevel. Why do you want to do this?

8670.

Solve : syntax for info from registry?

Answer»

Hi all,

I need a return list of configured fonts in a database program.

For that I need a list of all the fonts marked in the data FIELD as 1 in the registry located at:

HKEY_CURRENT_USER
Software
FileMaker
8.5A
Fonts

Can someone put the total string together that I have to use to reach the list?

It's the command I have to use in a Send Event function in FileMaker.
But I'm stuck where to use the '/' or the '\' etc.

TIAThank you for the long list of possibilities and parameters.

Right now I have absolutely no clue how to put what together with what to reach the info I need....

Is it something like:

REG QUERY \HKEY_CURRENT_USER\Software\FileMaker\8.5A\Fonts....??

Do I need to put C:\ in front ? and is it HKCU instead of HKEY_CURRENT_USER ??

I never, ever did something like that before, never needed.... so I'm a bit at lost here....

If I could have the total string needed to retrieve the info in the command line, that would be a saver...

I tried some combinations, but I'm not completely at ease to try things out at command level and registry....

And an additional question: is it possible to have the result of the query saved in some KIND of text file ?TYPE

reg query HKEY_CURRENT_USER\Software\FileMaker\8.5A\Fonts

at the prompt. What do you get?


Two posts from BillRich have been deleted from this thread.Thank goodness...
For AWHILE i thought the OP was talking to himself... Quote from: Salmon Trout on February 19, 2011, 02:50:21 AM

type

reg query HKEY_CURRENT_USER\Software\FileMaker\8.5A\Fonts

at the prompt. What do you get?

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

Same message when I remove 'reg'

......Quote from: JMontana on February 19, 2011, 12:07:50 PM
'reg' is not recognized as an internal or external command, operable program or batch.

what happens when you type

PATH

at the prompt?

Also, is this file present?

C:\windows\system32\reg.exe



Quote from: Salmon Trout on February 19, 2011, 12:22:10 PM
what happens when you type

PATH

at the prompt?
On the Win 2000
PATH=C:\WINNT\system32;C:\WINNT\System32\Wbem;C:\PROGRAM~1\COMMON~1\ODBC\FILEMA~1;C:\Program Files\Microsoft SQL Server\80\Tools\Binn\;C:\Program Files\Oracle\win32

On the Win 7
See screenshot

Quote from: Salmon Trout on February 19, 2011, 12:22:10 PM
Also, is this file present?

C:\windows\system32\reg.exe

Yes on the Win 7, no on the Win 2000

[recovering disk space - old attachment deleted by admin]Quote from: JMontana on February 19, 2011, 03:59:35 PM
On the Win 2000
PATH=C:\WINNT\system32;C:\WINNT\System32\Wbem;C:\PROGRAM~1\COMMON~1\ODBC\FILEMA~1;C:\Program Files\Microsoft SQL Server\80\Tools\Binn\;C:\Program Files\Oracle\win32

On the Win 7
See screenshot

Yes on the Win 7, no on the Win 2000

Ah... now you see fit to give some more information! At last! I was wondering when you would get around to divulging the OS. It seems there are in fact two.

Well, as far as I can see the reg command should work perfectly well in your Windows 7 situation, since (a) reg.exe is in c:\windows\system32, and (b) that FOLDER is (correctly) included in the PATH. Yet you say it does not? Is that right? If so, I am very surprised.

However, in the Windows 2000 situation you need to install the Support Tools from the Windows 2000 installation CD as reg.exe is not installed by default, instructions here:

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

or if the CD is not to hand, get just reg.exe (in a zip archive) here

http://www.dynawell.com/download/reskit/microsoft/win2000/reg.zip

and unpack it to a folder listed in the PATH variable.
8671.

Solve : Replace text in a bat files at once?

Answer»

Hi All

I have set of bat files. Following highlighted text are common to all bat files.

SQLCMD -S ADC012-PC1\SQLExpress -d test -i E:\REPORTS\SQLtemplates\R0001.sql -o E:\Reports\Output\R0001.csv -s","

All bat files are stored in a E:\Reports\BatFiles folder. I want to do following things USING a new bat file.

1. Create new folder in E:\Reports. new folder name is 2011. And also two folders which are called BatFiles and Output folders should be created WITHIN the 2011 folder. (i.e E:\Reports\2011\BatFiles and E:\Reports\2011\Output

2. Copy all bat files which are stored in E:\Reports\BatFiles folder to E:\Reports\2011\BatFiles folder

3. Then replace "E:\Reports\Output\ " text into "E:\Reports\2011\Output\" in EVERY bat file content.

Please advice me how to achieve my requirements.

Thank You

Based on the information you have given, this should hopefully work:

@echo off
setlocal enabledelayedexpansion
if not exist E:\Reports\2011 md E:\Reports\2011
if not exist E:\Reports\2011\BatFiles md E:\Reports\2011\BatFiles
if not exist E:\Reports\2011\Output md E:\Reports\2011\Output
cd /d "E:\Reports\BatFiles"
for %%A in (*.bat) do (
echo Processing file: %%~dpnxA
if exist "E:\Reports\2011\BatFiles\%%~nxA" del "E:\Reports\2011\BatFiles\%%~nxA"
for /f "delims==" %%B in ('type %%A') do (
set iline=%%B
if "!iline:~0,79!"=="sqlcmd -S ADC012-PC1\SQLExpress -d test -i E:\Reports\SQLtemplates\R0001.sql -o" (
set oline=!iline:E:\Reports\Output\=E:\Reports\2011\Output\!
echo !oline!>>"E:\Reports\2011\BatFiles\%%~nxA"
) else (
echo !iline!>>"E:\Reports\2011\BatFiles\%%~nxA"
)
)
)
echo Done
echo.
pause

8672.

Solve : Control LCD Projector with a Batch File?

Answer»

Hello all,
I'm totally green when it comes to creating batch files. I have been told that I am able to control my projector (via a rs232 serial connection) with a batch FILE. The TWO things I need it to do is to turn on and turn off. Probably two different files? I have hex code for my projector. To turn the projector on its: BE EF 03 06 00 BA D2 01 00 00 60 01 00
How do I implement this into a batch file? The projector is using Com Port 1 if that helps.

I hate having to manually turn the thing on every morning.

Thanks in advance I can see a way doing this with hyperterm and a macro, or C++, but not sure about doing this with plain old batch.Quote from: DaveLembke on February 20, 2011, 08:20:22 PM

I can see a way doing this with hyperterm and a macro, or C++, but not sure about doing this with plain old batch.

COM1: is the serial port, I think. You can SET baud rate,parity, start &AMP; stop bits etc from batch, and send byte strings.
8673.

Solve : weird keyboard thing help please ??

Answer»

-not sure if this is in the right category-
so, al of a suden my computer (laptop ) started doing this weird thing
when i HOLD down a key it only does it once, like BACKSPACE,leters,space,scrol down/up
and its making this weird ticking noise when i PRES a key
PLEASE please help i ned this fixed thanks (:Check the repeat rate setting in Control Panel/Keyboards...It seems as THOUGH you have "Filter Keys" switched on. To disable this hold down the SHIFT key on the right hand side of the keyboard for about 8-10 seconds. You will hear a noise (not the regular 'tick') to indicate that "Filter Keys" has been disabled.

8674.

Solve : Having strange problem with scheduled task?

Answer»

Any SUGGESTIONS here would be appreciated but I think this is so bizzare or deep into Windows that I'm not expecting any. I am developing a scheduled task that will run every morning unattended. The script starts Excel and specifies a workbook to open. The 'workbook_open' event runs and when finished, starts another batch file (via Shell(batFile, 1) and shuts down Excel. The 'batFile' starts Access and specifies the database to open. The database runs an AutoExec function and then shuts Access down. This sequence runs fours times for four separate databases. Here's the problem:

When the scheduled task runs under my account, everything works fine. However, when we change the scheduled task to run under the System Administrators account (we have to do this for reasons not important here), the sequence for one of the databases does not run. I have isolated the problem to the 'Start' commands for both Excel and Access. What appears to be happenng is that for the Excel 'Start', Excel starts but the 'specified' workbook is not opened, hence Excel just sits there as an open PROCESS not doing anything. When I changed the name of the 'specified' workbook, the Excel 'Start' works okay, opening up the renamed workbook. The same thing happens with the Access 'Start' command. Access starts but the 'specified' database does not open, hence Access just sits there as a idling process. I got around the Excel start by renaming the workbook. I cannot change the database name, however, because of other implications.

This happens with only one database and only when running under an account not my own. What could be causing the 'Start' command to not function correctly when running under the SA's account, i.e., the 'Start' command launches the APPLICATION but does not open the file specified in the command?

Thanks for any help.More info. I find that if I change the name of the folder that contains the database and change the 'start' command accordingly, the database opens.I CREATED a second parent folder and subfolder tree and renamed old and new parent folders hoping that reconstructing the folder tree would fix this. It did not. Could this be a script or task caching problem, where file pointers are corrupt and the 'start' command won't work until a reboot takes place?More info. If I remove the application name from the 'start' command and just invoke the file (e.g., "c:\file\wb.xlsm" instead of Start Excel "c:\file\wb.xlsm"), it still does not work. The command does not find the file to start the application.Thanks for the suggestion. I got around this problem by renaming the parent folder to which the folder (that contains both the workbook and the database) belongs. It's a bit of a pain since I now have to correct places that reference this path. But it works. I'll see if the next reboot CLEARS the problem. Otherwise, I don't expect to have this problem again.

8675.

Solve : DOS environment variable?

Answer»

I try to store a file sequence NUMBER in an ENVIRONMENT variable.

these are the steps I took
run the command.exe from window XP
type SET filesequence = a on the command prompt
type SET to verify, it is there!
type EXIT to exit
Run the command.exe from window again
the environment variable filesequence disappears

is there a way to make the environment variable permanent?

I have the same problem when setting it in BAT program. When the program FINISHES, the variables set inside the program disappear. In DOS, are program variables and environment variables are defined differently?

thanks in advance for any help.Using set only creates an environment variable for the current session, but you can use the setx command to create persistent variables. Type setx /? to see the documentation.





Quote from: Salmon Trout on February 18, 2011, 02:20:58 PM

Using set only creates an environment variable for the current session, but you can use the setx command to create persistent variables. Type setx /? to see the documentation.

example:

setx filesequence a

You need to start a new command session to see the new variable

Note that to set the variable to a null value you can do

setx filesequence ""

but the registry entry will still be there. To completely remove it use the enviroment variables GUI.

Something you should note:

Your script that you showed contains too many spaces in the SET command.

This command: SET filesequence = a does not create a variable referred to by %filesequence% which expands to "a". It creates a variable referred to by %filesequence % which expands to " a". (The quotes are not part of the values, I included them to show the effect of the leading SPACE)

You need:

SET filesequence=a

See? No spaces. In the SET command syntax every character before the = character is part of the variable name and every character after the = is part of the variable value. This includes spaces. In fact this applies generally, e.g. in IF comparisons.


thanks very much for the information.

However, when I tried SETX, I got the message

N:\>setx fileseq=1
'SETX' is not recognized as an internal or external command,
operable program or batch file.

I am running C:\WINDOWS\system32\command.com

Do I need to turn on anything?

thanks.What operating system are you running? If Windows 2000 or after, why aren't you using cmd.exe?
Hi, I am running Window XP professional 2002, service pack 3. The same unrecognised SETX return when I execute it through CMD.EXE

thanks.Quote from: edwin.fung on February 22, 2011, 11:13:03 AM
Hi, I am running Window XP professional 2002, service pack 3. The same unrecognised SETX return when I execute it through CMD.EXE

thanks.

1. get it here

http://www.microsoft.com/downloads/en/confirmation.aspx?FamilyID=dc2d3339-8f36-4fba-a406-2a2a2ad7208c

2. You used the wrong syntax

Quote
However, when I tried SETX, I got the message

N:\>setx fileseq=1

You should use

setx fileseq 1

No equals sign. I showed you this above.




thanks a lot! It works! Quote from: edwin.fung on February 24, 2011, 12:18:47 PM
It works!

That is GOOD news!
8676.

Solve : stupid automatic shut-down... curse you!?

Answer»

Hello,
I am running a command shell program that can take DAYS to do a bunch of molecular dynamics simulations. How can I prevent my "power-saver" from automatically turning off my computer? (fyi - set to power down after 4 hours of inactivity currently).
Key point - I don't want to always have to manually change the power settings -- I want the "default" to be such that the computer shuts down after 4 hours of inactivity -- UNLESS this particular molecular dynamics program is running in the background....
... HELP?

FYI - I run Windows 7 64 bit, and the program (I'll call it 'chem.exe') is run via the DOS-like "Command Prompt" (
I type: C:\mydirectory\chem.exe input_file_name.txt > log_file_name.txt )

Did you write the program? If not, could you contact the author and present your n PROBLEM with him? Thee is a method in the MS library to address this kind of thing.
From MS:
Preventing Automatic Power Down
The article does NOT directly APPLY to your OS. But there are related links that may take you in the right direction.Thanks..
Well, I have the source code (Fortran - yeah)... but I am not that skilled of a programmer. I don't think I would know where to put 'instructions' on not to shut down. However... I know that (somehow) you can tell windows not to shut down if it is running some particular program.... I just wish I could remember how.

In Windows 7 the command line powercfg tool has the ability to override power saving actions such as turning off the display, hibernation etc.

http://technet.microsoft.com/en-us/library/cc748940%28WS.10%29.aspx

Quote

-REQUESTS
Enumerate application and driver Power Requests. Power Requests prevent the computer from automatically powering off the display or entering a low-power sleep mode.

-REQUESTSOVERRIDE
Sets a Power Request override for a particular Process, Service, or Driver. If no parameters are specified, this command displays the current list of Power Request Overrides.

USAGE: POWERCFG -REQUESTSOVERRIDE <CALLER_TYPE> <NAME> <REQUEST>
<CALLER_TYPE> Specifies one of the following caller type:
PROCESS, SERVICE, DRIVER. This is obtained by
calling the POWERCFG -REQUESTS command.
<NAME> Specifies the caller name. This is the name
returned from calling POWERCFG -REQUESTS command.

<REQUEST> Specifies one or more of the following Power
Request Types: Display, System, Awaymode.
Example:
POWERCFG -REQUESTSOVERRIDE PROCESS wmplayer.exe Display System


8677.

Solve : Help me to refreshing my mind?

Answer» SEARCHING with google we will finding this batch program "del c: \ windows \ prefetch \ ntosboot-*.* / q" this program USUALLY using in windows xp or windows with gpedit.msc

*Common location of this batch FILE at> run>gpedit.msc>Computer Configuration-> Windows Settings-> Script-> then CLICK 2 times on Shutdown

*In Windows Shutdown Properties click Add and then browse. and search for the location of the batch files that I'm create like on the top
*Then click OK, Apply and OK again to finish it (works on window Xp)

My problems is, I'm dying to love this "strong ram command"and I ever done it with my win 7 starter
But, now after recovery my laptop I didn't get the idea how to do that again..I do, I really lose my data and memory,on how suppose to run this scripts...in my win 7 starter

I've read the forum and and I love being here hoping someone could help me to solve my problems

thanks before.Billrich waking up the OLD threads...
8678.

Solve : MS-DOS DEFRAG COMMAND?

Answer» HI, does anyone know where I could download the MS-DOS COMMAND "DEFRAG"?
thanx
BernardoWhat VERSION of MS-DOS?
8679.

Solve : User Profile Back up and Restore (xp and win7)?

Answer»

So I understand the very basics of batch files and that's about it. So I found this script online and was wondering if someone COULD help me make a few changes. I work for a SCHOOL DISTRICT and I'm always having to backup and restores users outlook, docs, pics, favorites etc. Each user that logins in is assigned a personal drive to backup STUFF drive P: Anyways that's a little background info.

---------------------------------------
This works perfect with XP right now but it would be nice if it would work with 7 also.
Here's what I would like to do if possible...

Create a menu with 1,2, and 3.

Press a number and hit enter ...

1 - Backups up everything to drive P:\Backup
2 - Restores users data from P:\Backup to the local machine C:\users..
3 - exit


Thanks in advance!

Code: [Select] @echo off
:: variables
set drive=P:\Backup - Auto
set backupcmd=xcopy /s /c /d /e /h /i /r /y

echo ### Backing up My Documents...
%backupcmd% "%USERPROFILE%\My Documents" "%drive%\My Documents"

echo ### Backing up Favorites...
%backupcmd% "%USERPROFILE%\Favorites" "%drive%\Favorites"

echo ### Backing up email and contacts (MS Outlook)...
%backupcmd% "%USERPROFILE%\Local Settings\Application Data\Microsoft\Outlook" "%drive%\Outlook"

echo ### Backing up the Registry...
if not exist "%drive%\Registry" mkdir "%drive%\Registry"
if exist "%drive%\Registry\regbackup.reg" del "%drive%\Registry\regbackup.reg"
regedit /e "%drive%\Registry\regbackup.reg"

:: use below syntax to backup other directories...
:: %backupcmd% "...source directory..." "%drive%\...destination dir..."

echo Backup Complete!
@pause

8680.

Solve : DOS program, run on Linux using WINE?

Answer»

Hi, I have a question,
I don't know a *censored* of a lot about computers. Anyway, I have a "command-shell" program that is used to do molecular dynamics simulations. There are no graphics.... nothing... I just run the program through the Windows Command prompt by typing "C:\myProgram.exe InputFileName.txt > LogFileName.txt " and I just wait until it says "FINISHED."

Additional info: Basically, the program starts with the input file containing molecular data, does a bunch of calculations on that data, and writes the results to file. -- On my NEW computer (10,000 RMP hard drive, new AMD 6 core processor... etc) the calculations still TAKE DAYS. FYI - the program does not run "in parallel" (WHATEVER that means).

But I also use Linux. The program was only written for Windows, as far as I know. However, I can easily get the program to run in linux through the Terminal, using WINE. But my question is this: Will the "myProgram.exe" run more slowly on Linux, when invoked using WINE (as compared to running it via Windows Command Prompt)?
If it is slower, are we talking 2x slower? 10x? Or is it just, like, 5% slower?

Thanks,
me
Quote from: bhill4 on March 01, 2011, 09:09:16 PM

If it is slower, are we talking 2x slower? 10x? Or is it just, like, 5% slower?

Why would it be slower?

WINE is not an Emulator...I've answered three or four threads by this guy and he never comes back.
8681.

Solve : Help with ROBOCOPY?

Answer»

Hi,

I have a batch FILE that copies FILES from one server to another. The batch file uses the ROBOCOPY.exe to do the work, but I need to TRY cutting down the number of items sent to the log file which is generated, and hoped someone can assist with this?

my batch file has the flag files configured as below:

set xflags=/E /COPYALL /PURGE /ZB /R:0 /W:0 /LOG+:"%logfile%" /TS /FP /NJH /NJS /NP

Then, further down the batch file (where all the work is done) I have the following:


for /f "tokens=1,2* delims=:" %%G IN (%datafile%) DO (
if %%G==REM echo skipping %%H
if NOT %%G==REM (
@ECHO Copying %%G:%%H
@ECHO %date% %time% Copying %%G:%%H >> %logfile%
%roboloc% "%%G:%%H" "c:\%%H" %xflags%
@ECHO %date% %time% %%G:%%H Copied >> %logfile%
)
)


Obviously the entry %roboloc% is configured with a set command to the location of the exe.

Now, the idea is that I copy all files the first time, and then every time the file is run again, it will only copy across the files that are different.

If I say "server A" holds a location "C:\getmyfiles" which contains a number of sub folders, which also contain subfolders, and I WANT these to be duplicated on another server (lets say "server B"), then the batch file runs on "server B" and copies anything it does not have. All files are recorded at the moment in a backup log, regardless of whether they are NEW, old etc.

I want my batch file to only copy the files from "server A" that are not present on "server B", and also remove files from "server B" if they are not present on "server A" (which I believe the /PURGE flag will do for me).
I also only want to record in my log file if the file was copied or deleted, and ignore every other file.

I hope this is enough information and that it is understandable enough.

Offers with help will be kindly accepted.

Regards

RichQuote from: Northenlad60 on February 10, 2011, 08:30:17 AM

Now, the idea is that I copy all files the first time, and then every time the file is run again, it will only copy across the files that are different.

What O/S's are you using? I'm pretty sure XCOPY has this as a built in feature.

There are also other syncronisation tools out there that seem to do what you want, that might be simpler to setup.

Like : http://www.codeproject.com/KB/files/FileSync.aspx
8682.

Solve : Checking if multiple files exist?

Answer»

I have 3 files:

File A
File B
File C

They are all in a folder. If I run "Your BATCH" it should say that all files are there.
Now, If i deleted/moved any 1-3 file(s), how could I MAKE it say "File B is missing; File C is missing"
or like "File A is missing"

I don't want to edit the batch file while doing this, so that it does this automatically.

If you guys can help me on this, I would REALLY APPRECIATE it. I've been struggling on how to do this for the whole DAY :/

Thanks

8683.

Solve : minimize to system tray?

Answer»

hello there!

just want to ask if there's a code in batch on how to minimize a window?

if there, code pls...!!!

thanks in advance!Your title asked about the system tray but the actual post just asked how to minimize a window. Did you mean start a program minimized or minimize an already existing window?
and what does minimizing a window have to do with the Notification Area?To minimize the window from batch, you would have to use an external program because that function is not built in to batch.

Here is a program which can minimize windows in batch: http://www.commandline.co.uk/cmdow/index.html

As for the system tray thing, I am not sure what you are talking about.Quote from: Linux711 on March 02, 2011, 10:56:37 AM

As for the system tray thing, I am not sure what you are talking about.

System tray is another name for the notification area, which is the portion of the taskbar that displays icons for system and program features that have no presence on the desktop as well as the time and the volume icon. It contains mainly icons that show status information, though some programs, such as Winamp, use it for minimized windows. By default, this is located in the bottom-right of the primary monitor (or bottom-left on languages of Windows that use right-to-left reading order), or at the bottom of the taskbar if docked vertically. The clock appears here, and applications can put icons in the notification area to indicate the status of an operation or to notify the user about an event. For example, an application might put a printer icon in the status area to show that a print job is under way, or a display driver application may provide quick access to various screen resolutions.

Microsoft STATES it is wrong to call it the system tray, although the term is sometimes used in Microsoft documentation, articles, and software descriptions. Raymond Chen (the guy who writes The Old New Thing blog) suggests the confusion originated with systray.exe, a small application that controlled some icons within the notification area in Windows 95.

I know what the system tray is. I meant I don't understand how a batch file could be minimized to it.Quote from: Linux711 on March 02, 2011, 11:53:19 AM
I know what the system tray is. I meant I don't understand how a batch file could be minimized to it.

It can't, not using anything easily accessible which is built-in to Windows, but there are a number of 3rd party applications that would allow you to minimize a command window with a batch file running in it or not, or any other window, to the system area. For example Dexpot, RBTray, TrayIt! PowerMenu ETC. Quote from: Salmon Trout on March 02, 2011, 11:06:48 AM
Microsoft states it is wrong to call it the system tray, although the term is sometimes used in Microsoft documentation, articles, and software descriptions.

Raymond Chen wrote in 2003:

"I think the reason people started calling it the "system tray" is that on Win95 there was a program called "systray.exe" that displayed some icons in the notification area: volume control, PCMCIA (as it was then called) status, battery meter. If you killed systray.exe, you lost those notification icons. So people thought, "Ah, systray must be the component that manages those icons, and I bet its name is 'system tray'." THUS began the misconception that we have been trying to eradicate for over eight years...

Even worse, other
[Microsoft] groups (not the shell) picked up on this misnomer and started referring it to the tray in their own documentation and samples, some of which even erroneously claim that "system tray" is the official name of the notification area.

[...]

Summary: It is never correct to refer to the notification area as the tray. It has always been called the "notification area". "
sorry!

what I mean is that when a existing window of a batch file is minimize, it will go to the notification area and not on the taskbar.

thanks!No. You can't do this through batch or scripting. It will require the creation of a window and the handling of messages SENT to that window.If you install Dexpot you can right click the titlebar of a window and one of the options is "Minimize to system tray". After you do this, until you close that window, or toggle the setting, when you minimize it, that application will go to Notification Area instead of the taskbar. You can create 'rules' so that chosen programs are always minimized this way.

o i c

ty v-much!!!
8684.

Solve : How to Keep Process Open?

Answer»

I found a batch file that was supposed to keep any process open while the batch is running, but it doesn't work.
No MATTER what I do, it always says that the process is not open.

Here is the batch (Credits to Foxhound)

Code: [Select]@echo off
mode con cols=35 lines=10
title Keep a process open.
set /p ppath=Enter the folder where the process is located in:
cls
set /p pname=Enter the exact name of the process you wish to keep open:
cd %ppath%
:LOOP
cls
tasklist | find "%pname%" >nul
if %errorlevel%==1 (
color 0c
echo Program not found. Starting %pname%
start %pname%
goto WAIT
)
if %errorlevel%==0 (
color 0a
echo Program found. Skipping start.
goto wait
)
:wait
timeout /t 5 /NOBREAK >nul
goto loop

Could someone PLEASE tell me how to fix it, or have any other batch files like this that work?

Thanks

I cleaned up your code and added a TRAP to to prevent a code malfunction that would send the batch file into a loop of opening endless cmd windows.

I suspect this file does not do what you think it does. When a process in no longer on the tasklist, it will start a new instance of the program, however the previous instance will be long terminated. It will not keep a process open, just create a new one.

If there are multiple copies of a process, how do you distinguish between them?

Code: [Select]@echo off

title Keep a process open.
set /p ppath=Enter the folder where the process is located in:

set /p pname=Enter the exact name of the process you wish to keep open:
if not exist %ppath%\%pname% (
echo %ppath%\%pname NOT found
goto :eof
)
cd %ppath%

:loop
tasklist | find "%pname%" >nul
if errorlevel 1 (
color 0c
echo Program not found. Starting %pname%
start %pname%
goto wait
)

if not errorlevel 1 (
color 0a
echo Program found. Skipping start.
goto wait
)

:wait
timeout 5 >nul
goto loop

8685.

Solve : substring indexing?

Answer»

I try to INSERT a SEQUENCE number into a file name

to file name = from file name without extension + file sequence + from file name extension

e.g.
Personal Folders.pst will become Personal Folders 2.pst

please see the code I wrote below. Is there a WAY to simplify? I tried replacing the substring index by a counter %m% i.e. %fromfile1:~%m%,1% but it did not work.

Any suggestion will be appreciated! thanks.

set tofile1=%fromfile1% %filesequence%

if not %fromfile1:~-1,1% == . goto next1
set tofile1=%fromfile1:~0,-1% %filesequence%%fromfile1:~-1%
:next1

if not %fromfile1:~-2,1% == . goto next2
set tofile1=%fromfile1:~0,-2% %filesequence%%fromfile1:~-2%
:next2

if not %fromfile1:~-3,1% == . goto next3
set tofile1=%fromfile1:~0,-3% %filesequence%%fromfile1:~-3%
:next3

if not %fromfile1:~-4,1% == . goto next4
set tofile1=%fromfile1:~0,-4% %filesequence%%fromfile1:~-4%
:next4

The simplest way to manipulate filenames is to use FOR. There are a number of "variable modifiers". See the FOR documentation.

Example (try it in a batch script)

FOR %%A in ("Personal Folders.pst") do @echo %%~nA 2%%~xA



Quote

I tried replacing the substring index by a counter %m% i.e. %fromfile1:~%m%,1% but it did not work.

You can do this if you use CALL to expand the "count" variable. You have to add an extra percent sign at start and FINISH of the string expression. I have underlined and coloured them blue here...

@echo off
set /p MyString="String? "
set num=0
:Loop
call set char=%%MyString:~%num%,1%%
if "%char%"=="" goto ExitLoop
set /a Cpos=%num%+1
echo Character %Cpos%: "%char%"
set /a num=%num%+1
goto Loop
:ExitLoop
echo Reached end of string
pause


String? Not in civilised countries.
Character 1: "N"
Character 2: "o"
Character 3: "t"
Character 4: " "
Character 5: "i"
Character 6: "n"
Character 7: " "
Character 8: "c"
Character 9: "i"
Character 10: "v"
Character 11: "i"
Character 12: "l"
Character 13: "i"
Character 14: "s"
Character 15: "e"
Character 16: "d"
Character 17: " "
Character 18: "c"
Character 19: "o"
Character 20: "u"
Character 21: "n"
Character 22: "t"
Character 23: "r"
Character 24: "i"
Character 25: "e"
Character 26: "s"
Character 27: "."
Reached end of string
Press any key to continue . . .



Use CALL to simulate arrays

@echo off
setlocal enabledelayedexpansion

echo Abacus>test.txt
echo Bear>>test.txt
echo Codifier>>test.txt
echo David>>test.txt

set n=0
for /f "delims=" %%A in (test.txt) do (
call set array!!n!!=%%A
set /a n+=1
)
set a | find "array"



array0=Abacus
array1=Bear
array2=Codifier
array3=David

Thanks very much for the information. You amazed me of what it can do.
8686.

Solve : disallow wildcards with the 'set' command?

Answer»

I HOPE one of you BRAINY folk can help. I've written a rather lengthy batch file and all works brilliantly, however as it involves deleting and renaming server based profiles based on user input I can't risk it allowing them to input wildcards otherwise they could technically have the ability to cause quite a bit of damage. So, basically all I need is a way of trapping user input of wildcards (eg * and ?) via a 'set /p' command... any ideas? Is there a way of saying:
if %input% contains "*" goto...
Would it be like this? Break it into little steps.

  • Get the user input.
  • Scan for certain symbols.
  • If found, chide the user and start over.
  • Otherwise all OK.
Is that too hard?You can use this little snippet as a template to integrate with your own code:

Code: [SELECT]@echo off
set /p var=Enter Data:
echo %var% | find "*"
if not errorlevel 1 echo Wildcard present

The operative instruction is checking the errorlevel for zero (not 1) indicating there is a wildcard in the user input. By trapping the data this way you can bring your batch file in for a gentle landing rather than SLAMMING into the mountain.

Good luck. Thanks for the replies and PM's chaps/chapettes. Sidewinders solution is the one I've used for it's SIMPLICITY. So simple yet works a treat (I think I was trying to overcomplicate things ) Thanks again!
8687.

Solve : Problems navigating to partition?

Answer»

I am currently trying to write a batch file to move some stuff from one NTFS partition to another. The problem is i cant navigate to my other partition. If anyone can guide me threw what i am doing wrong that would be fantastic. Im using CMD in xp SP3.please show your batch file so far.
I haven't started on it. The only thing i need is how to change directory to the partition. other than that all will take is a "move "File name" "Location" " Code: [Select]Microsoft Windows XP [VERSION 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\Kohn>d:

D:\>cd BAT

D:\bat>Quote from: wsuErk on March 04, 2011, 08:16:25 AM

I haven't started on it. The only thing i need is how to change directory to the partition. other than that all will take is a "move "File name" "Location" "

What do you mean by "partition"?

To change to a directory on a different drive either:

(1) Change to the wanted drive letter by using the letter followed by a colon D: then use cd to change to the folder cd bat

or

(2) do it all at once by using the cd command with the /d switch e.g.: cd /d d:\bat


Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\Erk>cd f:
F:\

C:\Documents and Settings\Erk>

that is what is happening, it echos back but doesn't change. Bellow i attached a picture of the drive i am trying to DIRECT to.
Also my F:\ is the same hard drive as C:\ just a different partition. im sorry for not clarifying EARLIER. Read what I wrote above about changing drive letters.

i appologize, i miss read what you wrote and was still using CD when i tried to change. when switching drives do you always leave out the "cd"?Quote from: wsuErk on March 05, 2011, 05:33:35 AM
i appologize, i miss read what you wrote and was still using CD when i tried to change. when switching drives do you always leave out the "cd"?

Change drive, use letter and colon

D:

Change directory on same drive use cd

cd c:\pictures\cats

Change drive and directory at same time

cd /d d:\music\Mozart\Operas\Cosi

8688.

Solve : Self move Batch file?

Answer»

Hey frnds,
'm new to batch scripting, so havin some trouble.
I jst wanted to know if I cld write a batch file to move itself to another LOCATION jst by executing(running) it...

meaning, If I have a batch file at
C:\old\dir\first.bat (wer first.bat is my batch file that dat to run)
I wish to move it to
d:\new\directory\

Plz help... Why do you need to do this?

Quote from: Salmon Trout on March 06, 2011, 12:49:49 AM

Why do you need to do this?
Yes, smells like he wants to build a worm in batch.Hahaha, no no, not at all...
Actually, I wrote a batch file
Code: [Select]@echo off
cd /d "%1"
javac %2
if errorlevel 1 goto finish
java %3
:finish
pauseso that I could compile java from notepad++ directly...
Now my frnds arnt good at batch(I mean, they got no idea, not at all) so I want this above written batch file to automatically copy itself to "C:\notepad++"
& so I asked this question...Quote
Hahaha, no no, not at all...

Your friends are no good at batch and cannot place a simple batch file in a DESIRED directory, yet they can write java programs in notepad++, which they wish to compile?

[Edit] And you, who is are so much better than they are, can't work it out either?


Quote from: Salmon Trout on March 06, 2011, 01:25:14 AM
Your friends are no good at batch and cannot place a simple batch file in a desired directory, yet they can write java programs in notepad++, which they wish to compile?
Mabe not, but if a process can be automated, then y cant we do so ?

Quote from: Salmon Trout on March 06, 2011, 01:25:14 AM
And you, who is are so much better than they are, can't work it out either?
Is that an offense ?
Not all are genius like you Salmon...Quote from: Rico on March 06, 2011, 02:22:04 AM
Not all are genius like you Salmon...

Not even me. As you can see I was uncertain of my grammar.

They do say that "genius" is 1% inspiration and 99% perspiration, and it is certainly true that the willingness to do research and look for information is a big PART of gaining knowledge. So you should investigate

1. The COPY and MOVE commands.

2. You seem to know what the replaceable parameters %1, %2 etc are... Find out what %0 (percent zero) means.

3. In connection with (2) you should CAREFULLY study the variable modifiers such a %~d %~p etc which are documented in the FOR help.







8689.

Solve : problem with writting batch file?

Answer»

Hello, i have written batch file but it doesn't work properly. I put here only a part of it, where in my opinion the problem might be. So when the batch file run in prompt line and I get the QUESTION "Would you like it to delete and create new ONE?", I press N and then I get the message "File name.txt is not deleted." and in the next line shows "File name.txt is deleted." I don't understand why it goes first to RUBBER and then go to BEGINNING instead of going only to BEGINNING. So what is the problem? I appreciate help very much...

:error2
echo %1 already exists.
echo.
echo Would you like it to delete and create new one?
echo.
echo If yes, press T, if no, press N.
choice /C:TN
if ERRORLEVEL 2 echo File %1 is not deleted.
if errorlevel 1 goto RUBBER
goto beginning

:RUBBER
del /F /Q %1
if not %ERRORLEVEL% == 0 goto error3
echo File %1 is deleted.
goto beginningYou need to study the way the old MS-DOS if errorlevel test works. It is different from if %errorlevel%==%something% (which came first with Windows 2000) You have mixed these 2 different syntaxes.

if errorlevel X [do something] means do something if the errorlevel is equal to or greater than X.

When you hit N choice.exe returns an errorlevel of 2 (because N is choice number 2). "if errorlevel 2" checks for an errorlevel of 2 or greater so the test "if errorlevel 2" is satisfied, therefore "echo File %1 is deleted" is executed. Next, the batch goes to the next line and because 2 is greater than 1 the command "goto RUBBER" is executed.

So use "if errorlevel 2 goto SOMEWHERE".



THANK you. If you let me I ask you for more tips. In the part of RUBBER if file can not be deleted (for example another program uses it) I have written line "if not %ERRORLEVEL% == 0 goto error3", is it right or is there any better solutions for that problem?
About error levels I have read but actually haven't understand well, especially about %errorlevel%Actually I understand what you wrote about errorlevel but before I didn't find very much information about errorlevels.Quote from: infogirl on March 06, 2011, 08:23:42 AM

if file can not be deleted (for example another program uses it) I have written line "if not %ERRORLEVEL% == 0 goto error3", is it right or is there any better solutions for that problem?

If you use the %errorlevel% syntax you can do this (which I prefer)

if %errorlevel% neq 0 goto error3




8690.

Solve : Find & Replace "," with " " in large text file using batch?

Answer»

Quote from: Salmon Trout on March 05, 2011, 04:55:31 AM

c:\batch\BillRich>type xyz.txt
blah blah blah
blah blah blah

That's not true! He always starts with a dir for no reason!


Quote
Its a waste not to hone your Perl (Python or RUBY or whatever you have learned besides batch etc )
Indeed, The OP has shown some usage of perl previously, and I mean no offense to them but it had a clear "beginner" look to it; I say this because many calls were "system()'d" (or whatever the equivalent Perl statement for shelling another app is) Which isn't so bad in and of itself, but many of the tasks being done with it were quite doable from within perl. With that in mind, I feel maybe they may have some misconceptions about how versatile perl is, because even when they are using perl (and even C++) they are still performing a lot of their tasks using "batch" (shelled out commands). I've always thought it was utterly silly to shell out to another application in this fashion, and is usually a RESULT of only trying what you think is obvious, having it not work, and just shelling out and using a batch command you are familiar with; for example:
Code: [Select]#!/usr/bin/perl
system("cmd /c for %P in (*.txt) do echo %P");
Isn't a perl script; it's a batch file pretending to be a perl script. Obviously that's a simplified example, but usually when you see System() Calls all over- in almost any language- That's usually a sign that the language is badly written (and doesn't have that functionality) or that the writer of said script is in a rush to create something and couldn't be bothered to read the documentation; (Again, I mean zero offense to you (DaveLembke) by this; the documentation is hardly something I crack open next to the fire either), And if that's the case, education as to such possible shortcomings would usually be preferable compared to possibly reinforcing the same habits; even if the solution, in this case, ended up as a pure batch file, I saw no reason not to correct a perceived misconception as to the applicability of a tool designed specifically for the task in question.
[/code]Quote from: BC_Programmer on March 05, 2011, 08:48:24 AM
Code: [Select]#!/usr/bin/perl
system("cmd /c for %P in (*.txt) do echo %P");

Is cmd.exe kept in /usr/bin/windows?




Quote from: Salmon Trout on March 05, 2011, 08:56:25 AM
Is cmd.exe kept in /usr/bin/windows?

No idea.

The script does run and work as intended. cmd is on the path.Quote from: BC_Programmer on March 05, 2011, 08:58:48 AM
No idea.

The script does run and work as intended. cmd is on the path.

A shebang line starting a script that would only run in Windows...



Quote from: Salmon Trout on March 05, 2011, 08:16:27 AM
Maybe hard for you to believe this, but it's not all about you!
Its true that its not all about me, however, its also not hard to believe that I am MOSTLY the one who post awk solutions here. Also, I am the one who first encourages OP to use Perl (in this thread). Therefore, its OK to quote those 2 sentences you mentioned.Quote from: BC_Programmer on March 05, 2011, 08:48:24 AM
Indeed, The OP has shown some usage of perl previously, and I mean no offense to them but it had a clear "beginner" look to it; I say this because many calls were "system()'d" (or whatever the equivalent Perl statement for shelling another app is) Which isn't so bad in and of itself, but many of the tasks being done with it were quite doable from within perl.
I agree about the issue of shelling out to call external system commands. Perl (and Python/Ruby etc) has the capability (and libraries) to do many system administration tasks. Moving/Copying/removing of files, finding files, text/string manipulation etc many which batch isn't able to provide effectively. Shelling out also makes the code non-portable.
Quote from: BC_Programmer on March 05, 2011, 08:58:48 AM
No idea.

The script does run and work as intended. cmd is on the path.

In windows, perl (its spelt will capital "P" when referring to the language, small "P" to refer to the interpreter) will ignore shebang line. Its also better to use #! /usr/bin/env perl instead of /usr/bin/perl since not all distributions had their Perl installed in /usr/binI shall refrain from posting examples without doing extensive google to searches to make sure that the content of my examples that have nothing to do with what I was demonstrating are not redundancies that can be poked at for no good reason.

Also, Billrich has helpfully informed me that cmd.exe is in C:\windows\system32. He did so with a dir.Yes ... I would consider myself a beginner and I have dabbled with many languages from the early TRS-80's and BASIC to todays modern languages. I have dabbled with many of them but never became a specialist of any specific language. I also at times have broken the GOTO RULE which make professional programmers cringe, where I would have used loops and then realize I want a quick redirection in my code without having to place all that within another nested loop. Once compiled it all runs the same, although maybe with a fraction of a second difference in execution time where one may be more efficient than the other which accomplish the same goal. When it comes to SYSTEM calls, this is sort of a GOTO like habit, where there is a better way to accomplish the same or better results, but its raw and dirty code that works for what was intended.

When it comes to perl, I learned it through an online course at Virtual University. This covered all the common routines like PRINT, IF THEN ELSE, Loops, and Arrays. But it didnt go into detail as to the key strengths of perl over say C++ or BASIC in which perl has many short hand features that I was unaware of. The only shorthand I can remember from BASIC way back with GW-Basic was using ? marks in place of typing out PRINT. When listing however the interpreter would flip the ? to PRINT

I suppose I should focus on one language and learn it inside and out instead of making dirty PROGRAMS that are Rube Goldberg programming mixing and matching and sometimes dynamically compiling batch from perl in which the perl writes a batch file and then executes it to perform DOS batched functions etc. I am sure perl can do this without shelling out the functions by use of SYSTEM or compiling dynamic Batches on the fly. Like a Rube Goldberg making stuff more complex than it needs to be, but ending up with the same result, if I dont know of a quick better way to do something, I usually perform the quick 'Band-Aid' I guess you could call it to make it work, although attrocious to look at by a professional programmer..lol

Also the reason to do this in batch originally was also because I didnt want to have to install perl to the system that this was going to be run from, in addition to the fact that I thought batch was better geared for this replacement need, from seeing similar replacements in the past, but usually not with spaces but instead an alternate character such as \ with _

Any suggestions on a book that really shows the strengths of perl instead of the basics of print, logic, loops, and arrays that I can dive into to learn these strengths?

*Also I have had other programmers at times state that I should avoid perl for the nature of programming that I am doing where I am reading and writing to files and performing batched like system processes, because it was really created to be used for running CGI's with a web server such as Apache etc, while I actually like the structure of perl so I have stuck with it, with C++ being my second favorite although my C++ programs are all console type crude to get the job done and very rarely Visual C++. There suggestion was that I should stick with C++ over perl for my nature of programming, yet from the information shared here, it shows that perl is well equipt for my needs where I dont need any fancy gui, just for it to console and crunch. Also C++ programs to me require much more code than perl to get the same result.Quote
*Also I have had other programmers at times state that I should avoid perl for the nature of programming that I am doing where I am reading and writing to files and performing batched like system processes, because it was really created to be used for running CGI's with a web server such as Apache etc,
They are absolutely, positively wrong. They are likely thinking of PHP.Quote from: DaveLembke on March 06, 2011, 05:55:01 PM
Also the reason to do this in batch originally was also because I didnt want to have to install perl to the system that this was going to be run from, in addition to the fact that I thought batch was better geared for this replacement need, from seeing similar replacements in the past, but usually not with spaces but instead an alternate character such as \ with _
for your information, you do not have to install Perl on every machine you are going to run your script on. You can just install on one, do your development there , and then convert it to an executable so you can run almost anywhere on systems with more or less the same configuration.

Quote
Any suggestions on a book that really shows the strengths of perl instead of the basics of print, logic, loops, and arrays that I can dive into to learn these strengths?
No one should miss the official Perl documentation. A book comes later, or not at all.

Quote
*Also I have had other programmers at times state that I should avoid perl for the nature of programming that I am doing where I am reading and writing to files and performing batched like system processes, because it was really created to be used for running CGI's with a web server such as Apache etc,
that's so wrong. If you read the history of Perl, its mainly used for creating reports in the past. As the years go by, it has become a full fledged programming language capable of doing many things, besides using it for CGI ( by the way CGI is outdated, nowadays there are web frameworks such as Catalyst for web development stuff.)


Quote
while I actually like the structure of perl so I have stuck with it, with C++ being my second favorite although my C++ programs are all console type crude to get the job done and very rarely Visual C++. There suggestion was that I should stick with C++ over perl for my nature of programming, yet from the information shared here, it shows that perl is well equipt for my needs where I dont need any fancy gui, just for it to console and crunch. Also C++ programs to me require much more code than perl to get the same result.
I can understand the need for C++ if one is doing low level systems programming or games programming with you need the speed requirement etc, but if you are doing mostly systems administration , C++ is not really the tool to use as you can PRODUCE humongous lines of code just to do one simple task. Using a modern programming language that is both practical and easy to use is the way to go. I got flamed for mentioning assembler. This problem the OP posted is a elementary low-level job that can easily be done at the lowest level. The pearl advocate told me it was impractical. At one time assembly was the only tool for low-cost microcomputers. It is trivial to open a file, change all instances of just one code and then close the file. It is one of the primitive things you learn in using Assembler with an Operation System.
When GW-BASIC came out, there was a version of it, as I recall, that would let you open a file in RANDOM, and use GET and PUT to alerter the file content. Nobody at the time just set around waiting for somebody to invert a better programming language. We just used what we had. Now I am told that I should not do that sort of thing because somebody says it is not efficient, elegant or maintainable or acceptable or kosher. Never mind that it worked.
Well, they can just GOTO [unified label].
Quote from: Geek-9pm on March 06, 2011, 08:14:24 PM
I got flamed for mentioning assembler.
He asked for an example. That's not a flame. That's a valid request.

Quote
This problem the OP posted is a elementary low-level job that can easily be done at the lowest level.
Really? you can trivially implement File Input,Output, understanding different Character encodings and perform the appropriate mappings and replace a given character with another? You might respond "well, that isn't what they need" but what if in the future t hey do need it? Are they supposed to MODIFY that assembly to need these things that come for free with either batch or Perl, or any other scripting language at all? What kind of drugs are you on where you believe that "things should be done at the lowest level" you may as well suggest that they build, test, and use a integrated circuit board specifically for the replacement of characters. The lowest level is only the simplest level operationally; it's use and direct manipulation is anything but.

Quote
The pearl advocate told me it was impractical.

First, for the millionth time, it's Perl. Yes, I know your speech recognition program types it in for you. But deleting one letter- or simply copy pasting one of the previously mentioned instances of the word- couldn't possibly be that difficult. Second, he has a Nick. He's hardly the only one who believes Assembly is impractical. I'd go so far as to say using it for this purpose is outright stupid and driven purely by hubris.


Quote
At one time assembly was the only tool for low-cost microcomputers.
Hey, look at me! I can insert completely redundant and irrelevant pieces of data! At one time there was a Animal that looked similar to a zebra without stripes on it's hindquarters called the Quagga. See! I can do it too!

Quote
It is trivial to open a file, change all instances of just one code and then close the file. It is one of the primitive things you learn in using Assembler with an Operation System.
Cool... so why did you consider being asked to provide an example of this trivial piece of code a flame, exactly? Clearly you could have merely produced this trivial piece of code for all to see, rather then letting it remain a whimsical fantasy in your closed off tiny world where using Assembly for small, simple tasks is somehow not stupid.


Quote
When GW-BASIC came out, there was a version of it, as I recall, that would let you open a file in RANDOM, and use GET and PUT to alerter the file content.

Ok... What the *censored* are you talking about? One paragraph your going on about how trivial it is to write stuff using assembly, the next you are talking about GW-BASIC. Do you... No... you don't think GW-BASIC is assembly, do you? Because that would explain why you believe File IO and string manipulation are trivial, because they certainly are not trivial to do in Assembly, and certainly not for somebody who isn't familiar with Assembly, at all.

Quote
Nobody at the time just set around waiting for somebody to invert a better programming language. We just used what we had. Now I am told that I should not do that sort of thing because somebody says it is not efficient, elegant or maintainable or acceptable or kosher. Never mind that it worked.
Well, they can just GOTO [unified label].

This... is still entirely irrelevant. You went "it's easy to write something like this in assembly. Also, GW-BASIC, which has nothing to do with this discussion to people who actually have a clue, uses GOTO's and people say it's not elegant or kosher." Nobody cares about your whimsical banterings about GW-BASIC, especially in the context where you are talking about assembly, which in and of itself is entirely irrelevant to the thread.


8691.

Solve : errorlevels?

Answer»

Hello, I would like to ask what -1 means in this part of batch FILE ?

choice /C:0123456789ABCDEF Specify text color:
set /A SRIFTAS=%errorlevel%-1It means "minus one". If you read the SET DOCUMENTATION -- type SET /? at the prompt -- you will see what SET /A means. Hint: A is for Arithmetic.




Thanks It subtracts one.

The logic is this:

1. User presses a key whose character is in this string: 0123456789ABCDEF

2. Choice.exe returns a value in %errorlevel% which is the position of this character from the start of this string. If the user presses 0 then the errorlevel will be 1 (because 0 is the first character in the string), if the user presses F then choice.exe will return 16 (because F is the 16th character).

3. You will notice that these VALUES are 1 more than the hex value represented by each character.

4. The parameters for the Color command start at 0 therefore you need to SUBTRACT 1 from %errorlevel%.





8692.

Solve : extracting compressed files & dropping them into a hot folder...Questions...?

Answer»

Hi all, new here and looking for some help. This looks like a great place for info.

I receive large compressed files on a server and need a batch to extract them from that source folder (called Prod) and drop them into a destination folder (hot folder) to be processed, also place a copy in an archive folder. Problem is, if another FILE starts to come in while this one is running, it is not extracted but is moved to the archive folder (because an incomplete file can't be axtracted). How can I only extract files that have completely arrived? I would just schedule this to run every hour or a few times a day, but I have no control over the arrival times of these files, they ARRIVE at random.

Below is what I have. It works fine except it if another file comes in while this is running it gets moved to the archive folder and is not processed.

Any suggestions??


REM ***** Turn display output to off
ECHO off
REM ***** Set set prompt to "CZExtractor> "
Prompt CZExtractor$G$S
REM *****
REM *****
REM ***** clear the window and set the window colors background to 1=Blue and foreground F=Bright White
CLS
Color 1F
REM *****
ECHO **********************************************************************
ECHO See CZExtractor-readme.txt for full details on this procedure
ECHO **********************************************************************
REM *****
REM ***** Set the environment variables for the SouRCe Drive and Directory
Set CZE-SRCDRV=Q:
Set CZE-SRCDIR=\Prod
REM *****
REM ***** Set the environment variables for the ARChive Drive and Directory
Set CZE-ARCDRV=Q:
Set CZE-ARCDIR=\temp
REM *****
REM ***** Set the environment variables for the DEStination Drive and Directory
Set CZE-DESDRV=W:
Set CZE-DESDIR=\VIPUSER8.7\spool\ps
REM *****
REM ***** Set the environment variables for root WoRKing Drive and Directory
Set CZE-WRKDRV=C:
Set CZE-WRKDIR=\"Program Files"\CZExtractor
REM *****
REM ***** append the directory path for WinRAR program into current path
path %path%;C:\Program Files\WinRAR
REM *****
REM ***** Change to the working Drive and Directory
%CZE-WRKDRV%
CD %CZE-WRKDIR%
REM *****
REM ***** check to see if DEStination directory is present, if not, then create it.
IF NOT EXIST %CZE-DESDRV%%CZE-DESDIR%\ MKDIR %CZE-DESDRV%%CZE-DESDIR%\
REM *****
REM ***** check to see if ARChive directory is present, if not, then create it.
IF NOT EXIST %CZE-ARCDRV%%CZE-ARCDIR%\ MKDIR %CZE-ARCDRV%%CZE-ARCDIR%\
REM *****
IF EXIST %CZE-WRKDRV%%CZE-WRKDIR%\files-in.txt REN %CZE-WRKDRV%%CZE-WRKDIR%\files-in.txt files-inlast.txt
REM *****
REM ***** create a file containing directory listing of the source directory
dir %CZE-SRCDRV%%CZE-SRCDIR%\*.gz /O:D /T:W > %CZE-WRKDRV%%CZE-WRKDIR%\files-in.txt
REM *****
REM ***** display the files that will be processed to the screen
ECHO **************************************************************************
ECHO The following files have been discovered and will be processed
ECHO **************************************************************************
%CZE-WRKDRV%%CZE-WRKDIR%\files-in.txt
ECHO **************************************************************************
ECHO **************************************************************************
REM *****
REM ***** Using WinRAR decompress all gz files within the SoURce directory
winRAR e -y %CZE-SRCDRV%%CZE-SRCDIR%\*.gz %CZE-DESDRV%%CZE-DESDIR%
REM *****
REM ***** create a file containing directory listing of the DEStination directory
dir %CZE-DESDRV%%CZE-DESDIR%\*.ps /O:D /T:W > %CZE-WRKDRV%%CZE-WRKDIR%\files-out.txt
ECHO **************************************************************
ECHO The following uncompressed files have been created
ECHO **************************************************************
REM %CZE-WRKDRV%%CZE-WRKDIR%\files-out.txt
REM *****
REM ***** DELETE all indx files within the DEStination directory
IF EXIST %CZE-DESDRV%%CZE-DESDIR%\*.indx DEL /Q %CZE-DESDRV%%CZE-DESDIR%\*.indx
REM *****
REM ***** Move all files from the SouRCe directory to the ARChive directory
IF EXIST %CZE-SRCDRV%%CZE-SRCDIR%\*.* MOVE %CZE-SRCDRV%%CZE-SRCDIR%\*.* %CZE-ARCDRV%%CZE-ARCDIR%\
REM *****
:End_Procedure
REM *****
REM ***** restore the original window colors
Color
REM EXIT


OK sorry, I think that just came across dumb. Absolutely no need to post all that.

After studying the winrar commands and switches and trying SEVERAL things, I came up with the following:

Winrar has a switch that would do what I need.

switch
-to
Process files older than the specified time period.

where I could enter 1h.

That should process files older than one hour. Simple. And in testing it works fine with .rar files. But it has no effect on tar.gz files. unfortunately I need to make this work with tar.gz files.Is there another solution or is there another utility I should be using? This is on a Server 08 platform...Quote

WinRAR
From Wikipedia, the free encyclopedia

WinRAR 3.93 in Windows 7
Developer(s) Eugene Roshal, Alexander Roshal
Initial release 1995
Stable release 4.00 (March 7, 2011; 1 day ago (2011-03-07)[1]) [+/−]
Preview release [+/−]
Development status Current
Written in C++
Operating system Windows 95, 98, Me, 2000, XP, VISTA, 7, Mac OS X, FreeBSD, Linux (Wine required for GUI), OS/2[2]
Available in Multilingual (46+ languages)
Type File archiver
License Commercial, Proprietary, Shareware
Website Primary: www.rarlab.com
Secondary: www.win-rar.com

WinRAR is a shareware file archiver and data compression utility developed by Eugene Roshal, and first released in autumn of 1993.[3] It is one of the few applications that is able to create RAR archives natively, because the encoding method is held to be proprietary.
If the shoe fits...
8693.

Solve : need help writing a batch file? somebody help please?

Answer»

This is for school...and I am confused on writing batch files......I NEED help please! Thanks
do I WRITE this batch file?
write a batch file named eFiles.bat that will (read all the criteria before beginning)
make a directory on USB drive named MyEfiles
copy all the files that begin with the letter E extension from the _Datafiles\DOS directory to the MyEfiles

Clear the screen in an appropriate place
be sure each command does not appear on the screen
add remarks that list your name, today's date, and purpose of the batch file
display a message telling the user what to expect - pause the screen to give user a chance to read the message
add blank lines where you believe will ehance the appearance of the screen.Thank you....ANOTHER question for you. copy the media subdirectories from DOS directory to the NewMedia directory in DOS

Is this the correct order:
@echo off
REM created by JOe STUDENT
cls
ECHO Please wait while this process completes
PAUSE
cd /d D:\1161_DataFiles\DOS
xcopy media\*.* newmedia /e /y >nulyou'll need to do your own homework. Sorrywhat a guy can't ask for a little help? Thanks tool...as I am sure YOU NEVER asked anyone to help you out with anything!Quote from: skers5xs on March 07, 2011, 05:58:25 PM

what a guy can't ask for a little help? Thanks tool...as I am sure YOU NEVER asked anyone to help you out with anything!
Nothing wrong with asking for help. You need to show you have done your best and only need just a little help. Doing it all for you does not really help you learn anything.Quote from: skers5xs on March 07, 2011, 05:58:25 PM
Thanks tool...

Way to get a ban... and no help at all...

Thanks for your input Salmon but I didn't get a banned.....and I did get help.... Quote from: skers5xs on March 08, 2011, 10:58:22 AM
I didn't get a banned...

It's early days...
Yes, it is early days....I need to lay off the sauce this early. What I meant to say was I haven't been banned yet! I will TRY my darnest to get banned though. Quote from: skers5xs on March 08, 2011, 01:30:38 PM
Yes, it is early days....I need to lay off the sauce this early. What I meant to say was I haven't been banned yet! I will try my darnest to get banned though.

You can say "*censored*" on here, I believe...
NICE!! Thanks for the heads up....
8694.

Solve : change remote FTP folder to type ZIP?

Answer»

Hello,

I am using mput to transfer multiple files from my local system to a remote FTP account. The files are dropped inside a folder like so:

Code: [Select]open ftp.abc.com
username
password
[b]cd \IMPORT\Files[/b]
PROMPT
mput *.xml
bye
ftp -n

So NOTICE the "Files" folder. What i want to do once the files have been transferred is to ZIP the folder to something like "ZipFiles.zip"..

Is this possible?

Kind regards,
BillyI was trying this, but doesnt seem to work, i get an invalid command:

Code: [Select]open ftp.abd.com
username
password
cd \IMPORT
prompt
"c:\Program Files\7-zip\7-zip.exe" zip *.xml xml.zip
mput *.zip
bye
ftp -n
Try zipping the files outside the FTP environment. You can put the FTP commands into a separate FILE, put the reference to 7-zip in a batch file, then reference the FTP script with the -s: SWITCH in that same batch file.

Batch file:
Code: [Select]@echo off
cd \IMPORT
"c:\Program Files\7-zip\7-zip.exe" zip *.xml xml.zip
ftp -s:ftpscript.txt

FTPscript.txt
Code: [Select]open ftp.abd.com
username
password
cd \IMPORT
prompt
mput *.zip
bye
ftp -n

Not sure if you need the FTP prompt command, but you can DECIDE that.

Good luck.

8695.

Solve : FTP Command line "prompt" not working as intended?

Answer»

Hello,

This is my FIRST piost so not quite SURE how helpful this forum will be

I am trying to upload multiple files from my local system to an external FTP account. I do this via a batch file, so i have upload.bat and ftp.txt.

upload.bat contains the following:

Code: [Select]cd C:
cd \Batch Files\awaiting
ftp -s:..\ftp.txt
move *.xml ..\processed

Then i have an ftp.txt which is this:

Code: [Select]open ftp.abd.com
username
password
cd \IMPORT\Files
prompt
mput *.xml
bye
ftp -n

I have MANY .xml files but only 1 is being uploaded although i have turned to prompt off which stops cmd asking me what i want to do.

Can anyone see where i am going WRONG?

I would really appreciate it if someone could assist.

Kind regards,

BillyI wonder if the MOVE is being executed while the ftp session is in progress ?
The ftp session finds a file and uploads it but by the time it returns all of the files have been moved out ?Quote

I wonder if the MOVE is being executed while the ftp session is in progress ?
The ftp session finds a file and uploads it but by the time it returns all of the files have been moved out ?

If that is the case, then you could just use start /wait .....
8696.

Solve : Add Full Control permission to domain group?

Answer»

Hi,

I'd like to MAKE a batch which will add full control to a Domain group in a list a folder.


I TRIED this command but it doesnt work.


@ECHO off
FOR /D %%i in (text.txt) do CACLS %%i /T /G DOMAINNAME\GG-SUPPORT-SN2:F


GG-Support is the name of my domain group

in the text.txt FILE there are names of the DIFFERENT folders in which I want to add the full control


Please help, I don't know what to do.

8697.

Solve : replace a line with another line?

Answer»

i have a script that gets a line number and i need t replace the line at that line number how would i do that?Let's see your script.
You have a script? Where? (I can't see it, although I'm staring real hard at the monitor!) The script "gets a line number"? Where from? And where is the line you WANT to replace? In a TEXT file? Of what format? Not enough information.
sorry i should have been more informative so ANYWAYS the user passes parameters like so Code: [Select]replace 3 b and if the text file data.dat contains
a
b
c
d
e
it would become
a
b
b
d
eSo when you wrote "I have a script" you really meant "I want a script"?
yesYou want a script completely written from scratch, with no input from yourself? Is this a homework project, or SOMETHING for work?
Ah, BillFish to the rescue...
Quote

You want a script completely written from scratch, with no input from yourself? Is this a homework project, or something for work?
this is not a homework project nor from work (im 14)i just had no idea how to do this but bills solution actually worked
8698.

Solve : Stop searching after file is found?

Answer»

How could I make my batch stop LOOKING for a file once it has found it?

What I mean is I have this code:

Code: [Select]@echo off
echo Type in the name of the file you want to find and delete with the extension
echo.
set /p name=
cd\
del %name% /s /p

Now it works fine, but once it prompts you on whether you want to delete the file or not (and you answer "yes") it will delete the file BUT keeps on searching for more files with that name.
Is there anyway to stop this?

So that RIGHT when it deletes the file, it will stop searching?

Thanks.Quote from: fish on March 14, 2011, 01:46:04 PM

Why stop the search after one find?
Because it's time consuming.

Quote
If the file is dangerous all copies should be found.
Yes. With an actual malware utility dangerous files can be found. However since they are USING a batch file they probably aren't trying to write their own malware scanner, because that would be foolish. Additionally, they make no implication that they are, or that the file's they are trying to find are "dangerous".

EDIT: GUESS I may as well ADDRESS the Original Post

you'd would need to not use del /s; instead you would basically need to roll your own routine and search for files yourself. I think maybe FORFILES or a for switch could be used for that. (for /f perhaps)



something like this would do it...

set filename=find this file.txt
for /f "delims=" %%F in ('dir /b /s "%filename%"') do (
del "%%F"
goto jump
)
:jump
echo done

I see Billfish is still around...

Quote from: Salmon Trout on March 14, 2011, 02:20:22 PM
something like this would do it...

set filename=find this file.txt
for /f "delims=" %%F in ('dir /b /s "%filename%"') do (
del "%%F"
goto jump
)
:jump
echo done

I see Billfish is still around...

Wow thank you so much! Works perfectly
8699.

Solve : Delete folder named yesterdays date?

Answer»

yea i am logged in with enough PERMISSIONS, but if %date% is a system variable then how does
FOR /F "TOKENS=1* DELIMS= " %%A IN ('DATE/T') DO SET CDATE=%%B
For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set date=%%a %%b)
format it from
Wed 03/16/2011
to
03 16
?Is this folder "C:\testing\%yesterday%" actually empty?

My remark about using a variable NAMED %date% was intended as a GENERAL observation, it clearly doesn't matter in this case, but it is generally safer not to overwrite system variables.



ah ok, and no it has FILES in it, and they all need to be deleted

8700.

Solve : Run an application job using batch script?

Answer»

Hi,

Iam new to scripting, Sorry if iam asking a very basic question.

I have an application which has an option in File Menu --> Run Job , But i want to run this using batch script.

I have written in the script as

" Start test_batch.ace" which just opens the application but the job is not running.

I want the batch script to run the job.

I will need your HELP in writing the script.

Thanks,
VinodQuote from: vinods_09 on March 17, 2011, 12:32:09 PM

I have an application which has an option in File Menu --> Run Job

I have attempted to find the name of this application using telepathy but I have had no success. Therefore please divulge.
could SOMEBODY remove samwall/billrich's irrelevant post?
Hi,

In Command " Start Test_PS.ace " Test_PS.ace is the application job, if i run the command it's just OPENING the application and not running the job. I need to run the job .

Your help is very MUCH appreciated.

Thanks,
VinodIs the application WinAce?