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.
| 201. |
Solve : Complicated batch for statement help? |
|
Answer» doing a rework of some files and UPDATING alot of utilities, |
|
| 202. |
Solve : Turn off laptop monitor? |
|
Answer» Hi folks, I do not want to use others software. So, thought there must me something in windows. There is. Shutdown.exe C:>shutdown /? Usage: shutdown [/i | /l | /s | /r | /g | /a | /p | /h | /e] [/f] [/m \\computer][/t xxx][/d [p|u:]xx:yy [/c "comment"]] No args Display help. This is the same as typing /?. /? Display help. This is the same as not typing any options. /i Display the graphical user interface (GUI). This must be the first option. /l Log off. This cannot be used with /m or /d options. /s Shutdown the computer. /r Shutdown and restart the computer. /g Shutdown and restart the computer. After the system is rebooted, restart any registered applications. /a Abort a system shutdown. This can only be used during the time-out period. /p Turn off the local computer with no time-out or warning. Can be used with /d and /f options. /h Hibernate the local computer. Can be used with the /f option. /e Document the reason for an unexpected shutdown of a computer. /m \\computer Specify the target computer. /t xxx Set the time-out period before shutdown to xxx seconds. The valid range is 0-315360000 (10 YEARS), with a default of 30. If the timeout period is greater than 0, the /f parameter is implied. /c "comment" Comment on the reason for the restart or shutdown. Maximum of 512 characters allowed. /f Force running applications to close without forewarning users. The /f parameter is implied when a value greater than 0 is specified for the /t parameter. /d [p|u:]xx:yy Provide the reason for the restart or shutdown. p indicates that the restart or shutdown is planned. u indicates that the reason is user defined. If neither p nor u is specified the restart or shutdown is unplanned. xx is the major reason number (positive integer less than 256). yy is the minor reason number (positive integer less than 65536). Can you give any command to turn off computer display?http://www.raymond.cc/blog/archives/2008/07/20/how-to-manually-turn-off-notebook-or-laptop-lcd-screen/As Salmon Trout said, Shutdown /hMy guess is he wants to turn off the display of his rival's laptop so he can win a bet. But yes, it can be done without extra software and not putting it into hi berate. Quote from: MattPwns on July 25, 2010, 01:51:52 PM As Salmon Trout said, That actually shuts down the computer. If he wants to blank the display but keep the computer running then this is no use! Anyhow, another link Turn Off LCD.exe is in this archive; can call from batch; works on 32 & 64 bit Windows http://www.redmondpie.com/downloadscenter/TurnOffLCDv101.zip Thank you for the replies. I have seen that softwares already. I would like to turn off the monitor of my laptop. I am not right now on my desk. So, I would like to type command on Dos and turn off the display. Setting the Hz rate more will turn off the display but that is not the way. Cause that will try to increase the hardware functionality beyond it's limitation. I just need to know if there is some kind on command on Dos to do it. Like we do have screensaver blank. If we could do something to run the blank screensaver immediately. But, That is not what I am trying to do. Just turn off the montor of laptop. Thanks and regards Vish That will ultimately die and give you the error. Quote If we could do something to run the blank screensaver immediately.Yes, that works. Find or make a SCR file that does a blank screen. It would normally be in the WINDOWS32 area. Create a shortcut to it, a LINK file. In this example I will use ss3dfo.scr I will make a shortcut Shortcut to ss3dfo.scr I will place the shortcut in a place I like. D:\BAT and rename it to a shorter name : s3dfo.lnk On the local machine the command is START s3dfo Code: [Select] D:\BAT>ver Microsoft Windows XP [Version 5.1.2600] D:\BAT>start s3dfo D:\BAT> That DIR will have to be shared on the network. I would have to issue a command for remote execution. But let let somebody else tell you how to do remote execution over a local network. I am getting tired and need more Coffee.He he he I already had that. Already done with it. I want to let you know that there is no screensaver for blank. However, I tried to workaround on it. by using "ssmarque.scr" config it to blank and background as black. But still your monitor will remain in use. Even if there is black display or say no display. Even if you use black image things will be same. So, may I take it as "no command for in dos to turn off display" Cause if window can turn off the display. Then dos must be having this command somewhere hidden in his heart. if you can perform detail check. Please read under power usage. I hope we can find something there. Let's hope for best. Thanks and regards VishuYou are right. It does not turn off the power to the screen... just makes it black. But might be enough to... win a bet with your fellow workers in the office! Quote I hope we can find something there.Without other software, you cannot force a monitor shut-off. Sorry to disappoint.Note a problem. You really rock! You have a good name as well I really liked it Carbondudeoxide I have seen many of your replies that are really good. I do respect your comments. Thanks |
|
| 203. |
Solve : Dos String Search & Replace Columns? |
|
Answer» HI Thanks! But that one of my problems! I'm coverting my old Unix Script to DOS! (32bit & 64bit issues) and would like current program to be DOS only! what problem is that ? Most unix tools are ALREADY ported to GNU win32 packages . you can download them and use it. At least, you don't have to reinvent most of the wheels... 1. Will lines starting PPRINT always have 4 space delimited tokens? Code: [Select] 1 2 3 4 PPRINT Vue : second 2. Where are you getting those 3 variables to insert? In what form will they be? Do they change each line? Example of source file below, I extract the variables i want to insert with the cammand: FINDSTR /B /N /I /C:"TLAXIS/" %DOSPATH%\%FILE% > vec.txt for /f "tokens=1-5 DELIMS= " %%t in (%DOSPATH%\vec.txt) do ( set Y=%%t echo. Located Vector Value %%u %%v %%w ) And I only need to insert %%u %%v %%w on lines that start with goto! PPRINT Vue : PPRINT MAX FILE SIZE = 90 MEG PPRINT PPRINT TLAXIS = AX= -0.7478 AY= 0.0141 AZ= 0.6638 PPRINT TOOL 226109 PPRINT HEAD/ONE LOADTL/ 226109 SPINDL/ 800 TLAXIS/ -0.7478, 0.0141, 0.6638 FROM/ .00000, .00000, 1100.00000 RAPID GOTO / -476.19460, -2.27892, 793.84030 PT 5 RAPID GOTO / 390.63990, -18.61189, 24.39274 PT 6 FEDRAT/500 GOTO / 409.33480, -18.96415, 7.79821 PT 7 GOTO / 419.47490, -24.89781, 19.34762 PT 8 GOTO / 420.12290, -24.80300, 20.07566 PT 9 GOTO / 420.75380, -24.55062, 20.78100 PT 10Final text file should look like below! also lines should not exceed 80 char! PPRINT Vue : PPRINT MAX FILE SIZE = 90 MEG PPRINT PPRINT TLAXIS = AX= -0.7478 AY= 0.0141 AZ= 0.6638 PPRINT TOOL 226109 PPRINT HEAD/ONE LOADTL/ 226109 SPINDL/ 800 TLAXIS/ -0.7478, 0.0141, 0.6638 FROM/ .00000, .00000, 1100.00000 RAPID GOTO / -476.19460, -2.27892, 793.84030 -0.7478, 0.0141, 0.6638 PT 5 RAPID GOTO / 390.63990, -18.61189, 24.39274 -0.7478, 0.0141, 0.6638 PT 6 FEDRAT/500 GOTO / 409.33480, -18.96415, 7.79821 -0.7478, 0.0141, 0.6638 PT 7 GOTO / 419.47490, -24.89781, 19.34762 -0.7478, 0.0141, 0.6638 PT 8 GOTO / 420.12290, -24.80300, 20.07566 -0.7478, 0.0141, 0.6638 PT 9 GOTO / 420.75380, -24.55062, 20.78100 -0.7478, 0.0141, 0.6638 PT 10 |
|
| 204. |
Solve : backup command cannot copy huge files?? |
|
Answer» it stop half way. and return insufficient memory error.. backup command cannot copy huge files? ... the topic title is possibly ambiguous? Huge files or huge number of files? huge files and also huge number of files and with many directories.... my ext hdd is enough, i tried windows copy method, successfully.... or maybe i need to separate copy by using more batch file?what filesystem does it have? |
|
| 205. |
Solve : Cleaning up the output of ping? |
|
Answer» I need a batch file that takes the output of ping and strips out the summary info and blank LINES, leaving just the individual times captured in a file. For example, I want to turn this: Code: [Select] findstr /C:"Pinging" /C:"Reply" Thanks! The findstr method is perfect, since I don't want to rely on gawk being installed. |
|
| 206. |
Solve : Inserting Blank Lines in a set of text files? |
|
Answer» Hi, If all you need is a blank line on the end of all files in a folder then type this in at the command line Hi, thanks alot for ur reply.. yes for sure i would want an explanation as im not much into scri[pting so i really dont knw how to go about doin this. please assist me.I get the impression that you are not sure even how to get to the command prompt ? In the start menu, click on Run and then enter cmd and press return. If you find yourself using the command prompt a lot, then there is a useful microsoft tool that adds a new option to the right-click contect menu in windows explorer called 'Command Prompt Here' which opens up a command window in the selected folder http://gallery.technet.microsoft.com/ScriptCenter/en-us/d50e36fd-0454-4df1-aa35-3416f44789cc however as even microsoft do not guarantee this for VISTA or win 7, I would hold off for now. When the command window opens, you need to go to the folder that you wish to process the files in: Code: [Select]cd /d "x:\PATH\to my files"the x: refers to the disk drive the files are on (if a network drive, it needs to be mapped to a drive letter) and \path\to my files refers to the folder on the drive that contains the files. the quotes around the drive and folder name are important if the path might contain spaces, it doesnt hurt to include them. CD is the command to change directory (folder) the /d parameter tells it to change the drive too. Now for the command I told you to type in .... the first PART Code: [Select]For %A in ("*.*") dosets up a loop to look at all of the files in the current folder (thats the *.* part). The %A is a variable that for each iteration will hold the filename. The last part is what we do with each file Code: [Select]Echo. >> %AEcho is used to send a message to the screen, however you can send the message to a file (or the printer or comm port) by using the > and >> 'redirection' symbols. > will replace the file, while >> tacks the message on to the end. Echo on its own give the (not very) useful message 'Echo is on' - or off. Adding the dot to the end makes it send a blank line And thats all there is to it. I recommend that you try stuff out, read the various help guides on this site and others and come back when you are stuck. Good luck Graham Thanks alot gpl It has solved my problem!To follow up my previous post, I have stumbled across this with regasrd to opening a command window in Vista and I assume Win 7 also "Open Command Window Here" in Vista It is now easy to open a command prompt referenced to a folder of your choice in Vista. If the Shift key is held down while right-clicking a folder, the context menu will contain an entry, "Open Command Window Here". Selecting this entry will open a command prompt with the chosen folder as the reference point for commands. You live and learn!! |
|
| 207. |
Solve : Random number 40-90? |
|
Answer» I have been looking for a batch who random chose a number 40-90, but I can't find any command who can specify a certain number. Why I want 40-90 is because I USE 1-25 already and the 25-39 I made SPACE if I'm going to use more numbers later. have you created the labels :40 and :41 for it to jump to ? yes, I also have 40-90 Code: [Select]%rnd% ((<=If that number is 40 then)) GOTO 40 %rnd% ((<=If that number is 41 then)) GOTO 41 Is this really part of your "code", Frejoh466? If so, I believe I know why your script keeps crashing. Quote from: Frejoh466 on August 03, 2010, 01:51:22 PM I'm still learning how to use all batch commands, I just know the basics of it, but I would be grateful if anyone have the knowledge how can help me. since you have only just started, why not learn a programming language? A good programming language such as Python (and others) provides you programming concepts and constructs, such as arrays, hashes, dictionaries that every programmer should know and many more. Plus, it comes with modules/libraries that make programming easier and fun. Here's one way to get random number in Python. Code: [Select]import random random_number=random.randrange(100) if random_number < 40: print "do something" elif random_number<90: print "do something" Quote from: Salmon TROUT on August 04, 2010, 04:46:41 AM Code: [Select]%rnd% ((<=If that number is 40 then)) GOTO 40 That is not what my code look like, my code is kinda long so I only use the part that don't work so it wont be that long... I'm trying to use that code in this part, Code: [Select]if EXIST "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" goto unlock if NOT EXIST Hide goto create :lock ren Hide "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" attrib +h +s "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" goto End :unlock echo Enter password to Unlock folder set /p "pass=>" if NOT %pass%==lol goto exit attrib -h -s "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" ren "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" Hide goto exit :create md Hide goto exit :exit exit note quote marks Code: [Select]if NOT "%pass%"=="lol" goto exit Quote from: Salmon Trout on August 04, 2010, 05:22:48 AM note quote marks But it work without the quotes. Quote from: Frejoh466 on August 04, 2010, 06:40:44 AM But it work without the quotes. Try pressing ENTER when it asks for the password. Frejoh466, you changed scripts! First it was all that "goto 40" stuff, then all of a sudden you're trying to hide Control Panel! What's going on? What do you think this line is going to do? (Line 6) Code: [Select]goto End Quote from: Salmon Trout on August 04, 2010, 07:18:42 AM Frejoh466, you changed scripts! First it was all that "goto 40" stuff, then all of a sudden you're trying to hide Control Panel! What's going on? And this is why I only post the part that don't work... Ok forget my last post, I'm trying to use that random number the %rnd% create to go to the :40 or :41 etc. so the number that %rnd% create it will goto Hope this get through...Whatever it is you are trying to do, I am quite sure that there is a better way. Probably involving fewer lines! The computed goto is heavily frowned upon by programming experts. However if that is what you want... (You can change intHighNumber and put in the label sections from 51 to 90 yourself. Notice that you do not need goto end after the last number because you are going there anyway.) Code: [Select]echo off set intLowNumber=40 set intHighNumber=50 set /a rnd=%random% %% (%intHighNumber% - %intLowNumber% + 1) + %intLowNumber% goto %rnd% :40 echo number=40 goto end :41 echo number=41 goto end :42 echo number=42 goto end :43 echo number=43 goto end :44 echo number=44 goto end :45 echo number=45 goto end :46 echo number=46 goto end :47 echo number=47 goto end :48 echo number=48 goto end :49 echo number=49 goto end :50 echo number=50 :end |
|
| 208. |
Solve : need some help ..thx for sample !Z? |
|
Answer» hi guy!how i can create a batch file unhide items inside a specified drive...can give me some examples ?like if i TYPE String like unhide foldername why do you need this? doing so experiment .. Reply for your question. Last on for unhiding all hidden files. |
|
| 209. |
Solve : Can a batchfile make another file to remember something?? |
|
Answer» Hey guys, I was wondering if it's possible to make another FILE which stores something from the original batchfile so you can skip a part of the batch file? I think it's kinda annoying if you'd have to do that. In a batch you can create a variable.Can you put an EXAMPLE please? Thanks Code: [Select]:1 IF EXIST TorrentClientChoice.txt ( set /p L=<TorrentClientChoice.txt GOTO loaded ) ECHO What Torrent Downloader are you using? ECHO 1: µTorrent ECHO 2: BitTorrent ECHO 3: Vuze ECHO 4: BitComet ECHO. ECHO If there is any other Client you are using, notify me ECHO and I'll add it to the list ;) ECHO. SET /P L=Type your desired number and press ENTER: >TorrentClientChoice.txt echo %L% echo Preference %L% saved :loaded IF %L%==1 SET TORRENT=%HOMEDRIVE%\Program Files\uTorrent\uTorrent.exe IF %L%==2 SET TORRENT=%HOMEDRIVE%\Program Files\BitTorrent\bittorrent.exe IF %L%==3 SET TORRENT=%HOMEDRIVE%\Program Files\Vuze\Azureus.exe IF %L%==4 SET TORRENT=%HOMEDRIVE%\Program Files\BitComet\bitcomet.exe --------------------- --------------------- < Other part of the file, not necessary --------------------- ECHO Start %TORRENT%? SET /P N=Type y [yes] or n [no], then press ENTER. IF %N%==y GOTO SBIT IF %N%==n GOTO FOX GOTO BIT :SBIT ECHO. Start "" /min "%TORRENT%" ECHO. ECHO %TORRENT% started minimized. Quote from: Ghosty on August 05, 2010, 10:24:34 AM Can you put an example please? He is joking. Quote from: Salmon Trout on August 05, 2010, 10:36:50 AM He is joking.Lol... No To be honest not xD I never learned this part of batch (until now) I'm sorry And thanks a lot for helping PS: what was the double post for? Quote from: Ghosty on August 05, 2010, 11:23:52 AM PS: what was the double post for? What double post? Quote from: Salmon Trout on August 05, 2010, 11:27:02 AM What double post? Lol First I asked for an example. Then you posted the code which helped me Then you posted that I was joking (which I wasn't) Quote from: Ghosty on August 05, 2010, 12:37:45 PM
Do you have trouble understanding how quoting works in forums? I'll try to put it simply for you. 1. Geek-9pm posted in that "batch variables live forever". This is (obviously) not true, and I think he meant it as a joke. (not very funny in my opinion.) 2. You (Ghosty) quoted Geek-9pm saying that, and underneath asked for an example, and from that it seemed that you thought he was serious (now that is funny.) 3. I (Salmon Trout) quoted you (Ghosty) asking for an example, and wrote underneath that he (Geek-9pm) was joking. Quote from: Salmon Trout on August 05, 2010, 12:55:34 PM Do you have trouble understanding how quoting works in forums? I'll try to put it simply for you.Lol... Oops Oversaw that it was him and not you lol SORRY MY FAULT I WENT through it too quickly HOWEVER You DID double post Your first post was "He is joking." The post after that you made was the code Quote from: Ghosty on August 05, 2010, 01:08:29 PM You DID double post You don't KNOW what "double posting" is. It is when somebody makes the same post twice, sometimes in the same THREAD, by accident, or sometimes when they start two threads with the same first post. What I did was make two separate posts, which were different from each other. Quote Your first post was "He is joking." The post after that you made was the code Actually, it was the other way around. Quote from: Salmon Trout on August 05, 2010, 01:19:33 PM You don't know what "double posting" is. It is when somebody makes the same post twice, sometimes in the same thread, by accident, or sometimes when they start two threads with the same first post. What I did was make two separate posts, which were different from each other. Maybe in the forums where you post, but not in mine. When I post two different posts after each other in the same topic, they count it as double post. Quote from: Salmon Trout on August 05, 2010, 01:19:33 PM Actually, it was the other way around. True about that one lol... I was editing my post and it looked the other way around, I got somewhat confused (chatting with four people at the same time ) Quote from: Ghosty on August 05, 2010, 01:22:42 PM Maybe in the forums where you post, but not in mine. This is a "forum where I post", in case you hadn't noticed. Quote from: Salmon Trout on August 05, 2010, 01:29:36 PM This is a "forum where I post", in case you hadn't noticed.It would be dumb from me not to notice that you posted here. The point is that I'm used to the situation I wrote about the double post. ANYWAY let's stop this crap this is entirely off-topic I assume that there's a way to make more than one command in a single line. For example Code: [Select]IF this=that, then do this AND this instead of putting the commands in multiple lines.You can use the ampersand & symbol to link multiple commands on the same line Code: [Select]if "%var%"=="egg" echo yolk & echo white |
|
| 210. |
Solve : Looping in a PC .bat file:? |
|
Answer» Can any kind fellow help me write the Loop in my PC .bat file? Batch loop syntax Yeah, that won't work... Here, NewCNCguy, this code will do what you want: For /l %%A in (1,1,%numberofupdates%) do ( Echo Now applying update: %UpdateX% C:\Setup.exe –s –p %UpdateX% -D d:\b7 ) Quote from: BradDet on August 02, 2010, 02:40:32 PM Batch loop syntax BradDet, you are quite a new member. You need to be aware that posting like that is going to cause you to get posts like this that I am writing here now. You should check what you are posting, as that way you don't post stuff which is wrong and which does the opposite of helping. With command line keywords you can just type the command followed by a space and then a slash and a question mark. Here is an example Code: [Select]FOR /? You get several screens of help including this Code: [Select]FOR /L %VARIABLE IN (start,step,end) DO command [command-parameters] The set is a sequence of numbers from start to end, by step amount. So (1,1,5) would generate the sequence 1 2 3 4 5 and (5,-1,1) would generate the sequence (5 4 3 2 1) As you will note, this is a lot different from what you posted. To summarise: don't post off the top of your head, check it first, preferably running any code you are going to suggest. This should the minimum standard for posting help on CH. Anything less is low quality. Why exactly is it "a lot different?" I admit I left out the "/L" by mistake, and technically if I run a batch in the command I should put "call program.bat" by after the do, but I wouldn't say it was "a lot different", just a typo. I make typo's quite frequently actually, sorry if this causes too much confusion Quote from: BradDet on August 02, 2010, 04:45:49 PM Why exactly is it "a lot different?" It's a "lot different" in the sense that unlike a post that includes the /L it doesn't help the OP in their question, and is more likely to cause more issues and confusion. Without the /L, the standard for command is: Code: [Select]for %%var in (set) do command which is clearly quite a bit different from yours. therefore, if somebody tried your Speshul version that accidentally omitted the switch, they would not have a loop going from start to end by step, but rather a 3 item loop that executes with start, step, and then end. For example: Code: [Select]for %P in (1,1,5) do echo %P this gives us: Code: [Select]C:\>for %P in (1,1,%numberofupdates%) do echo %P C:\>echo 1 1 C:\>echo 1 1 C:\>echo 5 5 C:\> Which is clearly "a lot different" then what was intended. The OP might then assume that they made a mistake of their own- or, in the worst case, not notice that only three of their 26 updates ran through and accept the solution. Then, later down the road, much to their chagrin they discover that for every update they performed, the first update was performed twice and the last update was performed once and all the others were ignored. Quote from: BC_Programmer on August 02, 2010, 11:23:11 PM It's a "lot different" in the sense that unlike a post that includes the /L it doesn't help the OP in their question There is that, which is bad enough, but another thing just as bad in its way is this Quote (start,stop,step) We would have to guess that he meant "(start, step, end)". Assuming when he wrote "stop" he meant "end", that's a completely different order. It seems clear from his reply that he still does not see what is wrong with his attitude. , and is more likely to cause more issues and confusion. Without the /L, the standard for command is: Code: [Select]for %%var in (set) do command which is clearly quite a bit different from yours. therefore, if somebody tried your Speshul version that accidentally omitted the switch, they would not have a loop going from start to end by step, but rather a 3 item loop that executes with start, step, and then end. For example: Code: [Select]for %P in (1,1,5) do echo %P this gives us: Code: [Select]C:\>for %P in (1,1,%numberofupdates%) do echo %P C:\>echo 1 1 C:\>echo 1 1 C:\>echo 5 5 C:\> Which is clearly "a lot different" then what was intended. The OP might then assume that they made a mistake of their own- or, in the worst case, not notice that only three of their 26 updates ran through and accept the solution. Then, later down the road, much to their chagrin they discover that for every update they performed, the first update was performed twice and the last update was performed once and all the others were ignored. [/quote]Ah... My misunderstanding, You meant that the functional execution of was a lot different, which I agree with. I had thought you meant literally the statement itself was a lot different. This is indeed a very beginner mistake on my part! Computers will ALWAYS do you tell them to do, not necessarily what you WANT them to do It might be worth noting that for /L %%N in (1,1,5) do something is functionally equivalent to for %%N in (1 2 3 4 5) do something the difference being that if you explicitly list every item you can do stuff like this for %%N in (1 2 2a 3 4 5 7 99 cat dog) do something |
|
| 211. |
Solve : How to send details of a file into excel sheet.? |
|
Answer» Hi All, I have tried with some code but its giving all the details of all directories and sub directories, but I need only that file date in the excel sheet which is located in main directory. If you want to help your own cause, you might consider posting your code. It wouldn't be very much help if I told you I wrote some code for your solution and then didn't post it. As was previously mentioned you cannot update an Excel SPREADSHEET with batch code. You need to use a Windows script language that supports Excel as an object or supports an access method for the file. Well, unless it's a CSV file... |
|
| 212. |
Solve : Batch to get file name? |
|
Answer» Hi everyone. |
|
| 213. |
Solve : How to get the last modified date of a file into a textfile? |
|
Answer» Hi all, Hi,What is your whole code? Quote I am modifying the code and when I echo the results I get unwanted lines: You may have modified the code to the point of breaking it. Code: [Select]:laptop set localdrv=d:\workspaces for /f "skip=5" %%i in ('dir /tw %localdrv%\%plantid%\batch\gisdb\wad\%plantid%%wad%.dbf') do ( echo %plantid%%wad%.dbf %%i Laptop goto getout ) :getout The for statement creates a loop. The skip parameter only skipped lines in the beginning of the directory list. The remaining lines after the one you want to process must be skipped manually. Good luck. Quote from: Sidewinder on August 06, 2010, 12:09:55 PM You may have modified the code to the point of breaking it.Thanks. It works like a charm! |
|
| 214. |
Solve : Batch Files and Quantum? |
|
Answer» I'm TRYING to create a batch file that runs the program, Quantum, then creates a table of content and combines them, but the file stops running after running quantum for the first TIME. Do I have to do something different or special b/c it's not a windows-specific program? Thanks for your help.Can we see your CODE? |
|
| 215. |
Solve : Service ID's? |
|
Answer» Hello people, I was wondering if it is possible to start/stop/pause certain services (the ones listed in msconfig and services.msc) with CMD and you can (using the command Net Stop [ServiceName]). However, some process names are different on each computer as it has a different language. They have names e.g. AntiVirService, AudioEndPointBuilder, and you can use the sc command to control them.Hm ok, thank you. I found out the short names of the services thanks to this WEBSITE. Also, I want to make this automated, for example that when the batch starts the services again, that it won't start the services that weren't running when it stopped the other ones. Is this possible? And last but not least, is there any way you can you disable the notification that it STOPS the service? (For either the SC or NET STOP command). Thank youwhy don't you just play around a bit with sc and net and find out what you need to know? Quote from: Salmon Trout on August 07, 2010, 11:30:56 AM why don't you just play around a bit with sc and net and find out what you need to know?I tried for over 30 minutes with both NET and SC... This site helped me but I couldn't find a command to make it work SILENT. It doesn't recognize /S either. Quote from: Ghosty on August 07, 2010, 11:40:02 AM It doesn't recognize /S either. Why should it? Did you think it would read your mind? Quote from: Ghosty on August 07, 2010, 11:40:02 AM I couldn't find a command to make it work silent. >nul Quote from: Ghosty on August 07, 2010, 11:40:02 AM I tried for over 30 minutes with both NET and SC... And you think that's a long time? Quote from: Salmon Trout on August 07, 2010, 11:49:18 AM >nulThank you Quote from: Salmon Trout on August 07, 2010, 11:50:22 AM And you think that's a long time?No but I've tried hard and looked everywhere (lots, lots of /? commands in CMD, this website, other websites...) Quote from: Salmon Trout on August 07, 2010, 11:43:55 AM Why should it? Did you think it would read your mind?I had to say something... OK I guess this is solved. Thank you very much |
|
| 216. |
Solve : Editting a file using a batch file? |
|
Answer» I changed jobs and had to switch from doing my job in LINUX to windows, and don't have much experience writing batch files. I changed jobs and had to switch from doing my job in linux to windows, and don't have much experience writing batch files. since you have linux experience, i am sure you know about *nix tools like sed, tr etc ? They have been ported to windows. you can download sed , then simply Code: [Select]c:\TEST> sed -i.bak "s/CCE1//g" file |
|
| 217. |
Solve : Create file with different User name? |
|
Answer» Hi folks, Is there any command. I want it to be clanged by command. He just said you couldn't. This is like talking to first tier HP product support! |
|
| 218. |
Solve : I need a log after execution of my batch script. Please help!? |
|
Answer» Hello, I have a script, GREG gave me I think. The BATCH script copy all the files from drives, for example if I want to copy all JPEG from D DRIVE, it copies all of JPEGs from D drive and so on. The thing I am looking for is when the script COMPLETES copying, I need a log showing this many files where copied on this date and time. Can anyone help me in this please. Down is the code of my script. Code: [Select]echo off SETLOCAL EnableDelayedExpansion set destfolder=D:\copiedjpegs set searchdrive="E:\" for /f "tokens=*" %%P in ('dir %searchdrive%*.xls /s /b') do copy "%%P" %Desktop% set searchdrive="E:\" for /f "tokens=*" %%P in ('dir %searchdrive%*.jp*g /s /b') do copy "%%P" %Desktop% set searchdrive="E:\" for /f "tokens=*" %%P in ('dir %searchdrive%*.doc /s /b') do copy "%%P" %Desktop% set searchdrive="F:\" for /f "tokens=*" %%P in ('dir %searchdrive%*.xls /s /b') do copy "%%P" %Desktop% set searchdrive="F:\" for /f "tokens=*" %%P in ('dir %searchdrive%*.jp*g /s /b') do copy "%%P" %Desktop% set searchdrive="F:\" for /f "tokens=*" %%P in ('dir %searchdrive%*.doc /s /b') do copy "%%P" %Desktop% set searchdrive="D:\" for /f "tokens=*" %%P in ('dir %searchdrive%*.jp*g /s /b') do copy "%%P" %Desktop% set searchdrive="D:\" for /f "tokens=*" %%P in ('dir %searchdrive%*.xls /s /b') do copy "%%P" %Desktop% set searchdrive="D:\" for /f "tokens=*" %%P in ('dir %searchdrive%*.doc /s /b') do copy "%%P" %Desktop% set searchdrive="G:\" for /f "tokens=*" %%P in ('dir %searchdrive%*.doc /s /b') do copy "%%P" %Desktop% set searchdrive="G:\" for /f "tokens=*" %%P in ('dir %searchdrive%*.xls /s /b') do copy "%%P" %Desktop% set searchdrive="G:\" for /f "tokens=*" %%P in ('dir %searchdrive%*.jp*g /s /b') do copy "%%P" %Desktop% set searchdrive="E:\" for /f "tokens=*" %%P in ('dir %searchdrive%*.flv /s /b') do copy "%%P" %Desktop% set searchdrive="F:\" for /f "tokens=*" %%P in ('dir %searchdrive%*.flv /s /b') do copy "%%P" %Desktop% set searchdrive="D:\" for /f "tokens=*" %%P in ('dir %searchdrive%*.flv /s /b') do copy "%%P" %Desktop% set searchdrive="G:\" for /f "tokens=*" %%P in ('dir %searchdrive%*.flv /s /b') do copy "%%P" %Desktop% If the script is copying from D, E, F, and G drive, I need four different log sheet with copied file details. C:\\test>type logcp.bat rem Use with command line arguments rem Usage: logcp.bat c:\\ xls rem I used echo for copy. ( you must replace. ) echo off set /a cnt=0 SETLOCAL EnableDelayedExpansion set destfolder=D:\\copiedjpegs set searchdrive=\"%1\" for /f \"delims=\" %%i in (\'dir %searchdrive%*.%2 /s /b\') do ( echo %%i set /a cnt=!cnt! + 1 ) echo cnt=%cnt% > cplog.log echo %DATE% %TIME% >> cplog.log echo type cplog.log type cplog.log C:\\test>logcp.bat c:\\ xls C:\\test>rem Use with command line arguments C:\\test>rem Usage: logcp.bat c:\\ xls C:\\test>rem I used echo for copy. ( you must replace. ) c:\\Office2003SP3Changes\\Office2003_SP3Changes.xls c:\\Program Files\\Microsoft Office\\OFFICE11\\1033\\PROTTPLN.XLS c:\\Program Files\\Microsoft Office\\OFFICE11\\1033\\PROTTPLV.XLS c:\\Program Files\\Microsoft Office\\OFFICE11\\1033\\XL8GALRY.XLS c:\\Program Files\\Microsoft Office\\OFFICE11\\SAMPLES\\SOLVSAMP.XLS c:\\Program Files\\Microsoft Office\\Office12\\1033\\PROTTPLN.XLS c:\\Program Files\\Microsoft Office\\Office12\\1033\\PROTTPLV.XLS c:\\Windows\\Installer\\$PatchCache$\\Managed\\9040211900063D11C8EF10054038389C\\11.0.5614\\XL9GALRY.XLS_1033 c:\\Windows\\ShellNew\\EXCEL9.XLS type cplog.log cnt=9 Sat 08/07/2010 15:55:41.82 C:\\test>I had too many \\ backslashes with my IE8 Browser above. I used echo for copy below. You must CHANGE echo to copy and use source and destination. |
|
| 219. |
Solve : delete subdirecttory folder only? |
|
Answer» nice day! |
|
| 220. |
Solve : How to create .bat files which create filelistings? |
|
Answer» Hi, Victoria, could you explain the reason you posted that cat picture? Have you read the forum rules? No, I have not read any rules about Cats. Where do I read about Cats? •Make posts / comments that only relate to the original question / topic. I cannot DELETE the Cat Picture. Time ran out. Quote No, I have not read any rules about Cats. Where do I read about Cats? How is that Bill has been back more than a week and nothing has been done? very convincing, Bill. Quote from: Manasito on August 09, 2010, 05:50:22 PM I haven\'t tried anything yet. But your list has been usefull, as well as the link you posted. Manasito, Im sorry the Thread got off topic. You should now have a better understanding how to list your folders, music files and other files. Good Luck Ignore the off topic posts that offer no suggestions of how to list your files. dir /? |
|
| 221. |
Solve : Generate Ping Test Report? |
|
Answer» Hi all, |
|
| 222. |
Solve : error command? |
|
Answer» Hi, |
|
| 223. |
Solve : Want to delete history using bat? |
|
Answer» Please help that is not a good idea a lot of programs will not work if you run that. Why? Give details. deltree application data programs store info in that folder. the info is required to run Quote from: mat123 on August 10, 2010, 11:15:10 AM deltree application data Absolutely correct. Deleting that folder is a quick ROUTE to a screwed up Windows system. the given program will not work on any Windows OS. Deltree is not a command on Windows NT systems, and windows 9x (which has deltree) doesn't have an application data folder in the user's profile directory. Which isn't relevant anyway, because command.com by default starts in the desktop folder. (C:\Windows\Desktop). Secondly, because deltree's arguments aren't quoted, it won't delete an "Application Data" folder even if one existed, it would instead delete files named either "Application" or "data" or folders with that name. that and the cd command on 9x doesn't requires quotes to CHANGE to any path with a space in it. That COMBINED with the fact that even if there was some screwy OS configuration whereby that would work, it still wouldn't doo the steps claimed.I am THINKING if I could add exception to delete folder that is newly created after basic folder like microsoft, sun, adobe etc. Please let me know if I can manually add exception not to delete these folder. Rest I can. Thanks and regards vish |
|
| 224. |
Solve : Dosmand command sys a? |
|
Answer» the dos command sys a puts which files on a floppy diskis this your homework? is this your homework? Probably. Purely because of the way he asked the question, sounds like the wording on an exam or something.No seeking knowledge about unix permissions and windows Dos commands using a PC might buy a mac soon Quote from: minkah on August 19, 2010, 04:44:38 AM No seeking knowledge about unix permissions and windows Dos commands This has nothing to do with Unix, and is a little bit esoteric. Additionally, the files placed on the disk will differ depending on what version you are RUNNING. Quote using a pc might buy a mac soon yes. I see. "I want to learn DOS commands because I am going to be getting a mac". Right. Stellar ASSOCIATIVE reasoning there. |
|
| 225. |
Solve : Batch File to delete content within a folder? |
|
Answer» The FOLDER will be name "Scans" but I need the CONTENT to be deleted within the folder and ALSO I need it to run when the computer starts up. How do I write a batch file for this, some examples? Thanks.Easy |
|
| 226. |
Solve : Push commands from a batch file to another open cmd window?? |
|
Answer» HI All, (OS Win XP) This might sound a little outlandish, but I wondered if it was possible. I have googled it to death so I guess this is not the case. You lovely people might prove me wrong!! I can push commands to another BATCH file using echo , but my problem is the cmd window I want to use is created by a vbs. Hmmmm, a quandary. Any advice would be most welcome. Thanks in advancePost the CODE you used?Hi, yes I should have done that, I've kind of gone down the vbs route as I REALISED I needed to objectify the cmd window, but still no joy. First I open a cmd window with:- Dim oShell Set oShell = WScript.CreateObject ("WScript.Shell") oShell.run "adminconsole.svb" The adminconsole.svb routine opens a cmd window and this is the one I want to use to push commands into onto the command line. I've tried .Exec but this does nort work. oshell.Exec "EMSWrapperInstall.bat" as I guess it's the wrong object. I think this post is now a vbs post so APOLOGIES for it being the wrong placeFound the vbscript solution which runs a script that produces a window:- CreateObject("Wscript.Shell").Run "adminconsole.svb", 0, False Dim oshell Set oshell = CreateObject("WScript.Shell") oshell.Run "cmd.exe" Do Until oshell.AppActivate("Admin C:\WINNT\System32\cmd.exe") Loop oshell.SendKeys "EMSWrapperInstall.bat{enter}" The Do Until finds the one you want via the title bar, so a distinctive title bar is required in your cmd session that is created from the adminconsole.svb. Then I can sendkeys to that cmd box!! HURRAH!!! Please feel free to move this thread to vbscript. |
|
| 227. |
Solve : How to capture batch commands? |
|
Answer» I have a batch file which performs some commands, how can i capture all the commands its performing in to a text file. Any help is highly APPRECIATED I used the single redirect batfile > capture.txt ftp> transfer ftp>echo. ftp>echo quit Rem Between the command that does the transfer and the command to quit Rem Use echo. echo. places a blank line ( also a redirect > of each command MIGHT fix the problem. ) p.s. a pipe | and a redirect >> are two different procedures. A pipe | sends the output to another program as the input. Redirect >> goes to a text file. |
|
| 228. |
Solve : Need Help Debugging DOS Script? |
|
Answer» I have the batch file below. Basically, if I login the batch file should do nothing, and if Insert backslashes where needed But, will this work? It seems to be complicated command line. However, yours is clear and pretty. Echo Off ::Detect an anomalous logon. If none detected file takes no action. If %Username% neq Tom ( ::Get the time and date FOR /F "tokens=5 delims=. " %%a IN ('ECHO ^| TIME ^| FIND "current"') do set Trun=%%a FOR /F "tokens=6" %%a IN ('ECHO ^| DATE ^| FIND "current"') do set Drun=%%a ::Build the log file--if necessary--then log the data if not exist "C:\Output\Logons.txt" ( echo Date Time User Name >> "C:\Output\Logons.txt" echo ---- ---- --------- >> "C:\Output\Logons.txt" ) ::Write the date, time, and user name to the output file. echo %Drun% %Trun% %username% >> "C:\Output\Logons.txt" ::Create the Anomalous Logon notification message. echo Anomalous logon detected. Check C:\Output\Logons.txt for more information. >> "C:\Documents and Settings\Tom\Start Menu\Programs\Startup\AnomalousLogons.txt" )vishuvishal, We do not need a for loop to record and save %DATE% and %TIME% in a log file. But I will test the for loop code and post back the results. The editor here or with the Proxy Server is not working for me correctly. I might need to take a picture of the code while on my machine. It is pretty but we cannot copy and paste from the picture. What happened when you tested the for loop code? Post your results.He he didn't work Actually I was trying to figure out the procedure happened on this code. But found myself dumb. So, I think I am just beginner. However, your code are awesome so simple. Quote from: vishuvishal on August 09, 2010, 02:49:44 PM
Yes, the For loop by the Original Poster worked. Quote from: vishuvishal on August 09, 2010, 04:46:43 PM
The following code was mangled by my Poxy Editor. Look at the above SCREEN shot for a clear picture of the code. C:\\\\test>type vis89.bat Echo Off set USERNAME=%1 echo USERNAME=%USERNAME% SETLOCAL EnableDelayedExpansion echo. > C:\\\\test\\\\Logons.log If \\\"%USERNAME%\\\" EQU \\\"Tom\\\" goto :end FOR /F \\\"tokens=5 delims=. \\\" %%a IN (\\\'ECHO ^| TIME ^| FIND \\\"current\\\"\\\') do ( set Trun=%%a ) FOR /F \\\"tokens=6\\\" %%a IN (\\\'ECHO ^| DATE ^| FIND \\\"current\\\"\\\') do set Drun=%%a echo Date Time User Name >> C:\\\\test\\\\Logons.log echo ---- ---- --------- >> C:\\\\test\\\\Logons.log echo !Drun! !Trun! !USERNAME! >> C:\\\\test\\\\Logons.log echo Anomalous logon detected. >> C:\\\\test\\\\Logons.log goto :secondend :end echo %1 was the only User exit /b :secondend echo %1 was a Bogus User >> C:\\\\test\\\\Logons.log echo Type logons.log Type logons.log Output: C:\\\\test> vis89.bat Tom USERNAME=Tom Tom was the only User C:\\\\test> vis89.bat vis USERNAME=vis Type logons.log Date Time User Name ---- ---- --------- 08/09/2010 18:23:30 vis Anomalous logon detected. vis was a Bogus User C:\\\\test> I should say your bat is worth than this. Cause ur's simple and good. Thanks and regards VishuVis, The for loop is not necessary. |
|
| 229. |
Solve : need to when child batch file execution is over? |
|
Answer» Hi
C:test>type main.bat echo off echo main call bat1.bat echo RETURN from bat2 echo %TIME% call bat2.bat echo return from bat echo %TIME% echo Bye C:test>type bat1.bat echo off echo bat1 sleep.exe 60 echo %TIME% exit /b C:test>type bat2.bat echo off echo bat2 sleep.exe 60 echo %TIME% exit /b C:test> Output: C:test>main.bat main bat1 3:37:24.95 return from bat1 3:37:24.95 bat2 3:38:24.97 return from bat2 3:38:24.97 Bye C:test> |
|
| 230. |
Solve : Background Music? |
|
Answer» Hi Guys I Appreciate helpmeh but any example of music player which can b ran silently during the show I think silence and playing music are sort of conflicting requirements here. Quote from: The Italian Stallion on August 10, 2010, 10:25:59 AM I Appreciate helpmeh but any example of music player which can b ran silently during the showCode: [Select]SET wshShell=wscript.CreateObject("WScript.Shell") wshshell.run "MPLAY32 /play /close PATHTOMP3\file.mp3", 0i made this program that does that(with special thanks to helpmeh for the vbs script) music.exe C:\test.mp3 [recovering DISK space - old attachment deleted by admin]First: Why do people insist on compiling batch files? Original batch for "music.exe": Code: [Select]echo off echo Set wshShell=Wscript.CreateObject("WScript.Shell")>temp.vbs echo wshshell.run "MPLAY32 /play /close "%1"",0>>temp.vbs cscript //nologo temp.vbs del temp.vbs Second: MPLAY32 is the windows 95 media player. It can be found on Windows XP,Windows 2000, 98, 95, and ME. Now, let's look at The_Mad_Joker's OS: "Windows 7". Now, allow me to tell you, that mplay32 is not present on Vista or 7. therefore that solution will not work. third: it doesn't solve the problem anyway, since the windows is simply minimized. Quote from: BC_Programmer on August 10, 2010, 05:43:40 PM First: Why do people insist on compiling batch files? #1 Insecurities? #2 Mplay2 then? #2.5 Not again...why does he return? #3 No... Also, the quotes need to be escaped somehow, because Wscript is expecting an end of statement at L:2 C:37 (when run straight from VBS).i complied it so it would be hidden so there is less confusion IE no popupsOr use JUST a vbs file, that way there is no need to compile anything, nor are there any popups.Batch file too doesnt give any pop ups, and yes that music.exe is not workingIs there a preferred option? Quote from: The Italian Stallion on August 11, 2010, 12:36:05 AM Batch file too doesnt give any pop ups, and yes that music.exe is not workingOk, then just use the batch file. Quote Ok, then just use the batch file.Okies thank u all 4 your help |
|
| 231. |
Solve : Registry edit using Dos? |
|
Answer» I want to create a read error of a registry key file using MS Dos |
|
| 232. |
Solve : net use /delete in script - do not work? |
|
Answer» Hi All however after calling e:\batchfile.bat It would help if you posted the contents of batchfile.bat. It appears some process has an open handle to the P drive. Any reason why you are using start with the net use command? There is no reason to run it in a separate window and running it inline produces the same result as the /wait switch would. hi Sidewinder Thank you for replay, here is full batchfile.bat: Code: [Select]echo off CD /d p:\ REM grab todays date into variables set MM=%Date:~3,2% set DD=%Date:~0,2% set YYYY=%Date:~6,4% REM Add the date variables to the log name REM putting the date in this ORDER will sort the files sensibly Set LogFile="e:\NewFiles_%YYYY%-%MM%-%DD%.Log" REM create the vb script >c:\evaluate.vbs echo Wscript.echo eval(WScript.Arguments(0)) REM extract todays date less 7 days set OldestDate= for /f "delims=" %%A in ( ' cscript //nologo c:\evaluate.vbs "Date -7" ' ) do set OldestDate=%%A REM tidy del c:\evaluate.vbs REM break up the date into constituent parts REM Note - the date is parsing YYYY-MM-DD format dates, set MM= set DD= set YYYY= set MM=%OldestDate:~5,2% set DD=%OldestDate:~8,2% set YYYY=%OldestDate:~0,4% REM reconstruct US format with '-' separators set OldestDate=%MM%-%DD%-%YYYY% REM add the new entry to the log >> %LogFile% Echo %DATE% %TIME% >> %LogFile% Echo Since : %OldestDate% net use p:|find "Remote name">> %LogFile% REM list the files that would be copied if we really were doing a copy REM force it to believe that the target NonExistentDirectory is a directory REM and echo the name & time for each for /f "delims=" %%A in ( ' xcopy /l /i /d:%OldestDate% *.* NonExistentDirectory ' ) do call :ProcessEach "%%A" REM tidy up the log >> %LogFile% Echo ======================================== goto :EOF :ProcessEach >> %LogFile% echo %~f1 %~t1 goto :EOF Thank you for help BR MichalThe second line in batchfile.bat LOGS you on to the P drive. There is no other CD instruction in the file (that I could find), so when batchfile.bat ends, you are still logged into the P drive. Batchfile.bat needs to be changed to log off the P drive before the calling file attempts to delete the mapping (net use p: /delete) Michal I knew it would be something easy ! Sorry I couldnt finish this off without Sidewinder's help (cheers SW) Graham Try this Code: [Select]echo off CD /d p:\ REM grab todays date into variables set MM=%Date:~3,2% set DD=%Date:~0,2% set YYYY=%Date:~6,4% REM Add the date variables to the log name REM putting the date in this order will sort the files sensibly Set LogFile="e:\NewFiles_%YYYY%-%MM%-%DD%.Log" REM create the vb script >c:\evaluate.vbs echo Wscript.echo eval(WScript.Arguments(0)) REM extract todays date less 7 days set OldestDate= for /f "delims=" %%A in ( ' cscript //nologo c:\evaluate.vbs "Date -7" ' ) do set OldestDate=%%A REM tidy del c:\evaluate.vbs REM break up the date into constituent parts REM Note - the date is parsing YYYY-MM-DD format dates, set MM= set DD= set YYYY= set MM=%OldestDate:~5,2% set DD=%OldestDate:~8,2% set YYYY=%OldestDate:~0,4% REM reconstruct US format with '-' separators set OldestDate=%MM%-%DD%-%YYYY% REM add the new entry to the log >> %LogFile% Echo %DATE% %TIME% >> %LogFile% Echo Since : %OldestDate% net use p:|find "Remote name">> %LogFile% REM list the files that would be copied if we really were doing a copy REM force it to believe that the target NonExistentDirectory is a directory REM and echo the name & time for each for /f "delims=" %%A in ( ' xcopy /l /i /d:%OldestDate% *.* NonExistentDirectory ' ) do call :ProcessEach "%%A" REM tidy up the log >> %LogFile% Echo ======================================== REM ---------------------------- REM Release mapped drive REM ---------------------------- E: goto :EOF :ProcessEach >> %LogFile% echo %~f1 %~t1 goto :EOF Hi Now it looks to work with deleting p: drive when script is finished It seems to be working as expected Thank you very very very much BR MichalHi I encouriage strange problem. Mentioned above script works fine on one computer, but on all others is failing. I have that error message: C:\MDM_Monitoring>echo Y | net use p: /delete p: was deleted successfully. C:\MDM_Monitoring>START /wait NET USE p: \\server1\P_Customer\Inbound\70\70_Customer_flat\Archive C:\MDM_Monitoring>call e:\bathfile.bat The system cannot find the drive specified. The device is being accessed by an active process. More help is available by typing NET HELPMSG 2404. Press any key to continue . . . Can you please help, I have no clue why that error occour. Special that it works on once computer only. On all other computers I have mentioned above error. Thank you in advance. BR Michal Quote REM ---------------------------- I see remarks for deleting the mapped drive but no actual INSTRUCTIONS. It may be time to rethink your design. Batchfile should contain all the instructions it needs to run whether from the command line or as a called file. By this I mean batchfile should map the drive, access the drive and release the drive; it should not rely on some caller batch file to supply these instructions. Be aware that in a caller/calling sequence, that if any module fails to complete properly, your session status may be corrupt. Why are you using start /wait with the net use command? Why are you piping Y to the net use command? Quote Special that it works on once computer only. On all other computers I have mentioned above error. Let us know. Are all the computers running the same OS. Are they on the same network? Hi All Sorry I messed up, all works fine. note. Always connect to disks mapped to your computer BR Silberzin |
|
| 233. |
Solve : how to get the Count of string in file? |
|
Answer» HI, Am having a FILE with 1 line having a file size of 35MB. Eg:- arun*America*MSC~INS*dfffs*Sdfsd*sdfsd~ssfsd*sdfsd~INS*dfffs*sdfsdf*sdfs~ I need to get a count of INS* in the above file. Am new to DOS Commands. Please help me. Thanks in Advance. Regards, Arun S. Quote from: arunavlp on August 03, 2010, 04:43:17 AM hi, download gawk for windows, then Code: [Select]c:\test> gawk "{m=gsub("INS",""); total+=m}END{print "total:" total}" file hi , Thanks for suggestion. but i got an error message like this 30.834 gawk: {m=gsub(INS,"); gawk: ^ unterminated string i dont know wht this error means. Please help me on this. Regards, Arun S.Escape your double quotes Code: [Select]c:\test> gawk "{m=gsub(\"INS\",\"\"); total+=m}END{print \"total:\" total}" file hi, Thanks It works.. but please let me know if we can do it in Find Command.... Regards, Arun S. Quote from: arunavlp on August 05, 2010, 12:34:57 AM hi,i personally wouldn't bother. find (or findstr) just find the string on a line for you. It won't count how many there are. More involved PROGRAMMING is needed. ( that i will leave it someone else who has the expertise and time to show you, ) When parsing files and doing string manipulation, use a good tool for the job.The find command will count the lines with the search argument. If a line has more than one occurrence of the search argument, it still counts for one. Findstr does not do counting but allows for multiple search arguments and a limited form of regular expressions. You can use VBScript which came with your Windows machine. The little demo script will prompt the user for the file name and the search argument. It can be tweaked to remove the prompts (which will probably gut the majority of the script). Code: [Select]Const ForReading = 1 Set fso = CreateObject("Scripting.FileSystemObject") Do WScript.StdOut.Write "Please enter file name: " strFile = WScript.StdIn.ReadLine If fso.FileExists(strFile) Then Set objFile = fso.OpenTextFile(strFile, ForReading) strCharacters = objFile.ReadAll Exit Do Else WScript.StdOut.Write "Invalid file name ... Try Again" & vbCrLf End If Loop Do WScript.StdOut.Write "Please enter character string: " strToCount = WScript.StdIn.ReadLine If strToCount <> "" Then Exit Do Loop strTemp = Replace(LCase(strCharacters), LCase(strToCount), "") WScript.Echo "Occurences of:", strToCount, "=", (Len(strCharacters) - Len(strTemp)) / Len(strToCount) objFile.Close Save the script with a vbs extension and run only from the command prompt as: cscript scriptname.vbs Good luck. I can give you Idea what it should like to be: set /p pass= echo %pass% call set new=%%pass:~%a%,1%% set /a a=%a% + 1 set key=%key%%new% echo %new% This new will give you the number of string. However, I am going will give you further details tommorrow Thanks and regard vishu Code: [Select]set /p pass=<string.txt echo %pass% :st call set new=%%pass:~%a%,1%% echo a=%a% + 1 echo %a% set key=%key%%new% echo %new% echo %key% pause ::if %new% ==; goto :EOF pause goto :st All we need to fix is loop. Change the string.txt to your file drive:path\file name Gave you a best option echo off sed s/the/the\\n/g yz.txt | egrep -c the counthe.bat 10 type yz.txt the the the the the the the the the the Two \\ should be one C:\\test>type cntstr.bat REM echo off sed s/%1/%1\\n/g %2 | egrep -c %1 C:\\test>cntstr.bat the yz.txt C:\\test>rem echo off C:\\test>sed s/the/the\\n/g yz.txt | egrep -c the 10 C:\\test>type yz.txt the the the the the the the the the the Only one \\ backslash each time type cntstr.bat rem echo off sed s/%1/%1\\n/g %2 | egrep -c %1 cntstr.bat 22 yr2010.doc rem echo off sed s/22/22\\n/g yr2010.doc | egrep -c 22 12 Output for REPLY #6 by sidewinder cscript swcnt.vbs Microsoft (R) Windows Script Host Version 5.8 Copyright (C) Microsoft Corporation. All rights reserved. Please enter file name: yr2010.doc Please enter character string: 22 Occurences of: 22 = 12 Victoria, I really understand wht these commands will do. Seems like not a proper bat file |
|
| 234. |
Solve : Help creating files? |
|
Answer» I'm writing a messenger for me and my brother to use at our house. I'm Just having a little trouble with it. FYI to save a lot of repetitive typing you could useWOW! You can actually do that? Dang...that could have saved tonnes of time! Quote from: helpmeh WOW! You can actually do that? Yep, try it out. |
|
| 235. |
Solve : Help with script involving dates and days of week? |
|
Answer» Hi, Here is the solution. There was small defect.Batch scripting is all but useless in manipulating dates. What happens if the day is 01? The result of SET /A dwDAY=%DATE:~7,2%-1 is that dwDAY will return zero , and if the day is 02 and you "count backwards" for six days, dwDay will return -4. Also, if the day is 08 or 09 Set /a will treat the values as Octal and throw up the usual error message because 08 and 09 are invalid in octal. If the script is run near the beginning of the month, month and day must be decremented. If you run the script in early January the day, month and year must be decremented. Best have a look at date manipulation using VB scripting. Good luck.C:test>type griff816.bat echo off set /a c=0 :start SET dwMONTH=%DATE:~4,2% echo dwMONTH=%dwMONTH% SET /A dwDAY=%DATE:~7,2% -%c% echo dwDAY=%dwDAY% SET dwDAY=%DATE:~7,2% SET dwYEAR=%DATE:~10,4% SET Datenow=%dwYEAR%%dwMONTH%%dwDAy% set localroot=c:test set localdrv=c:tmp copy %localroot%\\%datenow%.txt %localdrv%\\%datenow%.txt copy %localroot%\\%datenow%.txt %localdrv%\\%datenow%.txt SET dwMONTH=%DATE:~4,2% SET /A dwDAY=%DATE:~7,2% -%c% echo dwDAY=%dwDAY% if %dwDAY% LEQ 0 ( SET /a dwDAY=31 SET /a dwMONTH=%DATE:~5,1% -1 echo dwMONTH=%dwMONTH% if %dwMONTH% EQU 7 set /a dwDAY=31 if %dwMONTH% EQU 8 set /a dwDAY=31 if %dwMONTH% EQU 6 set /a dwDAY=30 if %dwMONTH% EQU 2 set /a dwDAY=28 echo dwDAY=%dwDAY% ) if %dwMONTH% LEQ 9 set dwMONTH=0%dwMONTH% echo dwMONTH=%dwMONTH% SET dwYEAR=%DATE:~10,4% SET Datenow=%dwYEAR%%dwMONTH%%dwDAy% echo Datenow=%Datenow% if %dwDAY% LEQ 9 set dwDAY=0%dwDAY% copy %localroot%\\FL_%plantid%_*%datenow%.txt %localdrv%\\rs_input\\FL_%plantid%_%datenow%.txt copy %localroot%\\\\D1_%plantid%_*%datenow%.txt %localdrv%\\\\rs_input\\\\D1_%plantid%_%datenow%.txt set /a c=%c% + 1 if %c% LEQ 7 goto :start C:test>Hi Roy, I tried your code but it placed a zero in front all dates even if there were ALREADY 2 digits. But I like your logic here. I'm trying this but it isn't working quite right either. Any thoughts? set /a addzero=0 SET dwMONTH=%DATE:~4,2% SET /A dwDAY=%DATE:~7,2%-14 SET dwYEAR=%DATE:~10,4% if (%dwday%) GEQ (10) ( set /a datenow=%dwYEAR%%dwMONTH%%dwDAy% ) else ( SET /a Datenow=%dwyear%%dwmonth%%addzero%%dwday% ) echo %datenow%here comes the expert Roy. Don't worry mcgriff1969, Roy will solve your problem using batch. As for my recommendation, i would suggest you use some other tools able to MANIPULATE dates better, eg vbscript. you can search the forum as there are many such vbscripts lying around. Quote from: ghostdog74 on August 23, 2010, 07:10:28 PM here comes the expert Roy. Don't worry mcgriff1969, Roy will solve your problem using batch. As for my recommendation, i would suggest you use some other tools able to manipulate dates better, eg vbscript. you can search the forum as there are many such vbscripts lying around. Wow! No love for Roy? I understand that VB Script is better for this but I have zero knowledge of it. Quote from: mcgriff1969 on August 25, 2010, 08:31:58 AM Wow! No love for Roy?No patience for Roy, or any of his other accounts. Quote from: mcgriff1969 on August 23, 2010, 01:51:44 PM
Many suggestions from the Ghost and Helpless about what does not work. But no suggestions or examples from the Ghost and Helpless of what can be done. The Cat Bell? Quote from: mcgriff1969 on August 23, 2010, 01:51:44 PM
C:test>Display mc.bat echo off SET dwMONTH=%DATE:~4,2% echo dwMONTH=%dwMONTH% SET /A dwDAY=%DATE:~7,2%-16 echo dwDAY=%dwDAY% SET dwYEAR=%DATE:~10,4% echo dwYEAR=%dwYEAR% if %dwday% LEQ 9 set dwday=0%dwday% SET Datenow=%dwyear%%dwmonth%%dwday% echo Datenow=%Datenow% Output: C:test> mc.bat dwMONTH=08 dwDAY=9 dwYEAR=2010 Datenow=20100809 C:test> When dwDAY is not less than or equal to 9, no zero is added. ( We subtracted -14 not -16 ) Output: C:test> mc.bat dwMONTH=08 dwDAY=11 dwYEAR=2010 Datenow=20100811 C:test> Quote from: mcgriff1969 on August 23, 2010, 01:51:44 PM
set /? « Sent to: mcgriff1969 on: Today at 12:14:03 PM » -------------------------------------------------------------------------------- set dwday=0%dwday% set /a dwday=0%dwday% set /a will not work 09 is octal not an integer Quote from: Fields on August 25, 2010, 12:17:56 PM 09 is octal not an integer 09 is not octal, and it is an integer. Quote from: Fields on August 25, 2010, 11:26:00 AM C:test>Display mc.bat I think you've got it! |
|
| 236. |
Solve : NET USE or Other Cmd to change Drive Mapping's "Label"? |
|
Answer» Is there a way to use the NET USE or some other command to CHANGE the "Comment" or "Label" for a DRIVE mapping? |
|
| 237. |
Solve : Chat tool using dos? |
|
Answer» HI Techs, Can we create a chat tool using dos. That can chat over internet like MSN or Yahoo. Thanks and regards vishuProbably. Why don't you RESEARCH it and show us your code? Here, I'll start you off http://www.google.com/search?source=ig&hl=en&rlz=&=&q=command+line+chat+tool&btnG=Google+Search Sorry to DISAPPOINT you but I could find it. Could you be specific?Did you mean you want somebody to write a chat program for you? Even if you look AROUND on this forum you will find something. Quote from: Frejoh466 on August 15, 2010, 03:51:30 AM Code: [Select]echo off |
|
| 238. |
Solve : MS Dos 3.1???? |
|
Answer» I am trying to get a very, very, very old computer, which runs a very expensive piece of equipment, up and running. I believe that this computer is a 1986 AT&T PC3600 running MS DOS 3.1. When the computer boots it runs a memory test and then comes to the following screen and sits: You say the ribbon cable comes out of the back of it - are you sure that this isnt the parallel printer port ?Parallel Printer cables aren't a ribbon... they're just a cable. Quote Ah, one thought comes to mind -- the BIOS holds the setup info in cmos ram, this needs a battery to help it remember, it may be that it does not know where to boot from. Open the case, locate and replace the battery. no computers before the 286/AT had a CMOS battery. All configuration was done VIA DIP switches and jumpers on the motherboard, so this is not the problem. Sounds more like, as you said, the hard drive has gone south. I'd of course first check that by making sure everything was snugly connected inside. The hard drive is highly unlikely to be a IDE drive- it is more then likely a ESDI or another older interface, which you won't be able to install in a new computer. Replacements will be equally hard to find, if they are even sold anywhere. Best idea would be to update the hardware/software solution in place to use more modern components with more readily available replacements when parts go BAD. |
|
| 239. |
Solve : DOS batch job to delete files? |
|
Answer» Need a DOS BATCH job to delete files older than 30 days Quote from: Sidewinder on August 06, 2008, 09:02:02 AM This little snippet is written in VBScript: Just change the 5 in the code to 30 and the folder to your own folder. Quote from: darther on August 19, 2010, 12:46:57 PM Need a DOS BATCH job to delete files older than 30 days Quote from: darther on August 19, 2010, 12:46:57 PM Need a DOS BATCH job to delete files older than 30 days ( copy and PASTE from this post. See above copy for no extra backslashes. ) ref: http://stackoverflow.com/questions/51054/batch-file-to-delete-files-older-than-n-days C:\\test>display de30.bat echo off rem change \"cmd /c echo path\" to \"cmd /c del path\" forfiles -p \"C:\\test\" /s /m *.bat -d -30 -c \"cmd /c echo path\" > 30day.txt rem type 30day.txt type 30day.txt | wc -l echo. > out829.txt for /f \"delims=\" %%i in (30day.txt) do ( dir /s /TC /OD %%i | FINDSTR \"2010\" >> out829.txt ) echo Display batch files older than 30 days sort out829.txt Output: C:\\test> de30.bat 130 files Display batch files older than 30 days . 05/30/2010 07:06 PM 1,869 parse2.bat 05/30/2010 10:35 AM 87 zoe.bat 06/01/2010 05:44 PM 368 matt524.bat 06/11/2010 01:28 PM 1,624 redirect.bat 06/11/2010 06:09 PM 413 sib611.bat 06/11/2010 06:22 PM 509 yesterdayfiles.bat 06/11/2010 06:26 PM 722 dayfiles.bat 06/11/2010 09:02 PM 285 trail.bat 06/14/2010 01:04 PM 455 fday.bat 06/14/2010 05:17 PM 253 date.bat 06/14/2010 06:51 PM 81 schedule.bat 06/15/2010 04:01 PM 514 nightrider.bat 06/15/2010 08:45 PM 3,386 vis.bat 06/16/2010 03:30 PM 768 tri.bat 06/16/2010 07:26 AM 456 nrider.bat 06/16/2010 08:23 AM 493 nnrider.bat 06/16/2010 12:42 PM 866 pascal.bat 06/17/2010 02:45 AM 143 aaron.bat 06/17/2010 09:58 PM 90 slept.bat 06/20/2010 06:25 PM 0 fibbie.bat 06/20/2010 06:33 PM 65 try.bat 06/21/2010 05:36 PM 442 swxfer.bat 06/25/2010 06:36 AM 70 ab.bat 06/26/2010 08:18 PM 252 sepstr.bat 06/26/2010 08:43 PM 434 spacechar.bat 06/28/2010 07:42 PM 146 tend.bat 06/30/2010 08:34 PM 703 bang.bat 07/02/2010 09:10 PM 178 nib.bat 07/02/2010 11:05 AM 744 scrpt.bat 07/03/2010 06:06 PM 517 sw070410.bat 07/03/2010 10:43 AM 189 st070310.bat 07/04/2010 12:04 PM 61 ravi.bat 07/05/2010 06:05 PM 213 project0705.bat 07/05/2010 08:16 PM 91 ravi2.bat 07/06/2010 06:18 AM 120 old.bat 07/06/2010 08:30 PM 1,619 ski.bat 07/06/2010 09:43 PM 10 test.bat 07/06/2010 11:18 AM 1,604 shshi.bat 07/07/2010 01:33 PM 184 numdown.bat 07/07/2010 02:43 AM 210 gok.bat 07/07/2010 06:27 PM 498 matt0705.bat 07/09/2010 05:25 PM 538 dis1.bat 07/09/2010 09:57 AM 559 dis.bat 07/09/2010 11:26 PM 320 dis2.bat 07/09/2010 11:54 PM 250 hope.bat 07/11/2010 07:56 PM 263 only.bat 07/11/2010 08:26 PM 300 xfilefor.bat 07/11/2010 08:27 PM 192 xfilefromstr.bat 07/11/2010 08:28 PM 164 xfiletime.bat 07/11/2010 08:29 PM 58 xfiletime2.bat 07/13/2010 08:46 PM 38 doni.bat 07/17/2010 01:07 PM 201 blank2.bat 07/17/2010 07:26 PM 88 cp.bat 07/17/2010 11:44 AM 751 blank.bat 07/17/2010 11:59 AM 160 clean.bat 07/20/2010 07:01 PM 152 ol720.bat 07/20/2010 07:10 PM 300 filefor.bat 07/24/2010 11:01 AM 77 lp.bat 07/25/2010 01:52 PM 702 lon.bat 07/25/2010 04:39 PM 384 paw.bat 07/25/2010 07:15 PM 479 paw2.bat 07/26/2010 07:33 PM 449 blog.bat 07/26/2010 12:45 PM 140 ol726.bat 07/28/2010 06:00 PM 287 id2.bat C:\\test> |
|
| 240. |
Solve : DOS Batch command to open file with certain program, depending on file size? |
|
Answer» Hello all, |
|
| 241. |
Solve : .Bat File For Renaming Files That Are Allways Changing? |
|
Answer» HI There I Wanting To Undergo A Tricky Operation How To Rename Files Without Specifying There Names Example File 1 To 01.MP3 File 2 to 02.mp3 Using This .Bat File For My Sonic 2 Mp3 tool Any Help Will Be Greatly Appreciated Code: [Select]echo off SET ext=mp3 setlocal ENABLEDELAYEDEXPANSION set path2=C:\test set a=1 dir /s %path2%.\*.%ext% /b >%path2%.\%ext%.dir for /f "delims=" %%a in (%path2%.\%ext%.dir) do ( set b=!a! if !a! lss 10 set b=0!b! ren "%%a" !b!.%ext% set /a a=!a!+1 ) del %path2%.\%ext%.dirC:\test is the folder of the mp3 files That Has WORKED Thanks So Much |
|
| 242. |
Solve : trim first 5 characters off of file names? |
|
Answer» Looking for a way to trim first 5 character places off of a bunch of file names named Looking for a way to trim first 5 character places off of a bunch of file names named what you need is a string manipulation tool that is free and versatile to use. you can download sed for windows and then do this Code: [Select]C:\test>dir /b /a-d *mp3 01 - song1.mp3 02 - song2.mp3 C:\test>dir /b /a-d *mp3|sed "s/^.[0-9]*[ \t]*-[ \t]*//" song1.mp3 song2.mp3 Use a for loop to iterate and rename your files. Note it takes care of variable number of spaces between your numbers, not just 5. COOL! ... I am going to use this right now to trim up the file names. Thanks!!!For renaming versatility, I cannot recommend a program more than ExplorerXP -- it can trim, stuff, replace and renumber multiple files. The version I have does not work on vista but is fine on XP (its not been updated on download.com since 2006, so I doubt there will be a new version) Graham Quote from: gpl on August 23, 2010, 12:33:03 AM For renaming versatility, I cannot recommend a program more than ExplorerXP -- it can trim, stuff, replace and renumber multiple files.there are alot of such kind of software for renaming files. One can create such a UTILITY with just simple scripting. Quote from: DaveLembke on August 22, 2010, 11:45:34 AM Looking for a way to trim first 5 character places off of a bunch of file names. This solution is nearly the same as TCs in reply 1. TCs is better. Except We show the output. Reference: http://www.dostips.com/DtTipsStringManipulation.php C:test>Display trim5.bat echo off echo. > newmp3.txt dir /b *.mp3 > mp3.txt type mp3.txt echo. setlocal enabledelayedexpansion for /f delims= %%i in (mp3.txt) do ( set mp=%%i echo mp=!mp! set mp=!mp:~5! echo mp=!mp! echo !mp! >> newmp3.txt copy %%i !mp! rem ren %%i !mp! rem del %%i ) echo Display Trim5 type newmp3.txt rem ( will need double quotes for source and destination for the copy command. ) Output: C:test>trim5.bat Kalimba.mp3 Maid with the Flaxen Hair.mp3 SleepAway.mp3 mp=Kalimba.mp3 mp=ba.mp3 1 file(s) copied. mp=Maid with the Flaxen Hair.mp3 mp=with the Flaxen Hair.mp3 1 file(s) copied. mp=SleepAway.mp3 mp=Away.mp3 1 file(s) copied. Display Trim5 ba.mp3 with the Flaxen Hair.mp3 Away.mp3 C:test> |
|
| 243. |
Solve : Adding or subtracting days from current date in batch script? |
|
Answer» Hi, |
|
| 244. |
Solve : MS-DOS training classes? |
|
Answer» I'm interested in DOS because I hope to find a way to run my OS/applications under DOS because I think that running under DOS protcts your computer from all the viruses, hackers, malware, MALICIOUS programing, etc., or is this not true. Im interested in DOS because I hope to find a way to run my OS/applications under DOS because I think that running under DOS protcts your computer from all the viruses, hackers, malware, malicious programing, etc., or is this not true. http://www.microsoft.com/mspress/books/sampchap/6321.aspx The book was written in 2002. Get a few more comments before you do anything. Quote I hope to find a way to run my OS/applications under DOS MS-DOS is an "OS". Quote from: debo0648 on August 28, 2010, 11:05:22 PM I'm interested in DOS because I hope to find a way to run my OS/applications under DOS because I think that running under DOS protcts your computer from all the viruses, hackers, malware, malicious programing, etc., or is this not true. DOS doesn't protect you from anything. At all. Not even yourself, in most cases. DOS viruses are probably not as common these days but they are a lot more dangerous then todays viruses, since in those days creating a virus usually meant learning about ASSEMBLY and actually being good with computers, as OPPOSED to just banging out a script as most kiddies do today. So in a sense, you'll be "protected" from modern worms/viruses, but you'll also be "protected" from using new applications. This is like protecting yourself from viruses entirely by shutting the computer off. you're safe but you can't do anything with it. Additionally, you'll be hard pressed to find a lot of modern software for it. And as to running your "OS" under DOS, (I assume you mean Windows 7) then your not understanding what DOS is. As ST says, DOS is an operating system. Therefore you cannot run another OS "under" it. You can run Shells (like windows 3.1) but you are never going to be able to have a Pure DOS environment beneath Windows 7, or any NT OS, for that matter.Not to be off topic, but if one was to want to use a computer that is immune to infection, one might want to check into a Live Linux Distro like Knoppix which is a Read-Only OS. Not only is Linux the least viral prone, but the Read-Only OS is immune from tampering once burned to CD or DVDi am interest to learnI suggest using a VIRTUAL machine for messing around with shady things. Antivirus will never compare. http://www.virtualbox.org/ |
|
| 245. |
Solve : How to determine the name of batch script while running? |
|
Answer» Hi all, |
|
| 246. |
Solve : %date% - issue on chinese computer? |
|
Answer» HI All I have few scripts where each of them every time is running is creating log. The log contain current date. It looks like: >> %Date%_files Question is: can be handled on chinese computer CORRECTLY? Scripts WORKS perfectly fine on computers in Europe but fail on computers in China. can you help? example: echo. echo.---------------------------------------- >> %Date%_files_from_exceptions_and_ready_folders.Log echo.the script has been run %date% at %time% >> %Date%_files_from_exceptions_and_ready_folders.Log echo.---------------------------------------- >> %Date%_files_from_exceptions_and_ready_folders.Log echo. this casue script to fail on chinese computer, but is Ok on my comptuer with "european date format". Do you know how to solve it? It looks like date format on chinese computers can't be changed due to other issues. Please advice. BR Michalwhat does the Chinese date format LOOK like? Please give an example. Hi Something like: 中國人 that generate problem. BR Michal |
|
| 247. |
Solve : learn dos without damage? |
|
Answer» Does exist a PROGRAM to learn dos without damage your computer (with a stupid error)Yes. It's here: http://www.virtualbox.org/ Yes. It's here: http://www.virtualbox.org/You can't run DOS from Windows XP.BC, you should KNOW by now that I'm referring to the Windows commandline, which he implicitly was referring to, too, as you said in a previous post that most people here 95% of the time are referring to this interface rather than the actual operating system. You might also want to read my degrees list. Quote from: Big on September 04, 2010, 09:12:24 PM BC, you should know by now that I'm referring to the Windows commandline,I know what you are referring to. Quote which he implicitly was referring toMaybe, but You cannot know this. But since you seem to think so, what the heck did me mean by "without stupid error?" Quote as you said in a previous post that most people here 95% of the time are referring to this interface rather than the actual operating system.And people who are actually talking about DOS happen to use the same term. Quote You might also want to read my degrees list. Don't care. Big, if you install VirtualBox you can install FreeDOS which is functionally a very close equivalent to MS-DOS. Why do you assert that HP2 was "implicitly referring to" the windows command line? Quote from: Big You might also want to read my degrees list. You are in danger of getting tedious. Quote from: Big on September 04, 2010, 09:12:24 PM You might also want to read my degrees list. I don't see "Physic" in your DEGREE list. Quote from: mroilfield on September 05, 2010, 12:41:20 AM I don't see "Physic" in your degree list. He comes from a linguistic family, and did Latin in high school, didn't you know? What's Virtual Box... More details please Quote from: Big on September 04, 2010, 09:12:24 PM BC, you should know by now that I'm referring to the Windows commandline, which he implicitly was referring to, too, as you said in a previous post that most people here 95% of the time are referring to this interface rather than the actual operating system.Linguistic? Hardly. Quote from: HP2 on September 05, 2010, 02:38:23 PM What's Virtual Box... More details please http://www.google.com/webhp?rls=ig#rls=ig&hl=en&source=hp&q=virtualbox What is it Virtual Box is a program that emulates (immitates) a computer environment by letting you install Windows on that program and letting it launch Windows from within that program (much like when you start your PC). So this program is basically a virtual computer. It immitates a computer. Runs the Operating Systems (such as Windows XP) that you give to it. You then see your Windows XP inside a window, much like you see a notepad window, or any other window on your desktop. In this case it's the Virtual Box window. History This concept is called 'virtualization' and it was needed because it is a lot cheaper and you need less resources. For example, if the Windows installation that is on that virtual box is corrupt or messy, you can simply delete it and make a new one, like nothing happened. This is of course less time consuming than having to format your system (yes, even quicker than quick format). You can do this, because when you tell Virtual Box to make a new 'virtual disk' it will make a fictional harddisk for you, with some GB on it (15 GB for example). It then represents your harddisk that is needed for let's say Windows XP. You then have a 15 GB .iso image on your real hard drive. You can delete this .iso, containing your Windows XP, when you want. Purpose So, finally, my point is that you can test software inside the operating system that is given to Virtual Box. 'Box' is a slang (dialect) for 'computer' (much like the PC tower you have; i.e. analogy 'box'). Thus it means 'Virtual Computer'. I hope that this was somewhat a good explanation for you, HP 2. If any further questions, you may ask. Now I am certain Big is Billrich. Quote from: Salmon Trout on September 05, 2010, 11:46:27 PM Now I am certain Big is Billrich.what are the signs? Quote from: ghostdog74 on September 06, 2010, 12:44:06 AM what are the signs? The writing style, certainly, the attitude, and his strategy of creating multiple accounts so that he can first pose as a (usually comically ignorant) questioner with some very simple query and then he can log in as an ENORMOUSLY knowledgeable "expert" who proceeds to answer the question. This thread is an example. He cannot resist the temptation to boastful prolixity. The "members" he creates have a certain feel, a smell ALMOST. A psychiatrist would have a field day with him - note he is calling himself "Big". |
|
| 248. |
Solve : Shortcut? |
|
Answer» Can we make shortcut with dos???Code: [Select]START "" "C:/path/to/file.exe" |
|
| 249. |
Solve : .bat or .vbs Find within text and Rename File? |
|
Answer» I have outputted some text files all in the same directory. Each .txt FILE has within a group number, this number always starts with RXC and can go upwards of 5 characters afterwards, giving us RXCXXXXX i need the script to find this RXC number and rename the file to its corresponding group number, then do the same for all files in the same directory. number always starts with RXC and can go upwards of 5 characters afterwards, giving us RXCXXXXXi C:test>type rxc.bat echo off REM dir /b rxc* >> rxc.txt echo. >> rxc.txt type rxc.txt setlocal enabledelayedexpansion for /f delims= %%i in (rxc.txt) do ( set x=%%i set x=!x:~3! echo !x! rem copy %%i !x! rem ren %%i !x! ) Output: C:test>rxc.bat rcx12345 rcx23456 rcx34567 12345 23456 34567 C:test>Hmmmm! Quote from: OP I have outputted some text files all in the same directory. Each .txt file has within a group number I think this means that the group number (RCXnnnnn) is part of the contents of the text file, in other words is part of the text not of the filename which could be anything.. Code: [Select]Set objFS = CreateObject("Scripting.FileSystemObject") strFolder="c:\test" Set objFolder = objFS.GetFolder(strFolder) For Each strFile In objFolder.Files If objFS.GetExtensionName(strFile) = "txt" Then strFileName = strFile.Name Set objFile = objFS.OpenTextFile(strFileName) Do Until objFile.AtEndOfStream strLine=objFile.ReadLine If InStr(strLine,"RXC" ) > 0 Then number=Mid(strLine,4,5) 'Get 5 characters afterwards objFile.Close strFile.Name = Trim(number)&".txt" Exit Do End If Loop End If Next Quote from: T.C. on August 31, 2010, 04:10:48 PM
C:test>Display rxc2.bat echo off echo rxc12345 > rxc1.txt echo rxc23456 > rxc2.txt echo rxc34567 > rxc3.txt echo. > run.txt findstr rxc *.txt >> run.txt echo Display run.txt type run.txt echo. setlocal enabledelayedexpansion rem Will need double quote before skip and after delims=: for /f skip=1 tokens=1,2 delims=: %%i in (run.txt) do ( set filename=%%i set newname=%%j echo filename=!filename! echo newname=!newname!.txt rem copy !filename! !newname! rem ren !filename! !newname! ) rem will need double quote around filename and newname for copy or ren Output: C:test>rxc2.bat Display run.txt rxc1.txt:rxc12345 rxc2.txt:rxc23456 rxc3.txt:rxc34567 filename=rxc1.txt newname=rxc12345.txt filename=rxc2.txt newname=rxc23456.txt filename=rxc3.txt newname=rxc34567.txt C:test> Quote from: Fields on August 31, 2010, 06:13:31 PM Code: [Select]C:test>Display rxc2.bat how do you know OP has only RXCXXXXX on a line by itself? He MAY have a line like this "troll RXC12345 is here". and then your script breaks. Quote from: ghostdog74 on August 31, 2010, 06:38:29 PM
The tokens and delims can be adjusted to account for as many tokens as needed, We can also use more than one delims. for /f skip=1 tokens=1,2 delims=: %%i in (run.txt) do ( Quote from: Fields on August 31, 2010, 06:52:19 PM The tokens and delims can be adjusted to account for as many tokens as needed, but do you know where RXC12345 will occur in the text? beginning of line? end of line? If it can occur anywhere in the text, then how do you go about setting your delims and tokens? Quote from: ghostdog74 on August 31, 2010, 06:58:32 PM But do you know where RXC12345 will occur in the text? beginning of line? end of line? If it can occur anywhere in the text, then how do you go about setting your delims and tokens? The original code did not fail. There is a longer name for the new file. The adjustments I MENTIONED will work but not needed now. If OP request the adjustments we will do it. Quote from: Fields on August 31, 2010, 07:39:01 PM The original code did not fail. There is a longer name for the new file.yes it does. Like your example rxc4.txt, you now have "nooutput rxc45678 is here" as the new file name. It should be "45678.txt" as the new file name. Here's a suggestion : Code: [Select]for .... ( txtfile ) do ( rem set delim to whitspaces. rem go through all the tokens, look for "RXC", rem once found, get the substring from 4th character onwards. rem create the new file. ) Quote from: ghostdog74 on August 31, 2010, 08:03:00 PM yes it does. Like your example rxc4.txt, you now have \"nooutput rxc45678 is here\" as the new file name. It should be \"45678.txt\" as the new file name. Here\'s a suggestion : Yes that will work but I will not look at all the tokens until the OP asks for it. The long file name is ok with me. Many OPS ask a question and never return. By the way, I dont know enough VBS to get your VBS code to run. I have not spent much time with your VBS. Wll try later. Quote from: Fields on August 31, 2010, 08:52:57 PM The long file name is ok with me.its not ok as OP's required specs. He wants to find the RXC number following RXC. (without other alphabets/words) Quote By the way, I dont know enough VBS to get your VBS code to run. I have not spent much time with your VBS. Wll try later.you don't have to know much to learn how to run a vbscript. Code: [Select]cscript //nologo myscript.vbs Quote from: ghostdog74 on August 31, 2010, 05:57:20 PM Code: [Select]Set objFS = CreateObject(\"Scripting.FileSystemObject\") I was able to run your vbs file. The output did not come to the screen but the vbs did change the names of the original file names. The original file rxc4.txt with text [ nooutput rxc45678 is here] was changed to utput.txt and not to 45678.txt. This is clearly a flaw with the vbs solution The ops specs were not followed. Please correct C:\\test>type ghost831.vbs Set objFS = CreateObject(\"Scripting.FileSystemObject\") strFolder=\"c:\\test\" Set objFolder = objFS.GetFolder(strFolder) For Each strFile In objFolder.Files If objFS.GetExtensionName(strFile) = \"txt\" Then strFileName = strFile.Name Set objFile = objFS.OpenTextFile(strFileName) Do Until objFile.AtEndOfStream strLine=objFile.ReadLine If InStr(strLine,\"rxc\" ) > 0 Then number=Mid(strLine,4,5) \'Get 5 characters afterwards objFile.Close strFile.Name = Trim(number)&\".txt\" Exit Do End If Loop End If Next Input: C:test>findstr rxc *.txt rxc1.txt:rxc12345 rxc2.txt:rxc23456 rxc3.txt:rxc34567 rxc4.txt:nooutput rxc45678 is here Output: C:\\test>dir * | sort 09/01/2010 04:55 AM 11 12345.txt 09/01/2010 04:55 AM 11 23456.txt 09/01/2010 04:55 AM 11 34567.txt 09/01/2010 04:55 AM 29 utput.txt 09/01/2010 04:55 AM 101 1.txt.txt C:test>type 12345.txt rxc12345 C:test>type utput.txt nooutput rxc45678 is here C:test>type 1.txt.txt rxc1.txt:rxc12345 rxc2.txt:rxc23456 rxc3.txt:rxc34567 rxc4.txt:nooutput rxc45678 is here that's easy to change. So now, are you going to change your batch script to do the same? Code: [Select]Set objFS = CreateObject("Scripting.FileSystemObject") strFolder="c:\test" Set objFolder = objFS.GetFolder(strFolder) For Each strFile In objFolder.Files If objFS.GetExtensionName(strFile) = "txt" Then strFileName = strFile.Name Set objFile = objFS.OpenTextFile(strFileName) Do Until objFile.AtEndOfStream strLine=objFile.ReadLine m=InStr(strLine,"RXC" ) If m > 0 Then number=Mid(strLine,m+3,5) WScript.Echo number objFile.Close strFile.Name = Trim(number)&".txt" Exit Do End If Loop End If Next Quote from: ghostdog74 on September 01, 2010, 04:59:10 AM Thats easy to change. Same error as before: 45678.txt is not created. utput.txt is created from the input file rxc4.txt with the line [ nooutput rxc45678 is here ] inside of the rxc4.txt file. The fix for the ghost.vbs did not work. C:test>Display ghost901.vbs Set objFS = CreateObject(Scripting.FileSystemObject) strFolder=c:test Set objFolder = objFS.GetFolder(strFolder) For Each strFile In objFolder.Files If objFS.GetExtensionName(strFile) = txt Then strFileName = strFile.Name Set objFile = objFS.OpenTextFile(strFileName) Do Until objFile.AtEndOfStream strLine=objFile.ReadLine If InStr(strLine,rxc ) > 0 Then number=Mid(strLine,4,5) Get 5 characters afterwards objFile.Close strFile.Name = Trim(number)&.txt Exit Do End If Loop End If Next C:test>cscript //nologo ghost901.vbs Output: 09/01/2010 08:15 AM 11 12345.txt 09/01/2010 08:15 AM 11 23456.txt 09/01/2010 08:15 AM 11 34567.txt 09/01/2010 08:15 AM 29 utput.txt 09/01/2010 08:15 AM 101 1.txt.txt C:test>type 12345.txt rxc12345 C:test>type utput.txt nooutput rxc45678 is here C:test>type 1.txt.txt rxc1.txt:rxc12345 rxc2.txt:rxc23456 rxc3.txt:rxc34567 rxc4.txt:nooutput rxc45678 is here |
|
| 250. |
Solve : Bug...? |
|
Answer» In some batch files, when I click on them, it open and close automatically and I don't have time to do anything... But how to run the batch file without this "bug" (call 'd the way you want) It isn't a bug, Bill, as you well know. Furthermore, the answer is in my post above, which you should read more attentively. You probably know this too. Did Big get banned? |
|