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.
| 701. |
Solve : In Batch file how to pass variables? |
|
Answer» I Created which will open a website now how to pass ID and password details in the website from Batch file. |
|
| 702. |
Solve : Batch file save/load variables? |
|
Answer» Hey, im having some PROBLEMS finding how to overwrite multiple variables to 1 .bat file with mutiple lines. Basicly im making a small Rpg game and there is a few stats (e.g. strength, health, intellect) that i want to write to one file such as: and to reply to Geek-9pm i have never even heard of WSH and most of the game is already created im just working on loading/saving the game now, thanks for the tip though ill be looking it upSorry I did not explain. Microsoft encourages users to move away from using just batch for non-trivial tanks. Quote Windows Script HostWSH lets you use neither the command line or a windows interface. It allows you to use other scripts as part of a task. Even two different languages in the same task. I wish CH would have a WSH area in addition to the DOS area. Many new users don't know that more advanced tools are built-in to current version of Windows. End of Ran t. Pardon me. settings.ini Code: [Select]strength=25 health=100 intellect=50ini.bat Code: [Select]echo off REM Reading in Property file for /f "tokens=1,2 delims==" %%G in (settings.ini) do set %%G=%%H REM echoing the values echo Strength %strength% echo Health %health% echo Intellect %intellect% REM Changing the values of each set /a strength+=10 set /a health-=5 set /a intellect-=8 REM echoing the changed values echo Strength %strength% echo Health %health% echo Intellect %intellect% REM Writing the changes back to the settings file for %%I in (strength health intellect) do ( setlocal enabledelayedexpansion TYPE settings.ini | find /v "%%I=">settings.tmp move /y settings.tmp settings.ini >nul echo %%I=!%%I!>>settings.ini ) type settings.iniOutput Code: [Select]Strength 25 Health 100 Intellect 50 Strength 35 Health 95 Intellect 42 strength=35 health=95 intellect=42Thanks for the reply squash, but I need the stats to be overwritten rather than flooding the file with updated ones. Any idea how I could change your code to achieve this? Thanks.Settings.ini Code: [Select]strength=25 health=100 intellect=50 If the loop variable (the line read from file by FOR /F) is of the format variablename=value then you can just put the set keyword in front of it: Code: [Select]echo off REM Read settings from file for /f %%S in (settings.ini) do set %%S REM Show values stored in memory echo strength %strength% echo health %health% echo intellect %intellect% REM Alter a setting set /p health="Enter new value for health ? " REM Write settings to file echo strength=%strength% > settings.ini echo health=%health% >> settings.ini echo intellect=%intellect% >> settings.ini or more compact... choose a unique variable name prefix and then you can use Set to do all the work of writing the values to file with one command. settings.ini: Code: [Select]MyVarStrength=100 MyVarHealth=50 MyVarIntellect=65 Code: [Select]echo off REM Read settings from file for /f %%S in (settings.ini) do set %%S REM Show settings now stored in memory echo strength %MyVarStrength% echo health %MyVarHealth% echo intellect %MyVarIntellect% REM alter a setting in memory set /p MyVarHealth="Enter new value for health ? " REM Write settings to file set MyVar > settings.ini One difference is that after a write to file the variable names in settings.ini will be in alphabetical order of name. Like this... Code: [Select]MyVarHealth=67 MyVarIntellect=65 MyVarStrength=100 another idea... run counter and last run logger Initial state of Runcount.log Code: [Select]MyProgramVarRuncounter=1 MyProgramVarLastRun=First run Code: [Select]echo off REM Read values from file for /f "tokens=*" %%S in (Runcount.log) do set %%S echo Script has been run %MyProgramVarRuncounter% time(s) Last run date/time %MyProgramVarLastRun% REM increment counter set /a MyProgramVarRuncounter+=1 REM Get date and time into variable set MyProgramVarLastRun=%date% %time% REM Write new values to file set MyProgramVar > Runcount.log Code: [Select]C:\>Lastrundemo.bat Script has been run 1 time(s) Last run date/time First run C:\>Lastrundemo.bat Script has been run 2 time(s) Last run date/time 22/01/2012 14:20:15.86 C:\>Lastrundemo.bat Script has been run 3 time(s) Last run date/time 22/01/2012 14:20:20.61 C:\>Lastrundemo.bat Script has been run 4 time(s) Last run date/time 22/01/2012 14:20:27.77 C:\>Lastrundemo.bat Script has been run 5 time(s) Last run date/time 22/01/2012 14:20:30.14 C:\>Lastrundemo.bat Script has been run 6 time(s) Last run date/time 22/01/2012 14:20:41.33 C:\>Lastrundemo.bat Script has been run 7 time(s) Last run date/time 22/01/2012 14:22:14.76 Thanks loads for help I should be able to work with that Quote from: Risen91 on January 22, 2012, 05:04:33 AM Thanks for the reply squash, but I need the stats to be overwritten rather than flooding the file with updated ones. Any idea how I could change your code to achieve this? You obviously didn't run my code. If you look at the output you will see after changing the values and rewriting the values to the stats file that the only values back in the file are the original value names with updated stats numbers. I don't know what you are thinking it is doing. Quote from: Squashman on January 22, 2012, 07:51:46 AM You obviously didn't run my code. If you look at the output you will see after changing the values and rewriting the values to the stats file that the only values back in the file are the original value names with updated stats numbers. I don't know what you are thinking it is doing. Ahhh, I thought by "output" you meant what would be in the file after the code had run, my apologies and thank you again, Ill have a look into all suggestions and see what code fits best then. Quote from: Risen91 on January 22, 2012, 07:57:29 AM Ahhh, I thought by "output" you meant what would be in the file after the code had run, my apologies and thank you again, Ill have a look into all suggestions and see what code fits best then. The OUTPUT of the batch file!!!! You obviously didn't even bother to read the code and SEE THE SIX ECHO STATEMENTS IN THERE AND THE TYPE COMMAND THAT WAS OUTPUTTING WHAT IT NOW IN THE STATS FILE!No need to holler... |
|
| 703. |
Solve : Batch file don't run in open dos window? |
|
Answer» Hello when i run this batch file I am unable to get it to popupate a list of pst files on the dos window, just brings up a empty dos window. Does not work in XP in the Start -> Run window. Error Windows can not find DEL... Sorry... I FORGOT it was the Run box... cmd /c DEL /f /s /q "%temp%"Awesome! # 2 worked thanks again, last question i promise. I also want to run this in start -> run dir /a /s /b *.pst I did: CMD /c dir /a /s /b *.pst But i am unable to figure out how to get it to pause after it generates a list of the PST files, the dos screen flashes and goes away quick. Noticed the pause command is for batch only and I am unable to locate the " / a b c d e f " commands list anywhere on the net and find pause. SOURCE: http://technet.microsoft.com/en-us/library/bb490965.aspx Quote from: wildmanjoe on January 22, 2012, 09:23:35 AM
(Please ignore the post above) I am showing some screen grabs this time... hope you can see them... this is what I typed... as you can see pause is not just for use in scripts. Code: [Select]CMD /c dir /a /s /b *.pst & pause You could also use the /K switch with the cmd processor. cmd /k dir /a-d /s /b *.pst Quote from: Squashman on January 22, 2012, 02:57:05 PM You could also use the /K switch with the cmd processo. yes, you are right. I thought of this after I posted but you have beaten me... If you use /k then the there is no need for a pause because the command window will not close. This is better. Nice! WOW, I was using the K at the end and it was asking me Y/N to run stuff so i didn't go thhat route, thanks again! |
|
| 704. |
Solve : bat file to random open all but 3 files need help set time delay? |
|
Answer» Code: [Select]echo off |
|
| 705. |
Solve : bat files help with strings? |
|
Answer» Okay, as part of a Utility that I'm making, I want to extract information from a text file. From the following sample: |
|
| 706. |
Solve : Convert string to numeric (for a beginner)? |
|
Answer» Hi. How do I convert a string to a float? More specifically, I want to convert my algebraic operation to a number of some form (floating point, double). http://stackoverflow.com/questions/1503888/floating-point-division-in-a-dos-batchYou may wish to do you whole project in WSH. Quote Windows Script Host - Wikipedia, the FREE encyclopedia |
|
| 707. |
Solve : "start app.bat" - in fullscreen? |
|
Answer» First of all; hi =) Batch files require the cmd window. This is the window you need to set to full screen. i did this and now cmd and all bat files run in full screen, but how can i change in back to normal? Quote from: Fairadir on September 27, 2008, 09:14:31 AM i did this and now cmd and all bat files run in full screen, but how can i change in back to normal?Press ALT + Enter when in the CMD window and reverse the process.Thanks alot for all the comments, but not exactly what I'm looking for. As said in my first post, I don't want the fullscreen to be default, only for this one .bat file. Can I do that? The mode command I've also tried, but again, in just resizes the windows, doesn't make it fullscreen. Is there a command which starts a process/batch file in fullscreen? Or someway I can start the shortcut it self, because I can make the one batch I need to run in fullscreen through a shortcut.Hmmmm.....That has been asked many times in the past and the ANSWER has always been the same. You can't.As mentioned, batch files require the cmd window. Try setting up the shortcut something like this: %windir%\system32\cmd.exe /k yourbatchfilehere Right click the shortcut, and check full screen on the Options tab. The batch command "reg add HKCU\Console\ /v Fullscreen /t REG_DWORD /d 1" will set every console application, for example cmd.exe, which all batch files are run from. Starting a batch file after that would make it fullscreen. You could use the "call" command for that. Replacing "/d 1" with "/d 0" resets this option. File1: reg add HKCU\Console\ /v Fullscreen /t REG_DWORD /d 1 call file2.bat File2: echo In fullscreen we are! pause reg add HKCU\Console\ /v Fullscreen /t REG_DWORD /d 0 Just thought I'd bring it up. //EmiLI cannot help, but this will sort out any problems with your code: Code: [Select]echo off set /p pass=<password.dat set /p password=Enter password: if %pass%==%password% goto correct exit :correct start app_here.bat exit This will exit even if you type nothing, when before you may have had some problems.I use something close to Sidewinder's solution. I set a global Environment Variable as follows: Code: [Select]Varname=Start /max %comspec% /k batfile.bat Batfile.bat will contain your script to be run.. Create another bat file (let's call in startup.bat) which contains: Code: [Select]echo off cls %Varname% When you click to open Startup.bat it will run the ENV Variable %Varname% which opens the command window in fullscreen then runs your Batfile.bat Of course: Code: [Select]Start /max Batfile.batmight work as well. Good luckOMG, devcom is right dudes it is mode 200 but you don't have to put it at the start of the program you can put it in any part of your program, once the person has typed the right pass word in or what ever just put this code into the batch file you want to run. if exist 'program used to open this one' goto fullscreen :fullscreen mode 200 :: continue on from there Or you could do it this way if exist 'program used to open this one' mode 200 Just so you know mode does not have to be 200 you can change it to what ever you want it to be, you can fiddle around with it and see the results that you get. hope that solved your problem, Tan_ZaI have create an easy way to do that. It's a EXE in C language name screen.exe He just simulate the TYPING on the KEYS Alt + Enter. It's simply. 505 donwloads at this time. Go on this link if you want to download it : Link Removed... It's easy to use. Just place it in the same directory of the Batch file and add this line in the Batch : Code: [Select]screen.exe You can use anothe way to do that. You can just copy the EXE in the "System folder" at this link : C:\Windows\System32 After that you can use this EXE everywhere the Batch file are. Windows XP only. P.S. I know this topic is old. So I just wan't to help the english communauty I'm a french guy. And I'm sory if my english is poor. See you everybody.daym last post in 2008 until this new post... mate the thing is this guy obviously wanted to program in batch and make it him self not use something that sounds so dodgy... even though this is like prob never gonna be SEEN again it was worth noting. regards, Tan_Za |
|
| 708. |
Solve : ms DOS portable? |
|
Answer» Is there ms DOS portable for PC with windows 7?Windows 7 does not tiredly run any DOS programs. |
|
| 709. |
Solve : Varuible Help? |
|
Answer» heh need more help Code: [Select]set HASSHINY=0 That's your problem. Delete the highlighted line. You will always GO to the "ACQUIREDSHINY" no matter your ANSWER in it's current state. There are a lot of other small issues with this code. It looks like you might want to PROOFREAD it yourself and think about what it is you are trying to accomplish.ugh thats not the problem, that was just some PASTING issue, but something is wrong with the HASSHINY variable thing.A couple of things: You don't clear the text variable each time, meaning that it will retain its value if the person just hits enter. Code: [Select]echo (y/n) set text= set /p text= if "%text%"=="y" goto AQUIREDSHINY if "%text%"=="n" goto STARTINGAREA echo Unknown term: %text%! Also Code: [Select]set AQUIREDSHINY=1 should surely read Code: [Select]set HASSHINY=1 oh thanks I didnt see that. |
|
| 710. |
Solve : all mac in LAN? |
|
Answer» we have 2 workgroup in win network (workgroup and callcenter) first of allUmmm... What? |
|
| 711. |
Solve : formatting an HDD and installing windows in command prompt? |
|
Answer» Hello good people |
|
| 712. |
Solve : Batch file to Delete Dates from pdf files? |
|
Answer» Hi All, I would have thought we have given you enough teaching already on string replacement to do this yourself. You tell him, Squashman! Quote from: Squashman on January 12, 2012, 03:31:57 PM You can't rename the file to the name of a file that already exists. So what are we to do with the 2nd file? Very true, within the same folder. If, perhaps, this is going to go through different folders, it's possible to have same names in different folders. But as mentioned, again, we require more information in order to give you the best possible answer. Quote from: Squashman on January 12, 2012, 03:31:57 PM have the same name. You can't rename the file to the name of a file that already exists. So what are we to do with the 2nd file? The second file is in a different folder. I would try and be explicit now. I do have a code which I run in different folders to prefix pdf files with dates. I have this script in each folder so folder 12 it will prefix the files with date 20120101 echo off pushd C:\Aug\12 ::for /f "tokens=*" %%a in ('dir /b /a-d') for %%a in (*) do rename "%%a" "20120101 %%a" popd this will result in the following for example 20120101 ACA 811 DDR63 03-01-2012.pdf 20120101 TULIPA-2_DDR_85_030112.pdf 20120101 BAT-109 DDR 01-Jan-12.pdf I would like to add to the above code so the dates are removed. Apologies Squashman, the dates aren't constant and are in the formats seen above. I would like to then archieve the result below within each folder; 20120101 ACA 811 DDR6.pdf 20120101 TULIPA-2_DDR_85.pdf 20120101 BAT-109 DDR .pdf I hope this is clear now...... Many Thanks........I thought Raven gave you a batch file for removing the end date and prefixing a new date at the beginning of the file already.Because of the inconsistent dates, and the inconsistencies in the names, it's really not possible to do this WITHOUT some sort of manual oversight. See this POST for the rename program that I built a little while ago. It will allow you to crop out what you want to keep from the old file name and will add a standard beginning name, if you want, or, at the very least, allow you to have a standard naming convention that we can then do a much simpler code to in order to get everything to work out how you want it to work out. Try the program on a test directory a few times first so that you can see what the feel of it is, and then when you are comfortable with it, run it on the directory you want to run it on. You could probably use it to get the standard beginning you are looking for depending on the folder if you set up a .txt file named "targetdirectory.txt" and place it in the same folder as the program with the target folder you are wanting to affect in there.I THINK by now, 50 files could have been renamed by hand. |
|
| 713. |
Solve : freedos 1.1 and some questions? |
|
Answer» I have installed freedos to virtualbox for playing with the os at my spare time. I have some question and want to ask about. DOS-on-USB lets you install MS-DOS 7.1 on your USB memory key. After formatting your flash drive, you can install a FULL working version of MS-DOS to let you run games or system UTILITIES. The best THING about having a DOS-bootable memory key is you can boot into it on any computer, just like a CD.Thanks for your advice...... |
|
| 714. |
Solve : Batch files to delete files and folders? |
|
Answer» I need a batch file to delete particular folders like See, it got executed using this code. "Quotes" Code: [Select]For /D %%I in (D:\test\*.*) DO RD /s /q %%I becomes Code: [Select]for /d "usebackq" %%I in ("D:\test\*.*") do rd /s /q %%I Why not use the original code I gave? It seems like a cleaner process than this. Did it run into problems?It didnt run into the problems but as my destination path folder has a space in it like C:\test\PRATIK MEHTA\abc now in the above path there is a space between PRATIK & MEHTA hence the code isnt working. It isnt allowing spaces. Kindly help me RESOLVE that.You have to pute "Quotes" around any path or file name with spaces. |
|
| 715. |
Solve : md multiple folders window 7? |
|
Answer» Hi all, But what does (1,1,10) mean? I guess it means 1 to 10 but what is the other digit for? You can take a look at the full documentation by typing in for /? Essentially, when using the /l switch, the first number describes the start point, the last number the end point, and the middle digit designates by how much the step is. So (1,1,10) will end up throwing 1, 2, 3, 4...10, while (4,2,16) will throw 4, 6, 8, 10...16. That's the basic explanation.I thought so, just wanted to check. Last question on this TOPIC is; what if I wanted to use A to Z instead of numbers for example Appendix A, B, C etc. thank you for all your help I'm not sure how this works with batch, but I know how to do it with VBScript. In fact, this works great with a hybrid script. See below: Code: [Select]echo off setlocal enabledelayedexpansion echo dim oArgs >ASCII.vbs echo set oArgs=wscript.Arguments >>ASCII.vbs echo wscript.echo CHR(oArgs(0)) >>ASCII.vbs for /l %%I in (65,1,90) do ( for %%J in ('cscript /nologo ASCII.vbs %%I') do set end=%%J mkdir "Appendix !end!" ) del ASCII.vbs exit This will go from A to Z, so you will have to do some manual math if you want to change the LETTERS that are used at all. Code: [Select]echo off set "chars=ABCDEFGHIJKLMNOPQRSTUVWXYZ" setlocal EnableDelayedExpansion for /l %%a in (0,1,25) do echo !chars:~%%a,1! Quote from: oh-dear on January 19, 2012, 11:04:20 AM But what does (1,1,10) mean? (start, step, end) Quote from: Raven19528 on January 19, 2012, 12:00:48 PM I'm not sure how this works with batch, but I know how to do it with VBScript. In fact, this works great with a hybrid script. See below: Did you try it? I tried that code out, I could only make it work if the FOR line that calls the VBSCript has the /f switch, and you can reduce the VBScript to one line, and the convention is that script engine switches such as //nologo have 2 slashes (so cscript or wscript can distinguish between switches intended for the engine and those for the script) Code: [Select]echo off setlocal enabledelayedexpansion echo wscript.echo CHR(wscript.arguments(0)) > ASCII.vbs for /l %%I in (65,1,90) do ( for /f %%J in ('cscript //nologo ASCII.vbs %%I') do set end=%%J mkdir "Appendix !end!" ) del ASCII.vbs in fact you can do it in one line of batch Code: [Select]for %%A in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do mkdir "Appendix %%A" Quote from: Salmon Trout on January 20, 2012, 12:01:27 AM in fact you can do it in one line of batchDoh! I just had a Homer moment. Not sure why I over complicated it. Quote from: Squashman on January 20, 2012, 05:44:51 AM Doh! I just had a Homer moment. Not sure why I over complicated it. Well, I had one too as you can see. Quote from: Salmon Trout on January 20, 2012, 05:13:01 AM Well, I had one too as you can see.And me makes us Amigos Three. |
|
| 716. |
Solve : Batch file to detect close program and rename.? |
|
Answer» Hi gents I don't know how to detect when "runner.exe" closes to do the remove naming. Code: [Select]:loop REM Wait 60,000 milliseconds (1 second) PING 1.1.1.1 -n 1 -w 60000 >NUL REM check tasklist to see if runner.exe is running REM if it is go to :loop tasklist | findstr /I "runner.exe" > nul && goto loop REM you get here after runner.exe stops REM do your rename stuff NEXT I guess I am confused on this. Batch files are sequential processing. It will not go on to the next command until the PREVIOUS one completes. At least I have never run into an instance of this not happening. Not sure why you couldn't use the START command with the wait switch either. So I guess I am not sure why we would need to use tasklist to see if it is still running. squashman, you have a very good point. Hi gents I'm new at this so thank you very much for the speedy response The code Salmon provided works superbly. I tried messing around with Squash Start /wait switch too. However, I later found out that it doesn't work on 32-bit GUI app which "runner.exe" unfortunately is. Thank you all againWell I am pretty sure Notepad is a 32bit gui application and I have posted examples on this very forum executing notepad with and without notepad and the batch file paused each time until I closed notepad.Well this certainly is INTERESTING. It is KIND of a mixed BAG of what applications will wait and which ones will not. Seems like all the Microsoft apps I throw at it will wait. Chrome will not. Firefox waits. itunes waits Skype waitsFound a few more things. http://www.ericphelps.com/scripting/samples/index.htm#Run You can use the Wait For Title or Wait for Exe VBscripts to pause your script. Although I guess it really doesn't hurt to do keep polling for the process with Tasklist. Especially if you want to keep it pure batch. I tried it on Runner.exe and it won't wait . The wait switch would have been lovely as users might run the program for a large amount of time and i'm not sure what 700+ checks might do to performance. Ye, VBscript will likely give me a brain aneurysm. Perhaps if i'm 20 years younger I might try to learn it The Vbscript is a no brainer to use. All you do is download it and use. Nothing to edit inside the code at all. You would use it just like this. Code: [Select]ren Jogger Jogger.pack runner.exe WaitForexe.vbs runner.exe ren Jogger.pack Jogger Quote from: Squashman on February 02, 2012, 07:56:19 PM The Vbscript is a no brainer to use. All you do is download it and use. Nothing to edit inside the code at all.OK. But where is WaitForexe.vbs Quote from: Geek-9pm on February 02, 2012, 08:18:31 PM OK. But where is WaitForexe.vbsQuote from: Squashman on February 01, 2012, 09:35:42 PM Found a few more things.From the link bySquashman Code: [Select]On Error Resume Next If WScript.Arguments.Count <> 1 Then WScript.Echo "Waits for an application to shut down. Usage:" & vbCrLf & Ucase(WScript.ScriptName) & " ""Program.exe""" & vbCrLf & "Where ""Program.exe"" is the executable name of the application you are waiting for." Else blnRunning = True Do While blnRunning = True Set objWMIService = GetObject("winmgmts:\\.\root\cimv2") Set colItems = objWMIService.ExecQuery("Select Name from Win32_Process where Name='" & Wscript.Arguments(0) & "'",,48) blnRunning = False For Each objItem in colItems blnRunning = True Next WScript.Sleep 500 Loop End IfNo quite so simple. The thing giving by Salmon Trout is more simple. Quote from: Geek-9pm on February 02, 2012, 10:03:25 PM From the link bySquashmanAnd this is coming from a guy who sits there and recommends PowerShell to people who ask questions about batch files and never provides them a PowerShell script. Then you see myself, Raven or Salmon come along and write the Batch file that can do it. I am sure the batch script code from Salmon Trout was not so simple for the O/P to understand either. I basically said the VBscript was easy to use! I showed the BATCH code on how to use the VBscript. How hard can that really be! You don't have to know VBscript to use the code at all. Just download it and use it in your batch file. |
|
| 717. |
Solve : Attempting to use FOR in DOS .bat file? |
|
Answer» I have numerous file in the current directory (FILE.1.txt, FILE.1.txt, FILE.3.txt, etc.) and am attempting to use the FOR COMMAND in a .bat file as follows: %%FILE FOR variables can only be single letters (A-Z, a-z, case sensitive). Type FOR /? at the prompt to see the documentation. |
|
| 718. |
Solve : Batch file copies to wrong folder on x64? |
|
Answer» I have a batch file that I converted to exe. It has a line that copies a file like this: copy filename.dat %systemroot%\system32 is executed correctly. Why is there any need to penetrate the 64 bit system? Because on the x64 system, this line. . . copy filename.dat %systemroot%\system32 Copies to sysWOW64 and not the real system32 where I need it to. Quote Because on the x64 system, this line. . . YES, I know it does! Quote from: Linux711 on January 31, 2012, 12:55:13 PM not the real system32 where I need it to. Why do you "need" it to? Because the PATH environment variable only points to system32 and not sysWOW32, so when I enter it into command prompt from anywhere, it doesn't work if it's in sysWOW64. Plus my program is designed to operate from system32, not anywhere else. At this point, you probably want to know what it's for. It is a program that adds an item to the right-click menu of any file. It allows you to delete any file even if it's protected by trusted installer. That's one of the things in 7 that makes my angry because I like to do a lot of system modding and I can't when everything is blocked from deletion by the admin. if /i "%programfiles%"=="%programfiles(x86)%" ( REM This is a 32 bit command prompt %systemroot%\sysnative\cmd.exe /c copy filename.dat %systemroot%\system32 ) else ( REM This is a 64 bit command prompt copy filename.dat %systemroot%\system32 ) Updated comments to be a bit clearer if /i "%programfiles%"=="%programfiles(x86)%" ( REM On a 64 bit system this is a 32 bit command prompt %systemroot%\sysnative\cmd.exe /c copy filename.dat %systemroot%\system32 ) else ( REM On a 64 bit system this is a 64 bit command prompt REM On a 32 bit system this is the only command prompt copy filename.dat %systemroot%\system32 ) Updated comments to be a bit clearer (again) if /i "%programfiles%"=="%programfiles(x86)%" ( REM On a 64 bit system this is a 32 bit command prompt REM So invoke the 64 bit cmd.exe to do the copy %systemroot%\sysnative\cmd.exe /c copy filename.dat %systemroot%\system32 ) else ( REM On a 64 bit system this is a 64 bit command prompt REM On a 32 bit system this is the only command prompt copy filename.dat %systemroot%\system32 ) Thanks for the help. Can't try it right now bc I'm not near my x64 comp. I tested my code and it didn't work so I'm hoping yours will. If it doesn't, I am just going to change my whole program to run in the windows folder instead of system32. I think that will work. Quote from: Linux711 on February 01, 2012, 10:11:24 AM I tested my code and it didn't work so I'm hoping yours will. Using exactly the same batch, on: my 64 bit Windows 7 system the results were 32 bit command prompt: file was copied to C:\Windows\System32 (not C:\Windows\SysWOW64) 64 bit command prompt: likewise On my 32 bit Windows XP system the result was the file was copied to C:\Windows\System32 My suggested solution exploits the FOLLOWING: In a 32 bit command environment the environment variable %programfiles% has the same value as %programfiles(x86)%. In a 64 bit environment it does not. WOW64 recognizes Sysnative as a special alias used to indicate that the file system should not redirect the access. Thus a 32 bit command prompt can select the 64 bit version of cmd. exe. Note that 64-bit applications cannot use the Sysnative alias as it is a virtual directory not a real one, and is not seen by 64 bit programs. |
|
| 719. |
Solve : Print and/or Burning files to CD for backup? |
|
Answer» Hi, I'm HOPING someone here can help resolve a problem a friend is having with a very old, DOS based, tanning salon program? The programs is "SunMate v4", that my friend bought in the late 1980's. A few years after my friend bought the software, the creator passed away, without being able to sell the software. Before he died, he placed the software on a public domain Bulletin Board so anyone could download and use it free of charge. The bulletin board was taken down TWO years later (1994, I believe), so all support for the program was lost when the bulletin board went down. The original program was installed on an old Windows 3.x operating system. Since upgrading to a newer, Windows 98 Computer, then later to Windows XP Pro SP3, being able to boot and run the program from pure DOS was lost. The program now RUNS by booting to Windows XP, then starting it by clicking a link that opens the program from the XP DOS Prompt window. The original installation floppy disks are corrupt (indicates they haven't been formatted - then ask if I want to format them), so we can't reinstall from them. A few DAYS ago, my friend inadvertently hit a wrong key combination that changed the software back into "Demo" mode. I've been able to get the program working again, but am not able to get it set up to print records and daily/weekly service activity, or burn them to CD to keep them updated. I'm hoping someone here can help me get the program set up so she will be able to print and burn to CD, the business records and activity. I have found a way of printing the records by using a program named "Printfil", but would rather be able to do it directly from the program because of the number of steps it takes to print using Printfil. I have the program files and even the DOS files ORIGINALLY used for the program if they would help resolve the problem. Please get in touch if you might be able to help. Thanks, disaksenYou need a reliable backup of whatever you have. As for the floppies, a skilled technician can get the neat off of them. But I have no idea where you would find one. Kind of a lost art. The alignment of the stepper has to be carefully tweaked to allow reading off track data. Hard to explain in words. Many floppy drives are mus-alined. Don't assume the diskettes are blank. One method of backup is to use another computer and 'slave' the DOS hard rive to a good working computer. The working computer can copy the files to a backup directory. |
|
| 720. |
Solve : DOS command to execute an app and auto load a MDB file? |
|
Answer» Greetings, |
|
| 721. |
Solve : Renaming a bunch of files to remove a "Q" from the name? |
|
Answer» Hello all. SETLOCAL ENABLEDELAYEDEXPANSION do? NORMALLY a batch script is run in 2 phases (1) parse (2) run. At parse time all the variables are expanded. In a FOR loop it would not be possible to assign values to and read values from such variables. Delayed expansion allows expansion of variables at run time. Such variables use ! as the variable name delimiter. This topic is very heavily covered at many web locations, so you will forgive me for not writing an article about it for you. ok, thanks again for your help. |
|
| 722. |
Solve : need help! need a batch script to delete certain data from a .c file? |
|
Answer» Hi all, |
|
| 723. |
Solve : Automatic updater? |
|
Answer» Hey I'm pretty rusty on dos but I had an IDEA the other day and I thought Id share it with you guys to see if it is doable. Basically I have this game that stores client side data. I will be running the sever the clients connect to but I need to DEVISE a WAY to ensure all clients have up to date client data. I have been trying to think of a user friendly way to allow a batch file to trigger before the client to check for updates and download only if the files on the client side are different than those on the server side. Is this possible? If so any ideas? |
|
| 724. |
Solve : writing a variable to another batch file? |
|
Answer» Hello Everyone, Works for me. That was done at the prompt. You can escape percent signs (%) using a caret (^) at the prompt. In a batch file it is different. You escape a percent sign with another percent sign (to echo one percent sign in a batch, you use two of them) At the prompt: Code: [Select]C:\test>echo echo ^%var1^% > test.txt Output of command typed at the prompt (test.txt): Code: [Select]echo %var1% test.bat: Code: [Select]echo off echo echo ^%var1^% > test2.txt echo echo %%var1%% >> test2.txt Output of batch (test2.txt): Code: [Select]echo echo %var1% Notice that the first echo is blank. |
|
| 725. |
Solve : Changing special characters.? |
|
Answer» Win XP Home SP.3+ |
|
| 726. |
Solve : Rar files by folder and by month to new destination.? |
|
Answer» I'm looking to create a batch that will take a set of files created in each month/year and rar them to an archive folder, labeling the rar by date and folder path. |
|
| 727. |
Solve : Script to Look for 1 File but Not Another?? |
|
Answer» I need a script that will search folder + subdirs for the existance of 2 files that don't match but contain information that pertain to a certain item, and if it finds 1 but not the other it will do something such as log that it's missing to another file, or email me. Here is an example of what I mean. |
|
| 728. |
Solve : Batch File to empty contents of log file but not delete it? |
|
Answer» Hi, And... won't you prefer just to get the content of the last line That will solve your problem and keep a real log and getting the info you are looking for to email.Two things not quite right about your approach to that. 1) If you are ALREADY going to to use a for loop to count the lines you might as well just use the For loop variable to assign the lines to a variable. Then you don't need to use the counter at all. You are already parsing every line. Might as well use it to your advantage. Code: [Select]FOR /F "delims==" %%I in (Your_File.log) Do Set lastline=%%I 2) Using the FIND command is much much much faster at counting the number of lines in a file. |
|
| 729. |
Solve : modifiying the windows regestry? |
|
Answer» I'm attempting to modify this GUID key with the REG command. |
|
| 730. |
Solve : stripping info from cmd prog output and adding to text file? |
|
Answer» Hi all, "M04296 - LET ME BE THE ONE - BLESSID UNION OF SOULS.mp3";-15.94;-15.93;-15.96 Does anyone know how i could code a batch file to do this? And if not, does anyone have any other suggestions for how i can achieve what i want? I guess some sort of regular expression on the output of the SoX program is what i'm looking for. Any help is appreciated cheers. NM [year+ old attachment deleted by admin]You already got a good start on it. I would use a Nested For Loop and put your SOX command inside that second for loop. Code: [Select]for %%A in (*.mp3) do ( FOR /F "Tokens=4,5,6 delims= " %%G in ( 'SOX "%%~A" -n stats ^|findstr /C:"RMS lev DB"') do ( echo %%A %%G %%H %%I >>myfile.txt ) )Thanks for getting back to me about this Squashman. There is one small problem though, the 3 values (tokens 4, 5 and 6) aren't getting found and passed on to the text file. The call to the SoX program goes ok and the results of it's analysis print onto the CMD screen but the values are either not getting found or not being passed on correctly. This line here doesn't get called at all it seems as the filename ( %%A ) isn't put into the text file either. Code: [Select]echo %%A %%G %%H %%I >>myfile.txt Any ideas on what the problem might be? Cheers NMThere are some console programs output that doesn't play nice with batch file output. There are even a few MS utilities that you can't use a FOR loop in a batch file to CAPTURE the output. I tried loading SOX on my computer and I can't seem to get it work. If you can help me get that installed and configured I could probably figure out the issue with the output from SOX. This is what I got when I tried to run the same command you were running on a single MP3 file. Code: [Select]C:\Desktop_from_first_computer\music>sox Slipknot-Before_I_Forget.mp3 -n stats sox FAIL util: Unable to load MAD decoder library (libmad). sox FAIL formats: can't open input file `Slipknot-Before_I_Forget.mp3':Hi, you just need to put the attached dll file into the same folder as SoX Thanks for your help. Cheers NM [year+ old attachment deleted by admin]Wow! I have no idea what SOX is doing but you can't capture any of its output. It won't let you parse the output in a FOR LOOP nor will it redirect its output to a LOG file. So my original code will not work nor will redirection to a text file like this: Code: [Select]SOX "Stone_Sour-3030-150.mp3" -n stats 1>Temp.logOk. Not to worry. Not your fault. I really appreciate you going to all that trouble for me anyway. Have yourself a "Thanked". I've got 22,000 files to process so i might just have to write a program to analyse them in Flash Cheers NMI think SOX sends its output to stderr and not stdout Hi Salmon Trout, Does that mean there might be a way to capture the data afterall? Cheers NMTry Googling for "redirect stderr to stdout cmd"I've managed to find the command to reroute the output but i'm not sure when to apply that in the current script i have. And you were right, if i use the following command... Code: [Select]SOX "M03671 - WHINEY WHINEY - WILLI ONE BLOOD.mp3" -n stats 2>Temp.log i get a log file with the information that would usually be shown in the CMD screen, like this... Code: [Select] Overall Left Right DC offset -0.000025 0.000000 -0.000025 Min level -1.000000 -1.000000 -1.000000 Max level 1.000000 1.000000 1.000000 Pk lev dB 0.00 0.00 0.00 RMS lev dB -16.78 -17.03 -16.54 RMS Pk dB -9.06 -9.72 -9.06 RMS Tr dB -1.#J -1.#J -1.#J Crest factor - 7.10 6.71 Flat factor 5.61 6.39 5.14 Pk count 48.5 35 62 Bit-depth 29/29 29/29 29/29 Num samples 10.5M Length s 237.949 Scale max 1.000000 Window s 0.050 so is there some way that i can redirect the info from stderr to stdout so that the tokens and findstring are carried out ok? Cheers NM p.s. i'm basically TRYING to find where i should put the redirect code Code: [Select]2>&1 or how i should rewrite this to make it workI'm almost there. I'm redirecting the output to a log file then trying to use the FINDSTR command to search through the log file for one specific line but it isn't working exactly as planned and i get every line output to my final file. Here is my code... Code: [Select]echo Filename;Total RMS;Left RMS;Right RMS >> RMS_Stats.txt FOR %%A IN (*.mp3) DO ( SOX "%%A" -n stats 2>Temp.log FOR /F "Tokens=4,5,6 delims= " %%G IN (Temp.log) DO ( FINDSTR /F:Temp.log /C:"RMS lev dB" echo %%A;%%G;%%H;%%I >> RMS_Stats.txt ) ) pause Any advice on what i'm doing wrong? Cheers NMSweet, i finally figured it out!!! Code: [Select]echo Filename;Total RMS;Left RMS;Right RMS >> RMS_Stats.txt FOR %%A IN (*.mp3) DO ( SOX "%%A" -n stats 2>Temp.log FOR /F "Tokens=4,5,6 delims= " %%G IN ('FINDSTR /C:"RMS lev dB" Temp.log') DO ( echo %%A;%%G;%%H;%%I >> RMS_Stats.txt ) ) pause Thanks for all of your help guys. Cheers NMI was thinking of redirecting stdout to stderr and not a file... like this... Code: [Select] 2>&1 This way you don't need to use a temp file Something like this... Code: [Select]for %%A in (*.mp3) do ( FOR /F "Tokens=4,5,6 delims= " %%G in ( 'SOX "%%~A" -n stats 2^>^&1 ^|findstr /c:"RMS lev DB"') do ( echo %%A %%G %%H %%I >>myfile.txt ) ) Quote from: Salmon Trout on February 14, 2012, 10:45:58 AM I was thinking of redirecting stdout to stderr and not a file... like this...Bingo! Thanks for chiming in! Got super busy at work this morning. |
|
| 731. |
Solve : Sound card driver, Audio device choice? |
|
Answer» I've installed DOS 7.1 on a VM (Virtual Machine) after figuring I needed to changed the boot order of the CD-ROM at some point. During the process I didn't really know what sound card driver to choose and knowing my device use AC97, I chose 1 of 2 that seemed a bigger company but the sound is horrible so I figure it wasn't the right choice. setup.exe /SECTION audio /mode single(single for single section). Thank you KINDLY for your help |
|
| 732. |
Solve : Need Help with a replaceable parameter in a batch program? |
|
Answer» I've been at this for the last 3 hours and I finally got my replaceable parameter command to work. The problem I am having is using it in a batch program. I have a menu program that when you hit the specific menu number the batch program that was created would kick in. Now if I run batch program on its own it worksk, The problem is how do I get the replaceable parameter batch program I created to run. when I hit the menu option it automatically runs it with errors. I guess what I'm asking how can I get the batch program to issue the command and ask the user for the parameter 1 and parameter 2 |
|
| 733. |
Solve : Batch only file name... from a? |
|
Answer» Hi, For YYYYMMDD form. Your offset is off by a few characters. For your first one it should be Code: [Select]ren d:\Temp\Testing\marti.rar d:\Temp\Testing\Docs%date:~10%%date:~4,2%%date:~7,2%.rarand your second should be Code: [Select]ren d:\Temp\Testing\marti.rar d:\Temp\Testing\Docs%date:~10%%date:~7,2%%date:~4,2%.rar Unless your date variable expands differently than mine.. Code: [Select]c:\>echo %date% Fri 01/06/2012 c:\> Quote from: Raven19528 on January 06, 2012, 10:27:27 AM
You mean like this? Code: [Select]C:>echo %date% 06/01/2012 Quote from: Salmon Trout on January 06, 2012, 10:47:00 AM You mean like this? Yep. Just like that. Maybe it would be better to explain the offset and parsing aspect of variables rather than try to assume how the OPs date variable expands. Unless the OP would like to show us how the date variable expands on his/her CPU.I made a mistake in my first answer, such that it would not work whatever the %date% EXPANSION. Ren does not expect a path when specifying the new file name. The code below is correct. My %date% expands just like Salmon Trout's. Something that would work on either of the expansions mentioned so far (ALTHOUGH not on any others): On UK systems for YYYYMMDD or on US systems for YYYYDDMM. Code: [Select]if "%date%"=="%date: =%" (ren d:\Temp\Testing\marti.rar Docs%date:~6%%date:~3,2%%date:~0,2%.rar) else ren d:\Temp\Testing\marti.rar Docs%date:~10%%date:~7,2%%date:~4,2%.rar On UK systems for YYYYDDMM or on US systems for YYYYMMDD. Code: [Select]if "%date%"=="%date: =%" (ren d:\Temp\Testing\marti.rar Docs%date:~6%%date:~0,2%%date:~3,2%.rar) else ren d:\Temp\Testing\marti.rar Docs%date:~10%%date:~4,2%%date:~7,2%.rar I AGREE that it would be a lot easier if the OP showed their %date% expansion.Hybrid script works in any locale Code: [Select]echo off echo Wscript.echo eval(WScript.Arguments(0)) > evaluate.vbs for /f "delims=" %%A in ( ' cscript //nologo evaluate.vbs "YEAR (date)" ' ) do set yyyy=%%A for /f "delims=" %%A in ( ' cscript //nologo evaluate.vbs "Month (date)" ' ) do set mm=%%A for /f "delims=" %%A in ( ' cscript //nologo evaluate.vbs "Day (date)" ' ) do set dd=%%A del evaluate.vbs if %mm% lss 10 set mm=0%mm% if %dd% lss 10 set dd=0%dd% echo yyyy %yyyy% echo mm %mm% echo dd %dd% echo yyyymmdd %yyyy%%mm%%dd% echo yyyy-mm-dd %yyyy%-%mm%-%dd% echo mm/dd/yyyy %mm%/%dd%/%yyyy% set examplevar=%yyyy%%mm%%dd% Code: [Select]yyyy 2012 mm 01 dd 06 yyyymmdd 20120106 yyyy-mm-dd 2012-01-06 mm/dd/yyyy 01/06/2012 There is a lot of stuff here that I don't understand. I thought you just wanted to rename something. If so I would do it this way: Create a batch file. We will call it 'rename.bat' The file would look like this: ren marti.rar Doc2012%1 I am not sure if I have the wording correct as I can't see your message, but you get the idea. When you run the file simply enter 'rename mmdd' where mmdd is the month and day. (or day and month if you wan this order. Since there is a lot of other stuff POSTED in posts to your message I am not sure if this is what you want. If you already have a batchfile to run the other programs you can just include this in it and enter the mmdd info when you run that batch file. Hope it helps Jim, the O/P has not posted back in over a month so we will never know what solved their problem. |
|
| 734. |
Solve : Time Set Batch Files? |
|
Answer» Hello everyone, Thanks to everyone for replies and the PMs. If you don't mind me asking...who are these PM's from ? ? Quote from: patio on February 08, 2012, 04:05:10 PM If you don't mind me asking...who are these PM's from ? ?Yes, indeed. Support is supposed to be limited to the forums or the chat service. Support is NOT supposed to be provided in PM's.We all know who sends "support" via PMs. Quote from: astaf on February 08, 2012, 03:18:34 AM Raven19528 Do you think a similar method can be applied on MS-DOS 6.22? I am not familiar with MS-DOS 6.22, but from what I do know about DOS, I doubt it. I have learned a great deal about cmd line batch filing, but I am by no means an expert in the DOS realm. At this point, I think it best that I let someone who knows a lot more about your specifics take a crack at it. Quote from: Salmon Trout on February 09, 2012, 11:09:57 AM We all know who sends "support" via PMs. I knew that and that's why i asked...That was a quick delete. Quote from: Raven19528 on February 09, 2012, 06:32:49 PM That was a quick delete. THANX...raven19528 I think it's not possible or requires much experience to do it, since i can't get a solution in this well-equipped forum.I am fairly sure that in MS-DOS 6.22, which is a single-tasking OS, you can't make one app press keys while another app is running. That's reasonable considering that you say it is a single-tasking OS. Thanks.I do a LOT of processing in DOS. I write short EXE programs to do most anything I want. I use RPG. It is quick easy, and makes comact programs. Usually 25-100k. I also use quite a few batch files. If you want to do it at the same time every day, there is a dos comand 'waitfor xx:xx. If you want to do it on certain days, there is a command that checks the day of the week. It is 'datechek' It will return an errorlevel 0-6 for Sunday-Saturday. I think these commands work on all vesions of DOS Hope this HELPS. |
|
| 735. |
Solve : Batch with Ascii Art and FTP Login... need help? |
|
Answer» Hi, if i run asp.bat i get this error.... Your third ASCII art line has this character | This is the pipe symbol. Echo blablabla | lalala means pipe text blablabla to program lalala So the ascii art after the pipe symbol is triggering the error. Because there is no program named "___". Escape the pipe symbols with a caret so | becomes ^| Also escape < and > if you use them. Quote from: arcanus on February 13, 2012, 11:48:28 AM ok i've put the ftp stuff into another file and got just the last line in my first file...But that forces you to hard code the directory you need to change to. You cannot ask for it in your batch file now.Ok now it works... the asp.bat works well but i set on this file a path with: set /p rel= And in the ftp file i want go to this dir with cd blabla/%rel% this doesn't work... how can i make this working? greetz arCi Quote from: arcanus on February 14, 2012, 09:09:55 AM Ok now it works... the asp.bat works well but i set on this file a path with:I gave you the code in my 2nd post and then told you about your issue in my 3rd post. You need to create the FTP script on the fly with the code I gave you.i know and i make 2 files... 1 File with the asciiart in (asp.bat) 1 File with the ftp Stuff (asp.ftp) the ftp file looks like this now: Code: [Select]open xxx.xxx.xx.xx xxxxx user username password cd incoming/%rel% mget -r * quit i removed the echo. commands because it won't work with that. Here is the asp.bat file: Code: [Select]echo off echo _____ ___________________ echo / _ \ / _____/\______ \ echo / /_\ \ \_____ \ ^| ___/ echo / ^| \/ \^| ^| echo \___^|__ /_______ /^|___^| echo arCi's \/ SiTE \/ PROJECT echo. echo PRiVAT + SECURE SiNCE 2K8 echo. echo Please input a Scene-Release: set /p rel= echo. echo Release was set on ASP echo. echo Ready for Connection? (Y/N) set /p answer= if %answer% == Y goto con if %answer% == N goto end :end exit :con clear echo _____ ___________________ echo / _ \ / _____/\______ \ echo / /_\ \ \_____ \ ^| ___/ echo / ^| \/ \^| ^| echo \___^|__ /_______ /^|___^| echo arCi's \/ SiTE \/ PROJECT echo. echo PRiVAT + SECURE SiNCE 2K8 echo. echo. echo establish Connection... echo. ftp.exe -n -i -s:asp.ftp btw thx 4 your help and time u spend here... For the third time I told you that the FTP script needs to be created on the FLY by the BATCH File. I told you in my 2nd post: "This is what the end of your batch file needs to look like!" You need to use the code I gave you to create the ftp script with the batch file. You cannot have the FTP script already created!sorry i told u my english sucks... But now i've understand it... with your code the ftp file will created when i START the bat... test... and it works fine. So but now i've got the *.bat file with the user and pw inside... Is there a way to encrypt it? That no1 can read what's inside... Quote from: arcanus on February 14, 2012, 11:59:13 AM sorry i told u my english sucks... But now i've understand it... with your code the ftp file will created when i start the bat...There are programs that will take your BATCH file and wrap it into an executable. But there are plenty of issues with that. All they are really doing is creating a self extracting executable file that launches the batch file. Many of these programs extract the batch file to a temporary folder which then becomes the working directory. If you are trying to DOWNLOAD files to the directory that the executable is launched from it will end up downloading them to the temporary folder that batch file was executed from. You could always just prompt for the username and password in the batch file and echo those variables to your script.Yes i try bat2exe or bat2com but the created exe or com-file doesn't work well... Maybe it's rly the best to make a prompt for user/pass... Ok thx 4 all Squashman Whoooshe... |
|
| 736. |
Solve : Some advanced techniques and efficiencies? |
|
Answer» Hey all, |
|
| 737. |
Solve : need a little script or software program to remove the .vir extensions on files? |
|
Answer» can anyone please help me with this: I have a folder that has FILES and subfolders and all the files have the .VIR extension APPENDED by an antivirus program. I know these are not infected, I just want to RECOVER them back to the original file extension. example -- dimstat.pdf.vir should be dimstat.pdf These files are part of a lighting design software and now the program doesn't work. The subfolders can GO down 3 or 4 levels. this is on a windows XP professional pc, SP3.Code: [Select]pushd "C:\path to top level folder\" |
|
| 738. |
Solve : Batch file error level? |
|
Answer» I should be able to work this out myself, but my mind is not working quite right. I have a batch file. I have a command that returns an errorlevel form 0-6. One for each day of the week. I want to 'goto' a tag if the returned error level is 5 or 2. What is an EASYIf "%errorlevel%"=="5" goto foo Not a massive difference in anything, just a little quirk about batch. The old MS-DOS if errorlevel command syntax was preserved in modern Windows command language for backwards compatibilty. In the old version, "if errorlevel N do something" means "if the errorlevel is N or more do something", which is why you have to test for the errorlevels you are interested in, in DESCENDING order. However, the modern version where you test a regular variable called %errorlevel% does not have this restriction, and if you use the arithmetc comparison operators (instead of QUOTES and double equals sign): EQU - equal NEQ - not equal LSS - less than LEQ - less than or equal GTR - greater than GEQ - greater than or equal you don't need any quotes either if %errorlevel% equ 0 if %errorlevel% neq 0 if %errorlevel% gtr 0 etc so you can do without gotos and LABELS too if %errorlevel% equ 5 ( rem the stuff at the :foo LABEL command1 command2 etc ) if %errorlevel% equ 2 ( rem the stuff at the :foobar label command3 command4 etc ) |
|
| 739. |
Solve : Batch help.? |
|
Answer» Hello, I know that DEL does this. But this doesnt work for all windows OS's How would i got about making a bathc that deletes a folder that will work on any windows OS eg it would delete a folder on winxp,win7,win8,vista? I'm not sure if I'm understanding correctly, but if you want to delete a folder, try using the RMDIR command. That should work on Windows 2000 or up. I don't know about windows 8, but it hasn't been officially released yet. |
|
| 740. |
Solve : Batch Programming Help - Renaming Files? |
|
Answer» So, I'm new to writing Batch files. I've got the basic algorithm, however it is the formatting and language I'm having problems with. |
|
| 741. |
Solve : MS-DOS application Date/Year format problem? |
|
Answer» Hello all of you! Possibly program is not year 2000 compliant.Any solution without source code??1. Easy: Remember that "112" means "2012" and "113" means "2013" etc 2. Difficult: FIND software vendor and request updated version. Quote from: Salmon Trout on February 14, 2012, 11:43:46 AM 1. Easy: Remember that "112" means "2012" and "113" means "2013" etcI have problems with customers... Is any solution with some decompilers or something else... Just to try?? Thanks!!!!!!!!!!!!!Why didn't you give the name and version number of the program? |
|
| 742. |
Solve : How to break out of 'for /f ...' loop after one iteration? |
|
Answer» I am pretty new to batch writing and so the issue I have is probably more a problem of wrong approach rather than a fix for the path I am on. |
|
| 743. |
Solve : Compare two folders and ontents.? |
|
Answer» I have TWO folders on efferent volumes, (Drives). You are not being clear on what your intended task is.The LATER. I need to know if the two folders and sub-folders a re equal. The contents of both are from a download and I don't have nth check sum information. So I want to compare then two to see if they are equal.If the two directory structures are the same and only the Drive LETTERS are different (C:Source & F:\Source) then you could do this to see if the files exist in each. Code: [Select]pushd C:\source FOR /F "tokens=1,2 delims=:" %%G in ('dir /b /s') do ( IF EXIST "F:%%H" echo file or folder exists in both drives )WinDiff |
|
| 744. |
Solve : String Manipulation Batch? |
|
Answer» I am making a batch file where the user needs to drag a file into the command window. Both the filename and the path need to be stored in two separate variables (when the file is dragged into the window, the full path and filename is retrieved and stored in one variable). I found soooo many examples of this on google EXCEPT they all assumed that you would be using %1 and for me it's %arpath%. I can't figure out how to make the thing work with a variable instead of %1. So the answer is there is no answer You waited under 9 minutes before making this petulant bump. This is not really acceptable. I wish now that I had waited 12 hours to tell you about FOR. Quote This is not really acceptable. I wish now that I had waited 12 hours to tell you about FOR. I apologize. I waited so little time after that first response because the way he said it, it sounded like there was no solution and I thought if I left it that way everyone would just read his post and think "up. not possible. moving on." But you didn't wait until 12 hours, so either you answered it anyway (in which case I appreciate it) or you just found out that it had been 9 minutes now.My bad anyways. The Majority of my batch files that we use here at work are drag and drop. The ones that are drag and drop the user drags and drops all the files they need to process onto the batch file. Everyone in my department knows that is how they work. So if you really wanted to do it that way you could just inform your users that all they need to do is drag a file or folder on top of the batch file and that will launch the batch file as well. Otherwise your users are doing 3 steps just to get the file path into the batch file. 1) They double click to launch the batch file 2) They drag and drop the file into the cmd window 3) They then need to hit enter for the SET /P to take the input. If you just have your batch file accept the %1 as the input all they have to do is 1) drag the file onto the batch file What I usually do at the top of all my scripts is check to see if %1 is not defined. If it isn't I GOTO a label at the bottom of my script called USAGE. It explains to the user that they MUST drag and drop the files they want to process onto the batch file. You could in theory have your batch file setup both ways. You could do an IF statement after your first QUESTION to see if %1 is defined and if it is SET it to your Path variable and GOTO a label after after your FOR LOOP. Quote from: Squashman on February 22, 2012, 05:11:05 AM What I usually do at the top of all my scripts is check to see if %1 is not defined. Is the coding for this simply if defined %1? I'm having some issues with a called script and I'm trying to break it down to it's basic parts and troubleshoot individually, but still running into snags. Also, when a script is called from cmd line or batch, does it see something in QUOTES as one variable to be passed? I.e. program.exe 2 3 "Hello all" would pass three variables to the program, not 4? I'm pretty sure this is the case, but looking to verify it before troubleshooting further. Quote from: Raven19528 on February 22, 2012, 12:44:48 PM Is the coding for this simply if defined %1? if [not] defined only works with regular %var% type variables (those which normally have a percent sign before and after) not the single-percent sign-and-number replaceable parameters, so you'd have to do this (notice there aren't any percent signs surrounding the variable name after the defined keyword) Code: [Select]set var=%1 if defined var echo YES if not defined var echo NO Code: [Select]set var=%1 if defined var ( echo YES ) else ( echo NO ) Or you can work directly with %1 to %9 Code: [Select]if not "%1"=="" echo YES if "%1"=="" echo NO Code: [Select]if not "%1"=="" ( echo YES ) else ( echo NO ) Moving on... Quote program.exe 2 3 "Hello all" would pass three variables to the program, not 4? test.bat Code: [Select]echo off echo parameter 1 is [%1] parameter 2 is [%2] parameter 3 is [%3] parameter 4 is [%4] test.bat 2 3 "Hello all" See the result... I shouldn't have said defined. I just do a comparison with an IF statement. IF "%1"=="" goto usage |
|
| 745. |
Solve : How to remove folder in Local Settings\Application data from a BAT file?? |
|
Answer» I use BAT files to manage and/or delete cache FOLDER(s) on computers which I use. |
|
| 746. |
Solve : Batch file to change to a specific date? |
|
Answer» I need to write a batch file so I can set the date to start a program, but I then need to change back to the current date after the program has loaded. I've not written any batch files in a long time and can't work out how to do it.This is dependent on your regional and language settings. I need to write a batch file so I can set the date to start a program, Why? Has the trial period EXPIRED? It's a parts catalogue, new one issued every month, no longer got access to latest one so having to use an old one. Quote from: Squashman on January 11, 2012, 07:53:01 AM This is dependent on your regional and language settings. I'm using XP and the date format is wrong, I get today=1/-01- You need to show me how the date variable outputs from the cmd prompt just like I showed you in my first post.It looks like it is likely UK date output, which expands DD/MM/YYYY. Let's modify for that and see if it works out better for the OP. Quote from: Raven19528 on January 11, 2012, 11:47:40 AM It looks like it is likely UK date output I think I once saw the Artilleryman at Horsell Common, near Woking. Quote from: Squashman on January 11, 2012, 10:39:46 AM You need to show me how the date variable outputs from the cmd prompt just like I showed you in my first post. OK I've worked out the first line for saving today's date SET TODAY=%date:~0,2%-%date:~3,2%-%date:~6,4% this gives me 12-01-2012 I'm using C:\myprog\myprog.exe which starts the prog OK, but after loading the prog the batch file stops and only completes after exiting the prog, what I realy need to do is reset the date once the prog has loaded. Line 3 start "" "C:\myprog\myprog.exe" IGNORES the date change.Here is an excerpt from the start /? text that I think specifies the problem: Code: [Select]Microsoft Windows [Version 6.1.7601] When executing an application that is a 32-bit GUI application, CMD.EXE does not wait for the application to terminate before returning to the command prompt. This new behavior does NOT occur if executing within a command script. The way around this is to "start" a different command process, which in turn starts the program, but never takes control away from your original batch file. Example: Code: [Select]SET TODAY=%date:~0,2%-%date:~3,2%-%date:~6,4% REM setting date back to an older date DATE 12-11-11 (echo start "" "C:\path to my program\myprogram.exe" echo del ^%^0) >tempstart.bat start "" tempstart.bat REM Changing date back to todays date ping 1.1.1.1 -n 1 -w 2000>nul DATE %TODAY% This may or may not be a long enough delay (2 seconds), but it does institute a slight delay before changing the date back to today. If this isn't required, you can remove the ping line. Quote from: The Artilleryman on January 12, 2012, 10:17:27 AM which starts the prog OK, but after loading the prog the batch file stops and only completes after exiting the prog, what I realy need to do is reset the date once the prog has loaded.I don't throw out random code for my good health. I gave you the correct code for starting the program in my first post. I had no control over the date output as I explained in both of my previous posts because anyone can change the short date format in their regional settings.Hi all This is my elegant solution to solving the date issue Edit launch to read the Progam Just amend the dates 01/01/2012 to whatever date you require Amend c:\...... to the shortcut properties of the program you wish to run When you exit the program the date will rest to today! Just copy and paste into notepad and SAVE as a .bat file ECHO OFF CLS :MENU ECHO. ECHO ....................................... ........ ECHO PRESS 1 to select your task, or 2 to EXIT. ECHO ....................................... ........ ECHO. ECHO 1 - Launch xxxxxxxxxxxx ECHO 2 - Exit ECHO. SET /P M=Type 1, 2, then press ENTER: IF %M%==1 GOTO PROGRAM IF %M%==2 GOTO RESETDATE :PROGRAM FOR /F "TOKENS=1* DELIMS= " %%A IN ('DATE/T') DO SET CURDATE=%DATE% COLOR 4f echo Setting System date to 01/01/2012 echo. date 01/01/2012 echo Launching Program........Please Wait echo. "c:\xxxxxxxxx.exe" echo Resetting System Date back to Todays Date....Please Wait date %CURDATE% Hope this helps Jules Code: [Select]SET /P M=Type 1, 2, then press ENTER: What will happen if the user TYPES 3 or just presses ENTER? None of the scripts in this thread should be run sufficiently close to midnight that the line with the start command finishes the next day. Nothing! You could delete the first section and just run the program batch file but remember running a date change could corrupt other files you save and will certainly impact your internet browser home page so be careful - hence to 1 or 2 check to make sure. Julian Quote from: jjh281 on February 29, 2012, 01:50:00 PM Nothing! If the user types 3 and presses Enter, neither of the following IF tests will be satisfied, so the script will fall through to :PROGRAM, and if they just press ENTER, then %M% will be set to an empty string, and the script will halt with an error at the first IF test. |
|
| 747. |
Solve : get the sum of %errorlevel% at the end of a subroutine.? |
|
Answer» I composed a batch file to ping a list of DEVICES, and return a notification whenever a device did not reply. These errors are also prepend to an existing logfile. [PM] Thanks for the tip, where did you INTEND to insert it? I don't see why I should return anywhere, or am I missing something.Who did you recieve a PM from ? ?PM stands for private message, so let's keep that private. I PRESUME that that person has good reasons why not posting in public. He has the right to do so and I think we should respect that. What does it matter anyway?....Do as you like... I have a good reason for asking.Okay, I'm still not with you but nevertheless... Do you have any suggestions?If you want help privately then do it through some other means. This is a help forum. All answers to a thread need to be posted here. Makes absolutely no sense to get some of your help from a PM and some of it here in your thread.what the Why do you think I post my question on this forum? I didn't pm myself to give this suggestion, some other guy did. I was just being open by posting his pm to the public as I figured it could also be useful to others. and I wanted some more explanation on his thought. so why are you dissing me with this shite, I just want some advice from experienced users, but it seems to me they aren't here..... the room is full of old tarts! Quote from: osvikvi on February 22, 2012, 09:31:12 AM the room is full of old tarts! Yeah, that's a really good way to get people to help. Labeling the whole based on the replies of the few. Please forgive me if I'm not my usual helpful, explanatory self. If you want one check after the list of ips has run through, try this: Code: [Select]ping -n 1 %1 IF %ERRORLEVEL% EQU 1 ( ECHO ** # %1 - %2 is not responding ** >> %tnm% mplayerc.exe /minimized /play /close "dingdong.wav" MSG "%username%" /TIME:600 %2 - %1 is not responding set erry=1 ) Then after your REN command in label3, put: Code: [Select]ren "testtemp.txt" "testpingme.txt" if "%erry%"=="1" (cscript yesno.vbs) goto :eof Alternatively, try this in your subroutine if you want it to check after each time the subroutine runs: Code: [Select]ping -n 1 %1 IF %ERRORLEVEL% EQU 1 ( ECHO ** # %1 - %2 is not responding ** >> %tnm% mplayerc.exe /minimized /play /close "dingdong.wav" MSG "%username%" /TIME:600 %2 - %1 is not responding cscript yesno.vbs ) Next time you are looking for help, try not to call the person/people capable of helping you "old tarts." Usually, it doesn't get you the results you are hoping for. Keep it clean...we have Members of all ages here. Quote from: osvikvi on February 22, 2012, 09:31:12 AM and I wanted some more explanation on his thought.I have no idea what they were thinking. I am not omniscient. Maybe you should ask the person to post here and explain themselves better.That's why I posted his pm here in the open. I couldn't reply to his pm for some reason. Anyway, Thanks Raven19528 I'll give it a try when I return to the office. to set things straight I said "it seems..." Sorry Patio, you may clean-out the irrelevant stuff, I would do it myself but I can't edit my posts.. Thanks for your supportNo problem...HOORAY works like a charm, thanks Raven19528. As usual the solution is simple, you just have to come up with it! Now I have only one messageprompt and at the end of the cycle. giving me the option to open the logfile containing the errors. Maybe I can show these errors in the vbs messagebox, is there any way to port %erry% to another script? Thanks a lot Quote is there any way to port %erry% to another script? I hope it's not bad manners of me to jump in here, but you can pass parameters to a VBScript on the command line like so (I always use //nologo) cscript //nologo Scriptname.vbs "p1" "p2" "p3" (etc) (quotes are stripped in the script) and in the VBScript there is an object called WScript.Arguments that acts like a zero-based array so that: WScript.Arguments(0) will be p1 WScript.Arguments(1) will be p2 WScript.Arguments(2) will be p3 You are not limited to 9 parameters like in batch, but total command line string length cannot exceed 8192 characters. |
|
| 748. |
Solve : Send an ENTER command to an Executable program? |
|
Answer» I hope this has not been already answered in another THREAD, but here's what I really NEED to do. XP Pro, Vista, Win-7 or Win-8 Eh? Your "customers" run all those operating systems? Including unreleased ones? Anyhow, cleanmgr is not the same on all those OSs. Vista and 7 have new switches compared to XP. Quote so the user doesn't have to manually click the [OK] button. But they are "manually" clicking the shortcut icon; their hand is on the mouse, what difference will another click or two make? If you did a reg QUERY you could check to see if the registry entry exists already. If it does then you don't need to use the SAGESET. Ok, I guess some clarification is needed. My customers who I set up a weekly maintenance routine for, do use XP, Vista and Win-7 and I'm personally testing Win-8/DP, so I'm trying to find things that will work across multiple OS's. But what I'd like to do is set up Disk Cleanup to run from a batch file, not from a desktop shortcut, so I don't have to depend on an 86 yr old gramma to do her weekly maintenance, which many of them won't. I'd like for it to run without user intervention, just like my XPCleanup.bat program, which I do put in the Startup folder, for a little daily maid service. I'd like to be able to add Disk Cleanup to the end of my own XPCleanup.bat program. It's just that Disk Cleanup addresses some System Folders that I've not previously identified, to add them to my cleanup batch file. The one I use on my own PC, is customized for my own use and has over 40 lines in it now. When I do a cleanup, I really do a CLEANUP! I don't mess around with it! I did figure out how to empty the trash cans (recycle bins) with a batch file, so now I empty those too. I'm just trying to do the best possible job for my customers, that I can do with the very minimal things for them to do. My goal (someday) is for a totally self maintaining PC. I use AV and AS software that updates and scans by itself every day and I have my Cleanup batch file that runs on every boot up, so the user can enjoy their PC without having to worry about the maintenance aspect of it. thanks for all your help, The Shadow Quote from: Squashman on February 19, 2012, 04:19:30 PM If you did a reg query you could check to see if the registry entry exists already. If it does then you don't need to use the SAGESET. Well, you're on the right track. If I manually run sageset, then I can run Sagerun as many times as I like and still wont have to change anything. Good point! Yous guys have got me thinking outside the box, and for this 68 year old, that's a GOOD THING! Cheers Mates! The Shadow I'm back! Salmon Trout, if memory serves me, you've helped me out before and sure enough you've done it again. echo. | program.exe This suggestion of yours works perfectly. I put the Disk Cleanup command at the end of my XPCleanup.bat batch file and it runs without user intervention. I did remove sageset from the command line, since the parameters only need to be set once and I can do that when I first install the batch file for my customer. Moving right along................ Many Thanks! The Shadow B)The reason it runs without user intervention is because you took the SAGESET out.I'm getting the WHOLE picture now. No, it runs automatically because of the help given to me by Salmon Trout to pipe the CR into the program when it runs. That was a huge help that I may be able to use again. Taking out Sageset was just a part of my learning curve. You still have to run cleanmgr with sageset at some point to set up the choice for what things will be removed. I know I'll get another argument about this, but I always check everything, but, Office Setup Files, Setup LOGS and Compress old files. After I run my registry tweaks, Compress old files is not even in the list. I'm working on a batch file to run from my Utilities disk, to install the Extended version of Disk Cleanup, into the Startup Folder, after first running cleanmgr with sageset, to set the parameters for later running cleanmgr with sagerun. I always try to automate the install process as much as I can to save valuable time, while at a customer's home. I have it nailed down now. Case Closed! Thanks for all the help, The Shadow PS: Now that I have the process nailed down for XP, I'll be working to make sure it works as well in Vista and Win-7 and Win-8. Quote from: TheShadow on February 19, 2012, 05:02:17 PM
Once you have done the sageset part, subsequent runs of cleanmgr /sagerun:NN should run without you doing this. (I just tried it) I've created a batch file, to install my new XPCleanup batch file into the Startup folder. At the end of my XPCleanup batch file is the line to automatically run Disk Cleanup (cleanmgr.exe) in the automatic mode. Like you said, in my install batch file, I run cleanmgr with sageset to set up the things to delete and then when I run cleanmgr with only the sagerun switch, it deletes only what was previously set up with sageset. I can minimize my XPCleanup batch file when it runs, but Disk Cleanup still pops up on-screen and runs without the user having to press the obligatory 'OK' button. I'd rather not actually see Disk Cleanup at all, but that's OK. I can live with that. It's neat, clean and definitely helps to keep a PC clean and running at peak performance. I've been working on my Cleanup.bat program since the '98 days and it's still a work in progress. Every time a find a new hiding place for junk files, I add that location (path) to a new line in my Cleanup batch file. This is just one little step in a whole litany of things I do to set up or tune up a PC. My goal has been and is still to set up a PC to run at maximum efficiency from one year to the next with little or no hands-on maintenance. Because most users just Won't Do It. The build-up of JUNK or Crapola as I like to call it, is one of the biggest problems in any PC. It loads up the hard drive, slows down all scans and can greatly increase the time and space to do a backup. One of my favorite quotes is "Minus CRUD is COOL!" Thanks again, The Shadow B)Shadow, I can't get the pipe to work when using SAGESET. Not sure how you are getting it to work. Salmon Trout does it work for you when using SAGESET? Quote from: Squashman on February 20, 2012, 06:59:34 AM Shadow, I can't get the pipe to work when using SAGESET. Not sure how you are getting it to work. No; see my reply above (Post 4 of this thread). You cannot send a CR to cleanmgr via a pipe. When using /sageset it requires the OK button to be pressed. When /sageset has been used and the registry entry has been saved, then cleanmgr /sagerun:NN does not need ENTER to be sent to it, and will ignore any that are sent. |
|
| 749. |
Solve : I've forgotten DOS commands, please help.? |
|
Answer» I'm trying to change the attributes of a read only file by using MS DOS. The commands are Try Norton Utilities FA.EXE (File Attributes) Not everyone out there has Norton... Quote from: patio on February 17, 2012, 05:59:13 AM Not everyone out there has Norton... And nobody in their RIGHT mind would use 16-bit DOS disk utilities within a windows environment, for any purpose. |
|
| 750. |
Solve : delete first n lines from a file? |
|
Answer» hi all, If you till tell me the maximum length of the a line, I can make you a quick program that will let you enter the number of lines to skip and then willl copy the rest of the file.That seems kind of limited if you ask me. Granted the cmd processor is limited to 8192 bytes to assign to a variable but what are the odds of the lines being that long.A For loop will probably not copy blank lines. Use the More command with the +n switch. Quote from: Dusty on February 19, 2012, 11:52:49 PM A For loop will probably not copy blank lines. Or ones starting with a space or semicolon, I think. And poison characters will STOP the script dead. Barring any line starting with a colon this will work. I can change the code as well if the file has a line that starts with a colon. Input Code: [Select]Line:1 Line:2 Line:3 Line:4 Line:5 Line:6 next line is blank Line:8 next line has special characters #[email protected]#$%^&*()+<>"':!%%! Line:10Script Code: [Select]echo off for /f "skip=5 tokens=1* delims=:" %%G in ('type "myfile.txt" ^| findstr /n "^"') do echo.%%H>>myfile_new.txtOutput Code: [Select]Line:6 next line is blank Line:8 next line has special characters #[email protected]#$%^&*()+<>"':!%%! Line:10Keeping to the KISS principle: Code: [Select]more +n myfile.txt > newfile.txt Quote from: Dusty on February 20, 2012, 11:11:05 PM Keeping to the KISS principle:As far as I can tell that will not work if the number of lines in the FILES exceeds 65,534. Which most of mine do. I do data processing for a living. On the 65,535 line it outputs -- More (4%) -- to the output file and the batch file pauses. Quote from: Squashman on February 21, 2012, 05:42:01 AM As far as I can tell that will not work if the number of lines in the files exceeds 65,534. Which most of mine do. skipline.vbs Code: [Select]Const ForReading = 1 Const ForWriting = 2 Set objFSO = CreateObject("Scripting.FileSystemObject") ReadFileName = wscript.arguments(0) LinesToSkip = wscript.arguments(1) WriteFileName = wscript.arguments(2) ' for demo purposes; can delete '-------------------------------------- StartRead = Timer '-------------------------------------- Set ReadFile = objFSO.OpenTextFile (wscript.arguments(0), ForReading) strText = ReadFile.ReadAll Readfile.Close ' for demo purposes; can delete '-------------------------------------- EndRead = Timer ReadTime = EndRead - StartRead StartSplit = Timer '-------------------------------------- ArrayOfLines = Split(strText, vbCrLf) ' for demo purposes; can delete '-------------------------------------- Endsplit = Timer SplitTime = Endsplit - StartSplit StartWrite = Timer '-------------------------------------- Set Writefile = objFSO.CreateTextFile (WriteFileName, ForWriting) For j = LinesToSkip To UBound(ArrayOfLines) Writefile.writeline ArrayOfLines(j) Next Writefile.Close ' for demo purposes; can delete '-------------------------------------- EndWrite = Timer TotalTime = EndWrite - StartRead WriteTime = EndWrite - StartWrite wscript.echo "Number of Lines in file: " & UBound(ArrayOfLines) wscript.echo "Read file in " & ReadTime & " sec(s)" wscript.echo "Split file in " & SplitTime & " sec(s)" wscript.echo "Wrote output file in " & WriteTime & " sec(s)" wscript.echo "Total time taken " & TotalTime & " sec(s)" '-------------------------------------- Code: [Select]C:\Batch\Test\>type 20lines.txt This is line 1 This is line 2 This is line 3 This is line 4 This is line 5 This is line 6 This is line 7 This is line 8 This is line 9 This is line 10 This is line 11 This is line 12 This is line 13 This is line 14 This is line 15 This is line 16 This is line 17 This is line 18 This is line 19 This is line 20 C:\Batch\Test\>cscript.exe //nologo skipline.vbs "20lines.txt" 3 "outlist.txt" Number of Lines in file: 20 Read file in 0 sec(s) Split file in 0 sec(s) Wrote output file in 0.0078125 sec(s) Total time taken 0.0078125 sec(s) C:\Batch\Test\>type outlist.txt This is line 4 This is line 5 This is line 6 This is line 7 This is line 8 This is line 9 This is line 10 This is line 11 This is line 12 This is line 13 This is line 14 This is line 15 This is line 16 This is line 17 This is line 18 This is line 19 This is line 20 Note: the load and split times for the small file are too short for the VBScript timer function to measure. Now for some real files... Clist.csv has nearly 300,000 lines like this and is 36 MB in SIZE "CreationTime","Length","FullName" "04/06/2011 08:43:43","4226277376","C:\pagefile.sys" "02/06/2011 21:08:43","3169705984","C:\hiberfil.sys" "05/03/2011 08:14:10","2376366352","C:\Documents and Settings\Mike\X15-65732.iso" "05/03/2011 08:14:10","2376366352","C:\Users\Mike\X15-65732.iso" "07/07/2011 20:39:09","1818939392","C:\Users\Mike\AppData\Local\Microsoft\Windows Virtual PC\Virtual Machines\Windows XP Mode.vhd" "07/07/2011 20:39:09","1818939392","C:\Documents and Settings\Mike\AppData\Local\Microsoft\Windows Virtual PC\Virtual Machines\Windows XP Mode.vhd" Code: [Select]C:\Batch\Test\>cscript.exe //nologo skipline.vbs "Clist.csv" 3 "outlist.txt" Number of Lines in file: 294457 Read file in 1.953125 sec(s) Split file in 0.6328125 sec(s) Wrote output file in 3.632813 sec(s) Total time taken 6.21875 sec(s) Big-Clist.csv has nearly a million lines and is 108 MB in size Code: [Select]C:\Batch\Test\>cscript.exe //nologo skipline.vbs "Big-Clist.csv" 3 "outlist.txt" Number of Lines in file: 883371 Read file in 5.164063 sec(s) Split file in 5.390625 sec(s) Wrote output file in 10.95313 sec(s) Total time taken 21.50781 sec(s) System: AMD Phenom II 3.0 GHz 4 GB RAM drive: 7200 rpm SATA Nice Job. Vbscript has always been one of those things I have just refused to learn.In my script above, is this: Code: [Select]Set ReadFile = objFSO.OpenTextFile (wscript.arguments(0), ForReading) That will work, but for consistency it should be Code: [Select]Set ReadFile = objFSO.OpenTextFile (ReadFileName, ForReading) Quote Vbscript has always been one of those things I have just refused to learn. It's not all that HARD, especially if you can use it to do useful things, and it can do so much more than batch. Of course Powershell is the way to go nowadays... I started pushing myself to use Powershell 2 years ago and then I went on vacationand when I got back to work I said screw it. But it made me realize that object oriented programming is pretty awesome. I was even making gui's with my Powershell scripts. |
|