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, |
|
| 8652. |
Solve : Issue with Replacable Parameters? |
|
Answer» The batch below is one for a school assignment. 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. |
|
| 8654. |
Solve : Using AND condition in DOS script causes trouble.? |
|
Answer» In a batch file I have |
|
| 8655. |
Solve : Search for multiple strings using batch? |
|
Answer» I have the following code |
|
| 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. 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. |
|
| 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. |
|
| 8659. |
Solve : Userprofile desktop folder contents? |
|
Answer» Hello CH members 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/126855look 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 accessThis 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 addressWHy 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 songAsserting 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.]Quote graveur sataHow 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).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.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 gigabytesATA-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 0 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 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. |
|
| 8663. |
Solve : Batch Problem? |
|
Answer» Hi, If I correctly understand what you are attempting to achieve, the following should work: 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 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 |
|
| 8666. |
Solve : net use time out? |
|
Answer» I want to connect to a network location and have this displayed as a drive letter S:. |
|
| 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? |
|
| 8669. |
Solve : Bach file for internet explorer? |
|
Answer» Hi all |
|
| 8670. |
Solve : syntax for info from registry? |
|
Answer» Hi all, type '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 typeOn 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? 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 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 |
|
| 8672. |
Solve : Control LCD Projector with a Batch File? |
|
Answer» Hello all, 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 & 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- |
|
| 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: |
|
| 8675. |
Solve : DOS environment variable? |
|
Answer» I try to store a file sequence NUMBER in an ENVIRONMENT variable. 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 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 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, -REQUESTS |
|
| 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. |
|
| 8680. |
Solve : DOS program, run on Linux using WINE? |
|
Answer» Hi, I have a question, 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, 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: |
|
| 8683. |
Solve : minimize to system tray? |
|
Answer» hello there! 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. |
|
| 8685. |
Solve : substring indexing? |
|
Answer» I try to INSERT a SEQUENCE number into a file name 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:
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" " 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, 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... 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 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 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. 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. 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. 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 ? |
|
| 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. WinRARIf 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 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, |
|
| 8695. |
Solve : FTP Command line "prompt" not working as intended? |
|
Answer» Hello, I wonder if the MOVE is being executed while the ftp session is in progress ? If that is the case, then you could just use start /wait ..... |
|
| 8696. |
Solve : Add Full Control permission to domain group? |
|
Answer» Hi, |
|
| 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 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? 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... 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 |
|
| 8700. |
Solve : Run an application job using batch script? |
|
Answer» Hi, 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? |
|