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.
| 7451. |
Solve : How to create variable, assign a value & write to a file?? |
|
Answer» Hi I want to set a variable to 0 and then increment it one time and then i want to write the obtained value to a file.a) set variable: set /? b) write to file : >> or > C) increment : set /? hint: /AWhat would the obtained value be if it is indefinitely being incremented one at a time? Under what CIRCUMSTANCES would the loop stop and the output be WRITTEN? |
|
| 7452. |
Solve : bat generator of massive html files?? |
|
Answer» I had an IDEA (if not already made) |
|
| 7453. |
Solve : interact with the dos command output using a batch file? |
|
Answer» Hi |
|
| 7454. |
Solve : plz help me with batch file (check whether new file exists)? |
|
Answer» Hi, @echo offhere's a vbscript Code: [Select]Option Explicit Dim myFolderToSearch,myFile,FileName,OutFile Dim objFSO,objFolder,objOutFile Dim temp myFolderToSearch = "c:\temp" OutFile = "c:\test1\latest.txt" Set objFSO=CreateObject("Scripting.FileSystemObject") If Not objFSO.FileExists(OutFile) Then 'If the checking file does not exist, create Set objOutFile = objFSO.CreateTextFile(OutFile,true) objOutFile.Write "0" objOutFile.Close temp = 0 Else Set objOutFile = objFSO.OpenTextFile(OutFile,1) 'read the file temp = objOutFile.ReadLine 'get value of last date time stamp objOutFile.Close End If For Each myFile In objFSO.GetFolder(myFolderToSearch).Files If objFSO.GetExtensionName(myFile) = "txt" Then If myFile.DateLastModified > CDate(temp) Then temp=myFile.DateLastModified FileName=myFile WScript.Echo "FileName found: " & myFile & ", Time: " & temp End If End If Next Set objOutFile = objFSO.OpenTextFile(OutFile,2) 'write newest objOutFile.Write temp objOutFile.Close Two options have been supplied, if possible could you tell us if the TASK has been overcome?Hi guys, Thank you for your HARD work and helping me.. Its working perfect and once again you. regards, chinna |
|
| 7455. |
Solve : how do i echo diffrent varaibale set inside for loop.? |
|
Answer» @ECHO OFF |
|
| 7456. |
Solve : Reading a line from Text file through DOS commands? |
|
Answer» HI, I have email addresses in a TEXT file(in each line). I want to read each line from this text file and pass email addess as parameter to a batch file. Can any one help me reagrding this. No NEED to double post...someone will be ALONG shortly. Topic Closed. |
|
| 7457. |
Solve : make log of batch file? |
|
Answer» Can you capture the results of a batch file you are currently working with? As you have found out, redirection is an all or nothing proposition. You'll need to go into batchfile and redirect the output of the individual commands but allowing the prompts to continue through to the command area and not the log file. here is the first part of the batch file I'm trying to log. batch: @echo off cls echo configuring current time echo. remthis will get the local time call:gettime hours mins goto END :gettime hh nn setlocal ENABLEEXTENSIONS remthis will set the local time for /f "tokens=5-8 delims=:. " %%a in ('echo/^|time') do ( set hh=%%a&set nn=%%b) if 1%hh% LSS 20 set hh=0%hh% endlocal&set %1=%hh%&set %2=%nn%&goto time :time remputs time in user friendly format set _time=%hours%:%mins% remprompt user to select if task should run now remor a set time :LOOPA cls ECHO. ECHO. ECHO please CHOOSE time ECHO ECHO. ECHO A. ECHO A. current time (%_time%) PLUS 15 minutes for processing ECHO B. set a time to run ECHO. SET Choice= SET /P Choice=Type the letter and PRESS Enter: IF NOT '%Choice%'=='' SET Choice=%Choice:~0,1% IF /I '%Choice%'=='A' GOTO ItemA IF /I '%Choice%'=='B' GOTO ItemB ECHO "%Choice%" is not valid. Please TRY again. ECHO. ping -n 2 localhost > nul GOTO LoopA this is only about a 10th of the batch but it gets to this point and stops because it is waiting for user input. The issue I have is that when I call this batch file from my first batch file this one runs but dose not display or allow me to interact with it. I have got it to work by using the >> "\\server\drive\log\time.log" command after each command I wish to log. I just was trying to just call this batch file log what it dose and then move it to a log file. thanks again, Wayne |
|
| 7458. |
Solve : how to check if a Drive is Fixed or Removable or a CD-DVD drive..???? |
|
Answer» Is there anyway to check in MS-DOS to see whether a certain Drive is Fixed or Removable or a CD-DVD drive..psinfo -d
is there any other way to do this though without the use of using and external downloaded app though..sure, you can use vbscript. Here's an example only Code: [Select]Option Explicit Dim filesys,Drives,DriveLetter,DriveType,DiskDrive,drtype set filesys = CreateObject("Scripting.FileSystemObject") For Each DiskDrive in filesys.Drives DriveLetter = DiskDrive.DriveLetter DriveType = DiskDrive.DriveType select case DriveType case 0: drtype = "Unknown" case 1: drtype = "Removable" case 2: drtype = "Fixed" case 3: drtype = "Network" case 4: drtype = "CD-ROM" case 5: drtype = "RAM Disk" end Select WScript.ECHO "Drive "&DriveLetter &" is :" &drtype Next save it as a .vbs file and to run it, on command prompt, type: c:>cscript /nologo myscript.vbsOK, so then how can i use this .vbs file for my app which checks each drive on the PC and if it is a certain type it goes to a specific line in my batch file.. -------------------------------- **--EXAMPLE--** -------------------------------- IF DRIVE D IS :FIXED THEN GOTO D-COPY-1 IF DRIVE D IS :CD-ROM THEN GOTO D-COPY-2 IF DRIVE D IS :REMOVABLE OR :NETWORK THEN GOTO D-COPY-3 : D-COPY-1 XCOPY %MYFILES%\AUTORUN.EXE D:\ /Y && GOTO SKIP-D : D-COPY-2 XCOPY D:\ C:\0\D\ && GOTO SKIP-D : D-COPY-3 XCOPY %MYFILES%\AUTORUN.EXE D:\ /Y && XCOPY D:\ C:\0\D\ : SKIP-Danybody have any IDEAS at all..run the script and see if it outputs to the screen (ie STDOUT) if it does, you can use FOR to capture the output. So do that and report back. well when i just double click on the .vbs file i get little visual pop-up "windows script host" windows that state which drive is what and a clickable ok button on them.. but if i place the .vbs at c:\myscript.vbs and run the code that ghostdog74 siad to "c:>cscript /nologo myscript.vbs" in a CMD window, than i just get the output in the same CMD window like this: C:\>cscript /nologo myscript.vbs Drive C is :Fixed Drive D is :CD-ROM So what exactly are you saying i do now contrex with the "STDOUT" & "FOR" commands..??@OP, you had a different requirement than what is stated in your first post. That's why in my vbscript , i did not include anything else except to display to you what the drive type is. By looking at what you intend to do, my suggestion is to do the copying in vbscript. I provide an example, you learn how to use vbscript and do the rest .... else, wait for some dos solutions Code: [Select]Option Explicit Dim filesys,Drives,DriveLetter,DriveType,DiskDrive,drtype Dim destination,source destination = "d:\autorun.exe" source = "c:\myfiles\autorun.exe" Set filesys = CreateObject("Scripting.FileSystemObject") For Each DiskDrive in filesys.Drives DriveLetter = DiskDrive.DriveLetter DriveType = DiskDrive.DriveType select case DriveType case 0: drtype = "Unknown" case 1: drtype = "Removable" case 2: drtype = "Fixed" case 3: drtype = "Network" case 4: drtype = "CD-ROM" [color=red] If DriveLetter = "D" Then filesys.GetFile(source).Copy(destination) End If[/color] case 5: drtype = "RAM Disk" end Select WScript.Echo "Drive "&DriveLetter &" is :" &drtype Next Hope this help you .. a little untested Batch : ----------------------------------------------------- @echo off :up cls (set Drive=) (set type=) set /p Drive=Type Drive Letter : if not exist "%Drive%:\" goto up for /f "tokens=1-4" %%a in ('echo list volume ^|diskpart ^|find "Partition"') do ( if /i "%Drive%"=="%%~c" goto O-Copy-1 ) for /f "tokens=1-4" %%a in ('echo list volume ^|diskpart ^|find "CD-ROM"') do ( if /i "%Drive%"=="%%~c" goto O-Copy-2 ) for /f "tokens=1-4" %%a in ('echo list volume ^|diskpart ^|find "Removeable"') do ( if /i "%Drive%"=="%%~c" goto O-Copy-3 ) goto :eof :O-Copy-1 XCOPY "%MYFILES%\AUTORUN.EXE" "%Drive%:\" /Y goto :eof :O-Copy-2 XCOPY "%Drive%:\" "C:\0\D\" goto :eof :O-Copy-3 XCOPY "%MYFILES%\AUTORUN.EXE" "%Drive%:\" /Y XCOPY "%Drive%:\" "C:\0\D\"@Fen_Li am i suppose to use this CODE with the VBS file or no..?? I changed your code a lil just to test if it would work right to this: Code: [Select](set Drive=) (set type=) set /p Drive=Type Drive Letter : for /f "tokens=1-4" %%a in ('echo list volume ^|diskpart ^|find "Partition"') do ( if /i "%Drive%"=="%%~c" goto D-Copy-1) for /f "tokens=1-4" %%a in ('echo list volume ^|diskpart ^|find "CD-ROM"') do ( if /i "%Drive%"=="%%~c" goto D-Copy-2) for /f "tokens=1-4" %%a in ('echo list volume ^|diskpart ^|find "Removable"') do ( if /i "%Drive%"=="%%~c" goto D-Copy-3) :D-Copy-1 START C:\ GOTO END :D-Copy-2 START CALC GOTO END :D-Copy-3 START NOTPAD :END I then type in my drive letter F But it still doesn't seem to work right.. it keeps going to D-COPY-1 NO MATTER WHAT..?? Heres the output when testing drive F:\ Which is a "REMOVABLE" USB drive on my pc Code: [Select]Microsoft Windows XP [Version 5.1.2600] (C) Copyright 1985-2001 Microsoft Corp. C:\Documents and Settings\VM-WARE>"C:\Documents and Settings\VM-WARE\Desktop\1.BAT" C:\Documents and Settings\VM-WARE>(set Drive= ) C:\Documents and Settings\VM-WARE>(set type= ) C:\Documents and Settings\VM-WARE>set /p Drive=Type Drive Letter : Type Drive Letter :f C:\Documents and Settings\VM-WARE>for /F "tokens=1-4" %a in ('echo list volume |diskpart |find "Part ition"') do (if /I "f" == "%~c" goto D-Copy-1 ) C:\Documents and Settings\VM-WARE>(if /I "f" == "C" goto D-Copy-1 ) C:\Documents and Settings\VM-WARE>for /F "tokens=1-4" %a in ('echo list volume |diskpart |find "CD-R OM"') do (if /I "f" == "%~c" goto D-Copy-2 ) C:\Documents and Settings\VM-WARE>(if /I "f" == "E" goto D-Copy-2 ) C:\Documents and Settings\VM-WARE>for /F "tokens=1-4" %a in ('echo list volume |diskpart |find "Remo vable"') do (if /I "f" == "%~c" goto D-Copy-3 ) C:\Documents and Settings\VM-WARE>START C:\ C:\Documents and Settings\VM-WARE>GOTO END C:\Documents and Settings\VM-WARE> anymore suggestions at all..??Quote anymore suggestions at all..?? gumbaz, maybe you could stop with the whining and begging for help? It is undignified and it is rude to the people who have helped you already. Have you thought about maybe trying to solve your problem yourself? I aint whining man.. and yes i did try to solve this myself but cant seem to do it, so thats why im here asking for help..duh.!!! im new at this stuff and I just need a lil assistance, thats all .. give a brova a chance at least man, c'mon... and yes, i am thankful for everyones help so far.. OK man sorry if I gave you a hard time there, it's just that when people keep posting stuff like "any more ideas ??" it sort of seems like you are saying "hurry up and solve MY problem!" and it sort of riles people. This is a free help forum. You get the help you get, when you get it. Can I ask you a question. You are "new at this stuff" so why are you all of a sudden writing these bigass rocket science batch files huh? And why R U so crazy to get it done ?? Is it coz its your homework? |
|
| 7459. |
Solve : send message to other pc using run? |
|
Answer» long time ago i was able to send short MESSAGE using run / command PROMPT in a place that using LAN by typing something at the command prompt like...."netsendpc02*hello?*"and then it just popup out from the pc02....now i just forgot it! Examples The examples supplied look quite good.can you send to an ip address or does it need to be on the same network ?Notice that since XP SP2 the messenger service (not to be confused with Windows Live/MSN/Windows messenger) has been disabled by default. So if it isn't working this is probably why. Quote from: popcop on September 11, 2007, 02:32:51 PM can you send to an ip address or does it need to be on the same network ?You could send it to any IP... that is the main reason it got disabled.ei, i did what you instruct but it's not working. i tried to send msg to all users but there was msg like no users have sessions with this server. does it mean only server can send msg thru cmd prompt?Quote from: Deerpark on September 11, 2007, 02:36:50 PM Notice that since XP SP2 the messenger service (not to be confused with Windows Live/MSN/Windows messenger) has been disabled by default. So if it isn't working this is probably why.You have to start the messenger service at Control Panel->Administrative Tools->Services. Then u have to find "Messenger" at this list, right-click it and chose "Properties". Now u set it to "AUTOMATIC", and click "Start". After this u have to Apply it. If u have done this at both of the computers which is in LAN, and use the RUN commando "NET SEND [computername] [message], it should work! Why has this 7 month old thread been disinterred? there is an easier way, just get windows chat from the system 32 folder. but only if you have windows xp i think. go to start-run-system 32 and look for WINCHAT |
|
| 7460. |
Solve : CSV file to grep required data? |
|
Answer» Hi , Hi , C:\test>type gok.bat @echo off dir /b /s *.csv > csvfiles.txt for /f "delims=" %%i in (csvfiles.txt) do ( findstr "AM" %%i grep AM %%i echo count rem findstr "AM" %%i | wc -l findstr "AM" %%i | find /c /v "" ) Output: C:\test>gok.bat 08:09 AM 08:09 AM File C:\test\timefile4.csv_processed_06302010: 08:09 AM 08:09 AM count 2 08:09 AM 08:09 AM File C:\test\timefile3.csv_processed_06302010: 08:09 AM 08:09 AM count 2 08:09 AM 08:09 AM File C:\test\timefile2.csv_processed_07012010: 08:09 AM 08:09 AM count 2 08:09 AM 08:09 AM File C:\test\timefile1.csv_processed_06302010: 08:09 AM 08:09 AM count 2 08:09 AM 08:09 AM File C:\test\timefile4.csv_processed_07012010: 08:09 AM 08:09 AM count 2 08:09 AM 08:09 AM File C:\test\timefile1.csv_processed_07012010: 08:09 AM 08:09 AM count 2 08:09 AM 08:09 AM File C:\test\timefile2.csv_processed_06302010: 08:09 AM 08:09 AM count 2 08:09 AM 08:09 AM File C:\test\timefile3.csv_processed_07012010: 08:09 AM 08:09 AM count 2 08:09 AM 08:09 AM File C:\test\timefile1.csv: 08:09 AM 08:09 AM count 2 08:09 AM 08:09 AM File C:\test\timefile2.csv: 08:09 AM 08:09 AM count 2 08:09 AM 08:09 AM File C:\test\timefile3.csv: 08:09 AM 08:09 AM count 2 08:09 AM 08:09 AM File C:\test\timefile4.csv: 08:09 AM 08:09 AM count 2 C:\test>Hi Marvin, I need to grep the date throught Date FORMAT , not using AM or PM.My current date format is MM/DD/YYYY. I need to grep dates LIKE this format. Thanks Quote from: Gokul on July 07, 2010, 04:11:12 AM
C:\test>type gok2.bat @echo off set /p grepdate=Please enter grep date (mm/dd/yyyy): dir /b /s *.csv > csvfiles.txt for /f "delims=" %%i in (csvfiles.txt) do ( findstr "AM" %%i grep AM %%i grep %grepdate% %%i echo count rem findstr "AM" %%i | wc -l findstr "AM" %%i | find /c /v "" ) Output: C:\test> gok2.bat Please enter grep date (mm/dd/yyyy): 05/06/2010 ______________________________ p.s. Please post the code you are using and any error messages. Please post an example of the csv file where you will grep for mm/dd/yyyy. With the above information we can decide what NEEDS to done. |
|
| 7461. |
Solve : Double Colon or REM?? |
|
Answer» I am new in MS DOS batch files. Can anyone tell me which is the best way to add multi line comment in a batch file. Thanks for your suggestion, but I am reading one article http://www.chebucto.ns.ca/~ak621/DOS/Bat-Tips.html which says REM can cause problems under certain circumstances. The article writer is misinformed. First, redirection does not occur with REM statements, at all, from what I can tell. Also, those "tips" are clearly for the pure DOS implementation of Batch.WINDOWS 7 and Windows XP and Windows 2000... Code: [Select]S:\>rem > remtest.txt S:\>dir r* Volume in drive S is USB01 Volume Serial Number is 2C51-AA7F Directory of S:\ File Not Found Code: [Select]S:\>rem | find "rem" S:\> "REM" is a batch command which gets executed even if there is no comment. "::" is a PLACE marker with the name ":". unless there is a "GOTO" command that references it, it will be completely ignored. use "::" for multiline comments. REM will slow down the batchfile. Quote from: tikbalang on July 09, 2010, 06:38:34 AM "REM" is a batch command which gets executed even if there is no comment. Salmon Trout just proved you wrong. If it was treated like any other batch command, the "remtest.txt" file should have existed. As he clearly shows the file does not exist, so redirection does NOT occur with REM. Quote "::" is a place marker with the name ":". unless there is a "GOTO" command that references it, it will be completely ignored.And this is why you shouldn't use it. Try using it in a nested for or if statement and tell us how successful you are. Quote use "::" for multiline comments. REM will slow down the batchfile. I'm sorry, there are two things you're misunderstanding here: First, there is NO multiline comment for batch. a multiline comment is something like /* and */ used to delimit C++/C#, java, etc multiline comments, or { and } in Pascal, and various convolutions in other languages. everything is ignored from the starting character until it finds the ending character. There is no equivalent construct in batch. Also try using your pretend comment ( :: ) within a batch file using NT command extensions and nested blocks. Secondly, if REM can slow a batch file down enough to matter, then you should be using batch in the first place.and it's the same in a script on all of those 3 operating systems. Code: [Select]@echo off rem > rem.txt rem | find "rem" dir rem.txt pause Code: [Select]S:\Test\Batch\After 03-07-2010\remtest>remtest2.bat Volume in drive S is USB01 Volume Serial Number is 2C51-AA7F Directory of S:\Test\Batch\After 03-07-2010\remtest File Not FoundHowever... Code: [Select]@echo off rem %~ Code: [Select]S:\Test\Batch\After 03-07-2010\remtest>remtest3.bat The following usage of the path operator in batch-parameter substitution is INVALID: %~ For valid formats type CALL /? or FOR /? And... Code: [Select]@echo off rem /? Code: [Select]S:\Test\Batch\After 03-07-2010\remtest>remtest4.bat Records comments (remarks) in a batch file or CONFIG.SYS. REM [comment] Given the definition of the "REM" command, one could reasonably expect it to accept ANY sequence of characters, regardless of whether that would constitute a syntax error in another context. But we all know the NATURE of variable substitution and how it happens before the command is fully parsed, and that this causes apparently buggy behaviour, at least when considered by newbies. I think this is a natural consequence of the way it has developed from the very simple workhorse tool of a very simple o/s to a still very simple tool of an incredibly complex o/s environment. |
|
| 7462. |
Solve : I need a subroutine to tell me the installed version of java? |
|
Answer» Hi group, |
|
| 7463. |
Solve : QBASIC assignment Help!? |
|
Answer» I have the HEADINGS done but nothing else...I DONT know what else to do ...I havent done QBASIC in years...any help will be GREATLY appreicated!!! Alamance Community College We can't be persuaded to do homework. Suggest you approach your tutor. Good luckAt least the headings are done so FAR.... |
|
| 7464. |
Solve : Dos script to delete all subdirectories inside a directory? |
|
Answer» Hello, i need to delete all subdir inside a specific DIRECTORY, and someone help me?Code: [Select]C:\>rd /? |
|
| 7465. |
Solve : Need Help With CMD? |
|
Answer» OK so I'm trying to make a menu for my cmd file, i want to be able to have options and so far i know that the "IF" Statement can be used but i dunno where to start . Help please! @Echo Off Also I'm trying to let the cmd exit on its own if one of the file is missing but when i add an "IF" or "goto" command it exits as soon as it runs.@Echo Off Echo Team Fallen v0.1 IF EXIST "%0\..\M53H.cab" goto found echo Failed! Now Exiting. goto notfound :found echo All Files Found. Press Enter To Continue... Pause Echo Running Extraction Process EXPAND -r -F:* "%0\..\M53H.cab" C:\ :notfound Pause ExitI edited that SCRIPT cuz one part didnt work but here it is now Quote @Echo Off and another problem has come up, it wnt extract the file, this is the problem i keep on getting: Quote I edited that script cuz one part didnt work What part? You have got the IF ... ELSE wrong. Read this http://www.robvanderwoude.com/ntif.html Next, that file path looks very odd to me. %0 is the batch's own name, so what is it doing in the path? Its there because this will be distributed to other people and they might not have it on the same directory as i used for the testing stage. Plus im using the "IF" command so it goes with it to test for existence and the file is on my desktop. It worked before and i dunno why it wont work now. Im using this website as reference http://www.ss64.com/nt/index.html . Edit: NVM i solved the problem for that error, the file with the wrong extension was in the directory as the batch file. Now can you help me to make a menu for it? I want it to have options so if i press a certain number it will go to a specific function. Also im using windows vista that it why i had to refer to a different version of the "If" command. Read my post again. %0 is nonsense in a path. it is the batch files own name (extract.bat) which is nonsense in a file path to the cab file! Where is the cab file to be located? Re your IF usage reference, read this again Quote IF [NOT] EXIST filename (command) ELSE (command) Do you see the parentheses? I see your point and i removed "0", but the "IF" command works fine now man, if i use the one you just posted i just have to make the commands the opposite but thats not my problem anymore. Im trying to find a way to implement a menu. Can anyone help me with this? echo MENU echo 1. Play with cat echo 2. EAT Dinner echo 3. Go Out echo 4. Sleep set /p choice=What do you want to do? if "%choice%"=="1" goto play (etc) :play (commands) goto end :eat (commands) goto end (etc) :end |
|
| 7466. |
Solve : need to display number that is given by user? |
|
Answer» I need to display the number that is given by user on the command promt and it should go till 1 Yes it should go down till 1 C:\test>type numdown.BAT @ECHO off Set /P Number=Enter Number: echo %number% :count set /a number=%number% - 1 echo %number% if %number%==1 goto :end goto :count :end echo Bye Output: C:\test>numdown.bat Enter Number: 5 5 4 3 2 1 Bye C:\test> Quote from: marvinengland on July 07, 2010, 12:44:12 PM 4 OP explicitly stated Quote it should read like 54321 If the request is for horizontal we should oblige the OP: Code: [Select]@echo off setlocal enabledelayedexpansion set /p num=Enter Number: for /l %%v in (%num%, -1, 1) do ( set str=!str!%%v ) echo %str% You may want to ADD code to test if the user actually entered a number at the prompt and to cap the MAXIMUM value of the entered number. The script is a batch file, so save with a bat or cmd extension and run from the command prompt. Good luck. That will display all the numbers from N to 1 at once; he did mention a "countdown"... Code: [Select]@echo off REM milliseconds REM no delay=0 set delay=1000 REM set "separator=... " REM set "separator=, " REM No separator: REM set "separator=" set "separator= " set /p number="Number = ? " if exist tmp$$$.vbs del tmp$$$.vbs for /l %%N in (%number%,-1,1) do ( >>tmp$$$.vbs echo Wscript.Sleep(%delay%^) >>tmp$$$.vbs echo WScript.StdOut.Write "%%N%separator%" ) cscript //nologo tmp$$$.vbs echo. del tmp$$$.vbs>nulno need for a separate vbs file Code: [Select]@echo off setlocal enabledelayedexpansion set /p value=Enter value: cls echo %value%|findstr /r "[^0-9]" > nul if errorlevel 1 goto A exit :A REM milliseconds REM no delay=0 set delay=1000 REM set "sep=... " REM set "sep=, " REM No separator: REM set "sep=" set "sep= " set list=%value% set /a v=%value%-1 echo %list% ping localhost -w %delay% -n 2 >nul for /l %%a in (%v%,-1,1) do ( cls set list=!list!%sep%%%a echo !list! ping localhost -w 1000 -n 2 >nul ) pause Sorry, mat123, I think your method is clunky. I don't really like flickery CLS stuff. Doing CLS is restrictive in terms of what you can do on the screen. Quote from: Sidewinder on July 07, 2010, 01:33:26 PM If the request is for horizontal we should oblige the OP: SW your code is 150% better than anyone else in this thread. Of course, you are an hour late and a dollar short. How much are you paid for your efforts?Quote from: marvinengland on July 07, 2010, 05:21:12 PM SW your code is 150% better than anyone else in this thread. Of course, you are an hour late and a dollar short. How much are you paid for your efforts? Why is Billrich/Joanlong/Greg/Papyrus/MarvinEngland/wafflebrain frequently "picking" on SideWinder so often, and always in this sarcastic fashion? Oh wait, I know the answer. Envy. |
|
| 7467. |
Solve : Delete all fies except jpg ones? |
|
Answer» Hello, i need to DELETE all files that aren't .jpg inside a DIR, for /f "delims=" %F in (' dir /b ^| find /v /i ".jpg" ' ) do del "%F" Salmon Trout, Very good. Now do it without the FOR loop Set all files to ARCHIVE. Set all JPG to not archive. Delete archive files. Code: [Select]D:\BAT>attrib *.* +A D:\BAT>attrib *.JPG -A D:\BAT>del *.* /a:A D:\BAT\*.*, Are you sure (Y/N)? y Quote from: Geek-9pm on July 08, 2010, 11:44:15 AM Now do it without the FOR loop Why? 3 lines versus 1, and you have to hit a key (although you could echo Y through a pipe to del) and you have to interfere with all the other files' archive bits. Quote from: Salmon Trout on July 08, 2010, 12:00:20 PM Why? 3 lines versus 1, and you have to hit a key (although you could echo Y through a pipe to del) and you have to interfere with all the other files' archive bits.Thanks. Good answer.Thanks |
|
| 7468. |
Solve : Append file contents in new line? |
|
Answer» HI Experts, My requirement is to APPEND the contents of file2.txt to file1.txt in a new line. I TRIED the below OPTIONS, i) type file2.txt >> file1.txt ii)copy /b file1.txt + file2.txt But the new contents from text2.txt were not appended in a new line. Instead they are continuing in the same line. please check the attachment & revert as soon as you can. Thanks in advance. -Arunach [recovering disk space - old attachment DELETED by admin]It would appear that file 1 does not have a crlf line end, easy to fix, append a crlf then append file 2 Code: [Select]echo.>>file1.txt type file2.txt >> file1.txtHi gpl, You are correct. It fixed my problem. Thanks a lot. Cheers, Arun |
|
| 7469. |
Solve : Script for taking first 3 lines fromm input file? |
|
Answer» I need a script where it contains more than 100 lines. From that file i need first 3 lines and i need to send to another new file.Quote from: Gokul on July 06, 2010, 12:00:18 PM I need a script where it contains more than 100 lines. From that file i need first 3 lines and i need to send to another new file. Output First three lines with Unix Head Command. The Head command can be dowlnloaded to windows. C:\test>type x.bat @echo off rem CNU wrote: rem "I am not familiar with batch commands. I need HELP from you guys to create a batch file. rem I am using some kind of tool that starts Building periodically every 5 mins if there are rem ny new files or binaries placed in that folder. rem Now I need a batch file that recognises latest binaries and triggers the build. rem When the job is done, then it should inform the building tool that the binaries rem have been tested." rem It seems that CNU is suggesting a log of a folder as the folder grows. if EXIST timefile*.txt del timefile*.txt dir > folderlog.txt rem for four times add dir info to log each time interval ( command line arg %1 ) set /a c=0 :timer if %c%==4 goto end set /a c=%c% + 1 time /t > timefile%c%.txt sleep.exe %1 time /t >> timefile%c%.txt dir >> folderlog.txt type folderlog.txt goto timer :end Output First three lines with Unix Head Command. The Head command can be dowlnload to windows. C:\test>head -3 x.bat @echo off rem CNU wrote: rem "I am not familiar with batch commands. I need help from you guys to create a batch file. C:\test>Who is CNU? what's with the nonsensical stuff, marvin? I found this in the snippet closet. It's not bulletproof, but it does have some error trapping. You may want to add a path for the output file (output.txt). This solution does not require a 3rd party program download. Code: [Select]@echo off setlocal enabledelayedexpansion :doOver set /p fName=ENTER Qualified File Name: if not exist %fname% goto doOver :numeric set /p nLines=Enter Number Of Lines To Select: echo %nLines%|findstr /r "[^0-9]" > nul if not errorlevel 1 goto numeric for /f "tokens=* delims=" %%v in (%fName%) do ( echo %%v >> output.txt set /a count+=1 if !count! EQU %nLines% goto :eof ) Good luck. I thought of something along those lines, but I hesitated because it would not handle absolutely any text file; it would not handle correctly BLANK lines or lines containing certain characters, and would bomb if a line contained the & character. I wonder about VBscript? I found the original code does not handle file names with embedded spaces, so it was changed to use the short name. Special characters seem to be seen transparently by the for command and do not seem to be a problem. The was tested with all the characters found above the number keys. Code: [Select]@echo off setlocal enabledelayedexpansion :doOver set /p fName=Enter Qualified File Name: if not exist "%fname%" goto doOver for /f "tokens=* delims=" %%v in ('dir /s /b "%fName%"') do set fName=%%~sv :numeric set /p nLines=Enter Number Of Lines To Select: echo %nLines%|findstr /r "[^0-9]" > nul if not errorlevel 1 goto numeric for /f "tokens=* delims=" %%v in (%fName%) do ( echo %%v >> output.txt set /a count+=1 if !count! EQU %nLines% goto :eof ) Good luck. Input.txt (4 lines) Code: [Select]Oranges & lemons say the bells of St Clements 50% of people eat butter hello! )Goodbye < > !%%&( Asked for first 3 lines... Output.txt Code: [Select]Oranges & lemons say the bells of St Clements 50% of people eat butter hello%%&( Also any line starting with a ; is skipped altogether. Rather than digging deeper, a VBScript solution is looking better and better. Code: [Select]Const ForReading = 1 Const ForWriting = 2 Set fso = CreateObject("Scripting.FileSystemObject") Do WScript.STDOUT.Write "Please enter file name: " strFile = WScript.StdIn.ReadLine If fso.FileExists(strFile) Then Exit Do Loop Do WScript.StdOut.Write "Please enter number of lines: " pLines = WScript.StdIn.ReadLine If IsNumeric(pLines) Then Exit Do Loop Set inFile = fso.OpenTextFile("c:\temp\text.txt", ForReading) Set outFile = fso.OpenTextFile("c:\temp\output.txt", ForWriting, True) Do Until inFile.AtEndOfStream inLine = inFile.ReadLine outfile.WriteLine inLine cLines = cLines + 1 If cLines = CInt(pLines) Then Exit Do Loop inFile.Close outFile.Close Save script with a VBS etension and run from the command prompt as: cscript scriptname.vbs Do not use WScript with this script as stdin and stdout are not supported. Oops! Not fatal but small error in the previous code. Code: [Select]Const ForReading = 1 Const ForWriting = 2 Set fso = CreateObject("Scripting.FileSystemObject") Do WScript.StdOut.Write "Please enter file name: " strFile = WScript.StdIn.ReadLine If fso.FileExists(strFile) Then Exit Do Loop Do WScript.StdOut.Write "Please enter number of lines: " pLines = WScript.StdIn.ReadLine If IsNumeric(pLines) Then Exit Do Loop Set inFile = fso.OpenTextFile(strFile, ForReading) Set outFile = fso.OpenTextFile("c:\temp\output.txt", ForWriting, True) Do Until inFile.AtEndOfStream inLine = inFile.ReadLine outfile.WriteLine inLine cLines = cLines + 1 If cLines = CInt(pLines) Then Exit Do Loop inFile.Close outFile.Close Save script with a VBS etension and run from the command prompt as: cscript scriptname.vbs Do not use WScript with this script as stdin and stdout are not supported. download coreutils if you can. They are TOOLS that can help you with your admin tasks. then just do this Code: [Select]c:\> head -3 file >newfile that's all you need. |
|
| 7470. |
Solve : batch script to cycle thru a list of files to provide data for the target file? |
|
Answer» Hello, |
|
| 7471. |
Solve : Batch Game Save Help? |
|
Answer» I know this is a peculiar question, but here goes.... |
|
| 7472. |
Solve : need CALL command help.? |
|
Answer» HEY, is it possible to call a label from another batch file? because so far i know that it is possible to call directly from another label in the same file.. and also call another file from its beginning.. but can you call a certain label from another batch file? RandomGuyYou can only use a label in the batch file in which it exists. hmm.. wel that sucks. as my secondary option.. i wil giv u my code and see if anyone can help with my situation. before starting my main batch file, (main.bat) it calls another batch file (pconfig.bat) to check for a password. this call function is one of the first functions in main.bat and when pconfig proves a correct password; it proceeds to call main.bat, which again calls for a password, which if correct calls main.bat etc ITS STUCK IN A LOOP! here is my code for each of the files.. PLEASE HELP. here is the portion of code from main.bat Code: [Select]echo off mkdir config title BATCH FILE call config\cconfig.bat if exist config\pconfig.bat ( call pconfig.bat ) else ( goto start OTHER UNIMPORTANT CODE :start and here is the code for pconfig.bat Code: [Select]@echo off cls :A echo enter your password to continue set /p pw= if /i "%pw%"=="password" ( cd ..\ call main.bat ) else ( goto next ) :next cls echo That's the wrong password. pause cls goto :A please help! thankyou. RandomGuy (of the RandomKamak team)When saying that things "suck" it usually a good idea to be 100% sure your code is error-free. 1. Enclose the variables on both side of an IF test in quote marks. If the password is a LITERAL string, (i.e. the password is actually "password") then it should have quote marks around it like this Code: [Select]if /i "%pw%"=="password" ( 2. If password is a variable it should have percent signs before and after like this %password%. Code: [Select]if /i "%pw%"=="%password%" ( but I doubt that you intended that, since you have not used SET to assign a value (unless you did so outside the batch file) Fix that and then perhaps we can see what's happening? yep, all fixed. but it stil makes an unwanted loop.. can u help wit tat one? Where is the loop occurring (in which batch file)?it starts at the if command in main.bat, which wil prove positive and call pconfig.bat. if the if command in pconfig.bat proves positive, it calls main.bat... etc etc etc there is your loopIt appears that you have not fully grasped the meaning of the CALL command. When cmd.exe is running a batch file and it comes to a CALL command, it leaves the first batch file and starts the second one. When (if!) the second one REACHES an exit point, control is passed back to the first batch file, at the line immediately following the CALL command. Your error lies in using, in pconfig.bat, following a correct password entry, the CALL command to get back to main.bat. That doesn't happen. You are starting a new copy of main.bat from the beginning. What you are doing is setting up an infinite series of CALLs. main.bat calls pconfig.bat calls main.bat calls pconfig.bat calls main.bat (etc until you run out of memory and/or patience) What you need to do is merely exit from pconfig.bat if (and only if) the password is successfully entered. Then main.bat picks up again. You don't need to direct the second batch back home, cmd.exe knows where to go because it remembers where it was CALLed from. Also, I eliminated the duplication of cls by moving the first one to after the A: label. Like this Code: [Select]@echo off :A cls echo enter your password to continue set /p pw= if /i "%pw%"=="password" goto OK echo That's the wrong password. pause goto :A :OK cd ..\ Dias de verano, you've been a GREAT help! i mean, kamak and i aren't exactly newbies, but we are still learning. you have made the call command a lot clearer now! =] *yay*Glad to help. PS you don't need the colon before the loop name after a goto command, although it does no harm. I.e. this works Code: [Select]:loop do-stuff goto loop also, personally I find my code is much more readable if, in the editor, I use tabs or spaces to indent code in batch files with labels in them so I can see them more easily (It makes people think you're an old FORTRAN programmer too, which is cool) Code: [Select] @echo off cls echo Pet Chooser :start set /p animal=Choose your pet - cat or dog if /I "%animal%"=="dog" goto kennel if /I "%animal%"=="cat" goto basket echo Only dog or cat allowed goto start :kennel echo GRRRR goto end :basket echo MEOW :end echo Goodbye from %animal%! @kamak team. If you guys are seriously learning how to program, i would suggest you pick a programming language, that shows you programming CONCEPTS like arrays, functions, procedures etc. Ah, Ghostdog. I'm getting used to you jumping into batch programming threads straight after me. I suppose I should be flattered? I have to say, guys, that in my opinion ghostdog74 is quite right. Batch language is OK for noodling around, but it can form lots of bad habits if you intend to learn programming seriously. i'm sure we will go into more advanced programming languages.. but this is our first major project btw. just a nice, simple batch program to publish. check out www.wilding.com.au for version 1.5 gamma of our batch program! |
|
| 7473. |
Solve : how to change the comma to tab space in a text file by using batch command?? |
|
Answer» how to make it? yes you can. i will let somebody else show you. I don't want to waste my time with batch. Then why are you wasting our time by posting in a thread where the question clearly asks "using batch commands?" Quote from: Dias de verano on April 25, 2008, 01:26:01 PM Quote from: ghostdog74 on April 23, 2008, 12:00:21 AMlet me ask you, what do you understand by : "using batch commands" and "using pure batch commands" ? Quote from: ghostdog74 on April 25, 2008, 10:23:13 PMyes you can. i will let somebody else show you. I don't want to waste my time with batch. let me ask you, what do you understand by : "using batch commands" and "using pure batch commands" ? I understand both to mean "by means of batch files". The clue is the word "batch". The word "pure" appears to be your own insertion, the reason for which I can only guess at. Quote from: Dias de verano on April 25, 2008, 11:35:46 PM Quote from: ghostdog74 on April 25, 2008, 10:23:13 PMlet me phrase it another way for youlet me ask you, what do you understand by : "using batch commands" and "using pure batch commands" ? Code: [Select]@echo off cd /path cscript /nologo script.vbs exit if you put the above into batch.bat, is this considered a batch file? Are those 4 lines batch commands? I had taken OP's "make it into .bat" file to mean he wants to do it not the vbscript way, therefore I replied it can be done, which sidewinder has provided the batch version. I really do not have time to do up a batch solution back then. So i don't understand what's the fuss is with you. Yes they are, but you are using a crafty argument, by introducing the concept of "pure" batch commands. If one is allowed to call an external program, then of course one can whip up a piece of code in C, javascript, VBS, Visual Basic, QBasic, FreeBasic, or whatever. Then again, some "batch commands" are built into cmd.exe (or command.com) and some are separate compiled exe programs. Of these, some are installed by default and some are available as toolkits e.g. the various Microsoft Resource Kits, the GNU Core Utilities, and of course many people install such old friends as sed and awk. I think a LOT depends on individual circumstances. While home users using a machine under their control and ownership can do what they please, many people using employer's or school/college computers are prevented from installing add-on programs or collections of programs. People writing scripts for deployment to many PCs may not be sure that all target machines will have the necessary programs installed and in the right places. Many such computers have Windows scripting disabled or filtered as a security MEASURE. For these reasons, it seems to me that very often the most USEFUL and WIDELY applicable solution is going to be one that uses commands and programs which are installed by default -- the lowest common denominator -- even if it involves using those pesky batch commands and techniques instead of the more elegant looking code which alternative methods might exhibit. You might argue (and many do) that using batch code is a bit like trying to eat spaghetti with a chisel, but if you only have a chisel, and you are hungry, there is a certain pleasure in meeting the challenge. I gather from your comment earlier about "wasting your time" that you dislike batch code, and while I fully respect your right to feel that way, there is a certain perverse pleasure and virtuous feeling to be got from only using the basic tools available. It is allied to the pleasure some people get from writing "one-liners". Quote from: Dias de verano on April 26, 2008, 02:14:02 AM You might argue (and many do) that using batch code is a bit like trying to eat spaghetti with a chisel, but if you only have a chisel, and you are hungry, there is a certain pleasure in meeting the challenge. I gather from your comment earlier about "wasting your time" that you dislike batch code, and while I fully respect your right to feel that way, there is a certain perverse pleasure and virtuous feeling to be got from only using the basic tools available. It is allied to the pleasure some people get from writing "one-liners".no, i won't eat spaghetti with a chisel even if i have a chisel. I can use my hands. Its easier. The same goes to choosing a tool to perform tasks for you easily. Not only does "easily" mean easy to use, but it also means easy to read and maintain code, especially if you have a big environment like the schools you mentioned. This is ultimately called , productivity. |
|
| 7474. |
Solve : BAT to EXE Converter Question? |
|
Answer» I have been using free the BAT to EXE Converter provided on this web site, to convert some of my batch files to executables. |
|
| 7475. |
Solve : Writing batch files in batch files help? |
|
Answer» Hi, i've come across a small problem in my coding and was wondering if anyone could help me FIND a way around it. this simple batch makes a variable and then creates another batch and uses that variable. That code creates a file with hello world in it, right? If it does, it wasn't quite what i wanted, but thanks for trying Quote from: kamak on April 22, 2008, 06:21:02 AM That code creates a file with hello world in it, right? not quite, it creates a variable and then echo's a few lines of code to a new batch file and runs it, displaying the varaible. I thought the issue was that your variable wasn't echo-ing into your new batch file correctly. I'm sorry if i got the wrong end of the stick.... Quote from: blastman on April 22, 2008, 06:51:08 AM Quote from: kamak on April 22, 2008, 06:21:02 AMThat code creates a file with hello world in it, right? My problem was that it wouldn't print %pw% in the new file (kamak and i are actually working together btw) we want to print the actual % variable signs in the pconfig.bat fileQuote from: RandomGuy on April 22, 2008, 07:10:53 AM (kamak and i are actually working together btw) we want to print the actual % variable signs in the pconfig.bat file arh, I didn't get that from the other posts. sorry for the confusion.In a batch, to echo one percent sign, use two percent signs Code: [Select]@echo off echo @echo off>test.bat echo set variable=cats and dogs>> test.bat echo echo variable=%%variable%%>>test.bat echo this is test.bat type test.bat call test.bat result Code: [Select]this is test.bat @echo off set variable=cats and dogs echo variable=%variable% variable=cats and dogs THANKYOU Dias de verano! it helped us heaps! |
|
| 7476. |
Solve : Help Command Utility? |
|
Answer» Help Command Utility v5 that we see from command interpreter (while typing help|more in winxp ): is it possible to convert it into DOC or TXT format. It would be easy to read all the txt in one large DOC file. If so can someone suggest some application that can do that: Many thanks:)help>help.txt Thank you very much Salmon: gave the cmd and changed .txt to .doc . What a time saver. I don't want to push my luck here: i noticed DOS 6.22 doesn't h' help.exe, I m running it on Virtual box, is it even remotely possible to get the doc file f DOS 6.22.( please dont think stupid guy.) Cause the above method doesn't work on DOS 6.22: My eyes really hurts staring on the screen for hrs, i just want a direct printout, i could get through Google but i want selective printouts. DOS on V. B. isn't recognizing the DOS PRINTER DRIVER. Any suggestion would be great:Can I ask you why you write h' instead of have? (I am curious) (It is not English) Just a question Real MS-DOS including 6.22 used a special help file format, .hlp, and help.com is the help reader application. Both are in C:\DOS by default. Detailed help: (help.hlp converted to html and hosted on a web site): http://www.vfrazee.com/ms-dos/6.22/help/ PDF reference: http://www.gregvogl.net/courses/os/handouts/doscmdref.pdf Fasthelp (similar to Win32 /Win64 help command list) : (You can copy and paste into Notepad, MS Word etc) Code: [Select]<ANSI.SYS> Defines functions that change display graphics, control cursor movement, and reassign keys. <APPEND.EXE> Allows programs to open data files in specified DIRECTORIES as if they were in the current directory. <ATTRIB.EXE> Displays or changes file attributes. <Batch> Commands specially designed for batch programs. <BREAK> Sets or clears extended CTRL+C CHECKING. <BUFFERS> Allocates memory for a specified number of disk buffers when your system starts. <CALL> Calls one batch program from another without causing the first batch program to stop. <CD> Displays the name of or changes the current directory. <CHCP> Displays or sets the active code page number. <CHDIR> Displays the name of or changes the current directory. <CHKDSK.EXE> Checks a disk and displays a status report. <CHKSTATE.SYS> Used by the MemMaker memory-optimization program to track the optimization process. <CHOICE.COM> Prompts the user to make a choice in a batch program. <CLS> Clears the screen. <COMMAND.COM> Starts a new instance of the MS-DOS command interpreter <CONFIG.SYS> Commands that can only be used in the CONFIG.SYS file. <COPY> Copies one or more files to another location. <COUNTRY.SYS> Configures MS-DOS to recognize one of the supported languages. <CTTY> Changes the terminal device used to control your system <DATE> Displays or sets the date. <DBLSPACE.EXE> Creates and manages drives compressed by using DoubleSpace. <DEBUG.EXE> Starts Debug, a program testing and editing tool. <DEFRAG.EXE> Reorganizes the files on a disk to optimize the disk. <DEL> Deletes one or more files. DELOLDOS.EXE Deletes the OLD_DOS.1 directory, the files it contains and then itself. <DELTREE.EXE> Deletes a directory and all the files and subdirectories in it. <DEVICE Drivers> Installable device drivers provided with MS-DOS. <DEVICE> Loads the device driver specified into memory. <DEVICEHIGH> Loads the device driver specified into upper memory. <DIR> Displays a list of files and subdirectories in a directory. <DISKCOMP.COM> Compares the contents of two floppy disks. <DISKCOPY.COM> Copies the contents of one floppy disk to another. <DISPLAY.SYS> Enables display of international character sets on EGA, VGA, and LCD monitors. <DOS> Specifies that MS-DOS should maintain a link to the upper memory area, load part of itself into the high memory area (HMA), or both. <DOSKEY.COM> Edits command lines, recalls MS-DOS commands, and creates macros. <DOSSHELL.COM> Starts the MS-DOS Shell. <DRIVER.SYS> Creates a logical drive that you can use to refer to a physical floppy disk drive. <DRIVPARM> Defines parameters for devices such as disk and tape drives when you start MS-DOS. <DRVSPACE.EXE> Creates and manages compressed drives by using DriveSpace. <DrvSpace Tips> Getting the most out of DRVSPACE. <DRVSPACE.SYS> Compresses hard disk drives or floppy disks, and configures drives that were compressed by using DriveSpace. <ECHO> Displays messages, or turns command echoing on or off. <EDIT.COM> Starts MS-DOS Editor, which creates and changes ASCII files. <EGA.SYS> Saves and restores the display when the MS-DOS Shell Task Swapper is used with EGA monitors. <EMM386> Enables/disables EMM386 expanded memory support. <EMM386.EXE> Enables or disables EMM386 expanded-memory support on a computer with an 80386 or higher processor. <ERASE> Deletes one or more files. <EXIT> QUITS the COMMAND.COM program (command interpreter). <EXPAND.EXE> Decompresses one or more compressed files. <FASTHELP.EXE> Provides summary Help information for MS-DOS commands. <FASTOPEN.EXE> Decreases the amount of time needed to open frequently used files and directories. <FC.EXE> Compares two files or sets of files, and displays the differences between them. <FCBS> Specifies the number of file control blocks (FCBs) that MS-DOS can have open at the same time. <FDISK.EXE> Configures a hard disk for use with MS-DOS. <FILES> Specifies the number of files that MS-DOS can access at one time. <FIND.EXE> Searches for a text string in a file or files. <FOR> Runs a specified command for each file in a set of files. <FORMAT.COM> Formats a disk for use with MS-DOS. <GOTO> Directs MS-DOS to a line in a batch program that is marked by a label you specify. <GRAPHICS.COM> Loads a program that can print graphics. <HELP.COM> Provides complete, interactive Help information for MS-DOS commands. <HIMEM.SYS> Extended-memory manager. <IF> Performs conditional processing in batch programs. <INCLUDE> Includes the contents of one configuration block within another. <INSTALL> Loads a memory-resident program into memory when you start MS-DOS. <INTERLNK> Connects two computers via parallel or serial ports. <INTERLNK.EXE> Redirects requests on the Interlnk server. <International> Commands used to change country-specific settings and character sets (code pages). <INTERSVR.EXE> Starts the Interlnk server. <KEYB.COM> Configures a keyboard for a specific language. <LABEL.EXE> Creates, changes, or deletes the volume label of a disk <LASTDRIVE> Specifies the maximum number of drives you can access. <LH> Loads a program into the upper memory area. <LOADFIX.COM> Loads a program above the first 64K of memory, and runs the program. <LOADHIGH> Loads a program into the upper memory area. <MD> Creates a directory. <MEM.EXE> Displays the amount of used and free memory in your system. <MEMMAKER.EXE> Starts the Memmaker program, which optimizes your computer's memory. <MENUCOLOR> Sets the text and background colors for the startup menu. <MENUDEFAULT> Specifies the default menu item on the startup menu and sets a timeout value if desired. <MENUITEM> Defines an item on the startup menu. <MKDIR> Creates a directory. <MODE.COM> List of tasks for which you can use the MODE command. <MORE.COM> Displays output one screen at a time. <MOVE.EXE> Moves one or more files. Also renames files and directories. <MSAV.EXE> Scans your computer for known viruses. <MSBACKUP.EXE> Backs up or restores one or more files from one disk to another. <MSCDEX.EXE> Provides access to CD-ROM drives. <MSD.EXE> Provides detailed technical information about your computer. <Multi-Config> Commands for Defining Multiple Configurations. <NLSFUNC.EXE> Loads country-specific information. <NUMLOCK> Specifies whether the NUM LOCK key is set to ON or OFF when your computer starts. <PATH> Displays or sets a search path for executable files. <PAUSE> Suspends processing of a batch file and displays a message. <POWER.EXE> Turns power management on and off. <POWER.EXE> Reduces power consumption when applications and devices are idle. <PRINT.EXE> Prints a text file while you are using other MS-DOS commands. <PROMPT> Changes the MS-DOS command prompt. <QBASIC.EXE> Starts the MS-DOS QBasic programming environment. <RAMDRIVE.SYS> Uses part of your computer's random-access memory (RAM) to simulate a hard disk drive. <RD> Removes a directory. <REM> Enables you to include comments in a batch file or in your CONFIG.SYS file. <REN> Renames a file or files. <RENAME> Renames a file or files. <REPLACE.EXE> Replaces files. <RESTORE.EXE> Restores files that were backed up by using the BACKUP command. <RMDIR> Removes a directory. <SCANDISK.EXE> Checks a drive for errors and repairs any problems it finds. <SET> Displays, sets, or removes MS-DOS environment variables <SETVER.EXE> Displays the version table. <SETVER.EXE> Display and modify the version number that MS-DOS reports to a program. <SHARE.EXE> Installs file-sharing and locking capabilities on your hard disk. <SHELL> Specifies the name and location of the command interpreter you want MS-DOS to use. <SHIFT> Changes the position of replaceable parameters in a batch program. <SIZER.EXE> Used by MemMaker to determine the size in memory of device drivers and memory-resident programs. <SMARTDRV.EXE> Starts or configures SMARTDrive, which creates a disk cache in extended memory. <SMARTDRV.EXE> Loads the SMARTDRV.EXE device driver to perform double buffering. <SORT.EXE> Sorts input. <STACKS> Supports the dynamic use of data stacks to handle hardware interrupts. <SUBMENU> Defines an item on a startup menu that, when selected, displays another set of choices. <SUBST.EXE> Associates a path with a drive letter. <SWITCHES> Specifies special options in MS-DOS. <SYS.COM> Copies MS-DOS system files and command interpreter to a disk you specify. <TIME> Displays or sets the system time. <TREE.EXE> Graphically displays the directory structure of a drive or path. <TYPE> Displays the contents of a text file. <UNDELETE.EXE> Restores files previously deleted with the DEL command. <UNFORMAT.COM> Restores a disk erased by the FORMAT command. <VER> Displays the MS-DOS version. <VERIFY> Directs MS-DOS to verify that your files are written correctly to a disk. <VOL> Displays a disk volume label and serial number. <VSAFE.COM> Continuously monitors your computer for viruses. <XCOPY.EXE> Copies files (except hidden and system files) and directory trees. Its an old HABIT, we used to txt message friends with this small understandable letters or numbers, just to get the message across. Like [ have is h', am is m, great is g8, for u is 4 u etc etc.....i think its used everywhere ] , and usually forget where i am writing : its no near to slang. Thank you for the links, its always good to have materials when we are offline. 5 pages in total, getting the printouts ready. Its not much much when you have a dotmatrix printer. CHEERS |
|
| 7477. |
Solve : Automate Telnet? |
|
Answer» Hi, |
|
| 7478. |
Solve : Find and delete file size? |
|
Answer» Hi all, Hi thanks for that, but then how do i delete those files?what requirements have you not stated yet? Code: [Select]Set objFS = CreateObject("Scripting.FileSystemObject") strFolder = "C:\test" Set objFolder = objFS.GetFolder(strFolder) For Each Files In objFolder.Files If objFS.GetExtensionName(Files) = "doc" Then If Files.Size > 10000 Then WScript.Echo "File " & Files.Name & " found." objFS.DeleteFile(Files) End If End If Next Quote from: ghostdog74 on April 26, 2008, 10:52:41 AM what requirements have you not stated yet? Original post Quote it looks into folder and delete .png files IF the size is below 10kb. [rolls eyes] @dias, yes i saw that in the original post thank you. I am asking OP what other requirements he has not stated yet, besides deletion of files.Hi, Thanks spot-on guys, thanks you your help. Cheers IanJust a point, 10 KB (file size) is conventionally 10 x 1024 bytes = 10240 bytes. it would depend on how OP wants it. A file with size 10239 bytes for example will not be deleted. |
|
| 7479. |
Solve : How to combine forfiles and for loop script to run the file? |
|
Answer» Quote from: _unknown_ on November 03, 2014, 09:00:36 PM There is a "system cannot find the path specified above". Here is how I set my path. You have changed this in more ways than only changing the paths and I have no confidence that you have not also introduced other changes... The error message you mentioned is only cosmetic and you can stop it appearing by changing this in two places: rd "%temp_path%" to rd "%temp_path%" 2>nul I predict 5 pages TOTAL for this THREAD....Quote from: Squashman on November 05, 2014, 06:40:24 AM Lets see the entire batch file that you are using. Please keep it as is. Do not obfuscate anything. The following are the entire batch file I am using from the input folder: A2001274033500.L1_LAC.A.hdf A2001274033500.L2_LAC.A.hdf A2001274051000.L1_LAC.A.hdf A2001274051000.L2_LAC.A.hdf A2001274051500.L1_LAC.A.hdf A2001274051500.L2_LAC.A.hdf A2001274065000.L1_LAC.A.hdf A2001274065000.L2_LAC.A.hdf A2001275041500.L1_LAC.A.hdf A2001275041500.L2_LAC.A.hdf A2001275042000.L1_LAC.A.hdf A2001275042000.L2_LAC.A.hdf A2001275055000.L1_LAC.A.hdf A2001275055000.L2_LAC.A.hdf A2001275055500.L1_LAC.A.hdf A2001275055500.L2_LAC.A.hdf A2001275060000.L1_LAC.A.hdf A2001275060000.L2_LAC.A.hdf While the bat file is running here are the files I've pasted/added to the input folder from the desktop folder. A2001038044500.L2_LAC.A.hdf A2001038045000.L2_LAC.A.hdf A2001038063000.L2_LAC.A.hdf A2001038062500.L2_LAC.A.hdfI asked for the BATCH file code you are using!! Not what input files you are using!!!Quote from: Squashman on November 05, 2014, 09:37:43 PM I asked for the BATCH file code you are using!! Not what input files you are using!!! Sorry @echo off set in_path=E:\input\ set out_path=E:\output\ set temp_path=%out_path%\temp\ set processed_files_path=E:\processed files\ md "%processed_files_path%" 2>nul cd /d "%in_path%" :loop set now=%date% %time% if exist "*.L2_LAC.*.hdf" ( rd "%temp_path%" 2>nul if exist "%temp_path%\" echo An ERROR occurred as the "%temp_path%\" folder exists - may have UNPROCESSED files within: & pause & goto :EOF md "%temp_path%" 2>nul echo moving files @ %now% move "*.L2_LAC.*.hdf" "%temp_path%" >nul cd /d "%temp_path%" echo projecting files FORFILES /m *L2_LAC*.hdf /C "cmd /c gdalwarp -geoloc -t_srs EPSG:4326 -te 113.205 1.120 157.105 2.005 HDF4_SDS:UNKNOWN:@file:37 %out_path%\@fname.tif" move "*.L2_LAC.*.hdf" "%processed_files_path%" >nul cd .. rd "%temp_path%" 2>nul if exist "%temp_path%\" echo An ERROR occurred as the "%temp_path%\" folder exists - may have unprocessed files within: & pause & goto ) timeout /t 30 /nobreak goto :loopWould it kill you to use bulletin board CODE tags like everyone else has been using. You have two lines of code that are wrapping. If they are like that in your batch file they would cause some syntax errors.Quote from: _unknown_ on November 03, 2014, 09:00:36 PM There is a "system cannot find the path specified above". Quote from: foxidrive on November 05, 2014, 08:52:47 AM The error message you mentioned is only cosmetic Now that I look again - the error you quoted (without the word "above" in Win 8.1) is caused by a different problem, but it would have to be such an elementary error that I can't BELIEVE you keep getting it... The input folder doesn't exist, and so there can't be any source files in there. This assumes that the batch file you pasted above is correct... Quote from: Squashman on November 06, 2014, 06:39:06 AM Would it kill you to use bulletin board CODE tags like everyone else has been using. Code: [Select]@echo off set "in_path=E:\input\" set "out_path=E:\output" set "temp_path=%out_path%\temp\" set "processed_files_path=E:\processed files\" md "%processed_files_path%" 2>nul cd /d "%in_path%" :loop set now=%date% %time% if exist "*.L2_LAC.*.hdf" ( rd "%temp_path%" 2>nul if exist "%temp_path%\" echo An ERROR occurred as the "%temp_path%\" folder exists - may have unprocessed files within: & pause & goto :EOF md "%temp_path%" 2>nul echo moving files @ %now% move "*.L2_LAC.*.hdf" "%temp_path%" >nul cd /d "%temp_path%" echo projecting files FORFILES /m *L2_LAC*.hdf /C "cmd /c gdalwarp -geoloc -t_srs EPSG:4326 -te 109.975 3.475 135.025 25.025 HDF4_SDS:UNKNOWN:@file:37 %out_path%\@fname.tif" move "*.L2_LAC.*.hdf" "%processed_files_path%" >nul cd .. rd "%temp_path%" 2>nul if exist "%temp_path%\" echo An ERROR occurred as the "%temp_path%\" folder exists - may have unprocessed files within: & pause & goto ) timeout /t 30 /nobreak goto :loop Quote from: foxidrive on November 05, 2014, 08:52:47 AM You have changed this in more ways than only changing the paths and I have no confidence that you have not also introduced other changes... This solved the error "can't find the path specified above". But after all the files from the input folder was projected successfully and those files were moved to the processed files folder then I've pasted 4 new files in the input folder I don't know why it isn't even working. It just keeps on waiting for 30 seconds But in your case it's working Because in the middle of the script you do a change directory to the temp path but never do a change directory back to the input path because it is outside the loop label.Quote from: foxidrive on October 30, 2014, 05:07:53 AM Code: [Select] cd .. Figured it out already. The cd .. part is causing the problem. Just modified it by changing the directory pointing to the input_path. Thank you squashman and to you foxidrive who do all the efforts in creating this script and for your patience. Quote from: Squashman on November 06, 2014, 08:06:17 PM Because in the middle of the script you do a change directory to the temp path but never do a change directory back to the input path because it is outside the loop label. Well spotted Squashman. My test created extra files after the timeout command but it created them in the current directory, and of course it worked fine. Anyway, it's solved after a lengthy battle, NICE work. Quote from: _unknown_ on November 06, 2014, 09:01:21 PM Figured it out already. The cd .. part is causing the problem. Just modified it by changing the directory pointing to the input_path. |
|
| 7480. |
Solve : Echo. >>smallfiles.txt file names less than 200k in size???? |
|
Answer» Was wondering if anyone had any suggestions on a way to search through a directory for files less than 200k in SIZE and write them as a ASCII text file. I was curious as to if batch could be used Code: [Select]@echo off for /f "delims=" %%A in ('dir /b /a-d') do ( if %%~zA lss 204800 echo file %%A is less than 200 kB ) Thank You Salmon Trout for showing a way to do this in batch!!!!! |
|
| 7481. |
Solve : Delete all files apart from all video types and images? |
|
Answer» i ment to say there on on C:\ the external HDD is H and no foldes just the files These two commands will USE drive h: and the file.txt will be saved on your desktop. Ive ran the Delete side of the script and it saying files not found :/You know it is possible to copy and paste text from the CMD window.Squashman yeahh i know that, Since you are not running both commands from the H:\ drive on the command PROMPT then you need to hard code both commands to use the H: drive. Code: [Select]for /f "usebackq delims=" %a in ("%userprofile%\desktop\file.txt") do del "H:\%a"how would i do that ive tried to use the dir H:\ bfor the code Quote from: blackrainbow on November 24, 2014, 10:55:44 AM how would i do that ive tried to use the dir H:\ bfor the codeWell you don't need to if you use the small code variation I made to Foxidrive's code. Code: [Select]C:\Users\Squashman>H: H:\>I'm sorry, I initially used a recursive search and removed the /s while editing it because you hadn't mentioned if there were subdirectories, but Squashman's modification will work if all the files are in H:\ and the following modification should work too if there are no subdirectories - I put the /s back in. Code: [Select]dir h:\*.* /s /b /a-d |findstr /v /i /L ".mpg .mkv .mpg .mpeg .jpg .png .bmp .gif" >"%userprofile%\desktop\file.txt" Code: [Select]for /f "usebackq delims=" %a in ("%userprofile%\desktop\file.txt") do del "%a" ive done it following squashmans adcive thanks guys :D |
|
| 7482. |
Solve : ask for help to crate batch script to judge which program occupy specified port? |
|
Answer» Hi friends, |
|
| 7483. |
Solve : Simple batch file...but an issue....? |
|
Answer» Here is the batch file... |
|
| 7484. |
Solve : Batch script to remove columns from txt file? |
|
Answer» I have a text file that has columns delimited USING a pipe character ("|"). The csv has hundreds of columns, and I want to remove column 16&17 and rest of the columns to be intact. How do i create a batch script that will create a new output.txt file. May I ask why? Why do you need to do that? Why use a script in Batch? Programs the use CSV have ways to read and modify the files. Microsoft says one can use Excel to do it. But f batch is better, they would have RECOMMENDED it. Reference: Microsoft Excel Tutorial: How to work with CSV files Quote from: carmine on November 26, 2014, 08:59:44 PM I have a text file that has columns delimited using a pipe character ("|"). The csv has hundreds of columns, and I want to remove column 16&17 and rest of the columns to be intact. How do i create a batch script that will create a new output.txt file. It does DEPENDS on the text makeup of the file, unicode, foreign text, the maximum length of a line, the total size of the file. If the file is ASCII, then you can do this very quickly with JREPL.BAT Assuming none of the columns contain the quoted pipe characters as part of the value, then: Code: [Select]jrepl "^((?:.*?\|){15}).*?\|.*?\|" "$1" /f "yourFile.csv" /o - The above will overwrite the original file. If you want to preserve the original and write a new file, then use /o "newFile.csv" instead of /o - It can also be made to work if column values can contain quoted pipe literals. It even supports quotes within the quoted value (escaped as ""): Code: [Select]jrepl "^((?:\q(?:\q\q|[^\q])*\q\||.*?\|){15})(?:\q(?:\q\q|[^\q])*\q\||.*?\|){2}" "$1" /X /f "yourFile.csv" /o - DAVE BenhamHi, Many thanks to Dave Benham for helping. Thanks. |
|
| 7485. |
Solve : Need help with script? |
|
Answer» Quote from: edwis1345 on November 29, 2014, 04:45:25 AM I want to figure out how to do this You misunderstood my question. What business or other task do you have that needs this? Anyone can help me with this? I need to run proccesses listed in .txt file if they are killed. @echo off @echo off &setlocal enabledelayedexpansion tasklist /FO list|find /i ".exe">%temp%\running.tmp for /f "tokens=2*" %%a in (%temp%\running.tmp) do ( call :process %%B ) pause exit /b :process for /f "tokens=*" %%c in (sarasas.txt) do if "%*"=="%%c" ( set Answ=N echo Isjungti procesa? set /p Answ=Isjungti? %*? IF /I NOT "!Answ!"=="Y" GOTO :EOF if errorlevel 1 goto :EOF echo Killing %%c taskkill /f /im "%%c" ) Quote from: edwis1345 on November 29, 2014, 07:25:23 AM Anyone can help me with this? People that help in forums like this generally do so because they like coding, and understanding why a task is being performed gives them some satisfaction - and if you answer their questions then they will probably bend over backwards to help you. A second benefit of DISCUSSING the tasks properly is that these helpers will often use their experience and KNOWLEDGE to give you a robust script that also works in situations that you hadn't YET considered. |
|
| 7486. |
Solve : number of times started? |
|
Answer» Quote from: Jaka on November 05, 2014, 02:30:51 AM Program will close itself when it finishes backup - file1.exe The batch file is not going to keep running in a loop if a reboot happens. Quote This script is not started that often, so program have no time to close, but it is started with TASK schedule every hour. You said EARLIER that you tested it with notepad. There will be multiple copies of notepad open, and this is the expected behaviour, do you know why? Quote from: foxidrive on November 05, 2014, 09:10:48 AM The batch file is not going to keep running in a loop if a reboot happens.I think this is why he said we need to keep track of the number of times it has ran in a log file.Quote from: Squashman on November 05, 2014, 09:12:44 AM I think this is why he said we need to keep track of the number of times it has ran in a log file.yes, that is it. every time I start batch it will write log in txt file for example for notepad and also everytime after that is stared calc.exe it will write log in second txt file so script knows what to do nex time I start it.Quote from: Squashman on November 05, 2014, 09:12:44 AM I think this is why he said we need to keep track of the number of times it has ran in a log file. I read the first two explanations and then my eyes glazed over. See if this is what you are looking for. I must have missed when you said that you were rebooting between each execution. Code: [Select] @echo off setlocal EnableDelayedExpansion if exist log1.log set /p t1=<log1.log if not defined t1 set t1=1 if %t1% LEQ 5 ( file1.exe set /a t1+=1 echo !t1! >log1.log ) else ( if exist log1.log set /p t2=<log2.log if not defined t2 set t2=1 if !t2! LEQ 3 ( file2.exe set /a t2+=1 echo !t2! >log2.log )) EDIT: Missed a close parenthesis at the end, was fixed.Quote from: foxidrive on November 05, 2014, 09:45:42 AM I read the first two explanations and then my eyes glazed over.I am sorry if this is to complicated and to hard to do.Might want to fix that. Code: [Select]if exist log1.log set /p t2=<log2.logQuote from: Jaka on November 05, 2014, 11:00:50 AM I am sorry if this is to complicated and to hard to do.The only hard part is getting the user to explain what EXACTLY they want to do and the information we need to code it.Quote from: Lemonilla on November 05, 2014, 11:00:25 AM See if this is what you are looking for. I must have missed when you said that you were rebooting between each execution. YAY this almost work. I tested again with notepad and calc. And it opens 5 times notepad and than opens 3 times calc. This is almost it But it should open 5 times notepad and than 1 time calc and than goes again to notepad 5 times and than again 1 calc and than goes again 5 times to notepad and again 1 time calc and stop.Quote from: Squashman on November 05, 2014, 11:23:54 AM The only hard part is getting the user to explain what exactly they want to do and the information we need to code it.yes I know, but I am trying to explain really hard how this should work. I know one single thing and script doesn't work right.Try harder...either on your work...or the explanation of what you want to do...So let us get this straight. Your scheduled task will fire. The batch file will run file1.exe and write 1 to log1.txt Your scheduled task will fire. The batch file will run file1.exe and write 2 to log1.txt Your scheduled task will fire. The batch file will run file1.exe and write 3 to log1.txt Your scheduled task will fire. The batch file will run file1.exe and write 4 to log1.txt Your scheduled task will fire. The batch file will run file1.exe and write 5 to log1.txt Your scheduled task will fire. The batch file will run file2.exe and write 1 to log2.txt Your scheduled task will fire. The batch file will run file1.exe and write 1 to log1.txt Your scheduled task will fire. The batch file will run file1.exe and write 2 to log1.txt Your scheduled task will fire. The batch file will run file1.exe and write 3 to log1.txt Your scheduled task will fire. The batch file will run file1.exe and write 4 to log1.txt Your scheduled task will fire. The batch file will run file1.exe and write 5 to log1.txt Your scheduled task will fire. The batch file will run file2.exe and write 2 to log2.txt Your scheduled task will fire. The batch file will run file1.exe and write 1 to log1.txt Your scheduled task will fire. The batch file will run file1.exe and write 2 to log1.txt Your scheduled task will fire. The batch file will run file1.exe and write 3 to log1.txt Your scheduled task will fire. The batch file will run file1.exe and write 4 to log1.txt Your scheduled task will fire. The batch file will run file1.exe and write 5 to log1.txt Your scheduled task will fire. The batch file will run file2.exe and write 3 to log2.txt Lather, rinse, repeat.......... Quote from: Squashman on November 05, 2014, 02:15:41 PM So let us get this straight. yes exactly that and when I delete log1.txt or log2.txt or both than it will start all over again from start Now I see how I should explain what script sould do. Sorry for my bad explanation. This your is really great, now I will know for next time. Today I learned something more. Hmmm, Not sure about your logic with deleting one file or both. What happens when you delete log1.txt and log2.txt has a value of 3. The way I would understand your logic is that file1.exe would run 5 times and file2.exe will never run. Is that correct?No logic...and i just THOUGHT about the overall goal of this project...i came up with HuH ? ? |
|
| 7487. |
Solve : need a batch file to move files depending on a condition? |
|
Answer» i have a list of filenames with me. now i want to move that list of files to another folder using a batch script.. but i need to check a condition on file name.. this script i want to run on 300 gb data and i want to check the file names starting I'm going to do my best to answer the question that I think you are asking here. First, there is a database that you have that has certain IDs in it. Second, you want to move only the files that match an ID in that database. And third (and irrelevant in this situation), you are running this program on 300 GB of data. Given that all of the above is true, here is how I WOULD solve the problem: First, OUTPUT the IDs from the database to a plain text file. <> ID1 ID2 ID3 etc... Then use this: Code: [Select]@echo off setlocal enabledelayedexpansion set old=c:\oldfilepath set new=c:\newfilepath for /f "delims=" %%G in (output.txt) do ( for /f "delims=" %%H in ('dir %old% "%%G" /s /b') do copy %old%\%%H %new%\%%H ) It's late here so please identify any errors you run into as I have not taken the time to test this.use the below move \*.* ex: move C:\test\*.* C:\test\bak The problem with move is that it automatically deletes the file from the original location. Copy is safer because if the copy doesn't complete correctly, the file still exists. Once the OP is satisfied that all files are in the new location, all they would need to do is change the code from Code: [Select]for /f "delims=" %%H in ('dir %old% "%%G" /s /b') do copy %old%\%%H %new%\%%Hto Code: [Select]for /f "delims=" %%H in ('dir %old% "%%G" /s /b') do del %old%\%%Hand run it again. |
|
| 7488. |
Solve : Win/Batch: How to display the "seconds" field in last modified date of a file?? |
|
Answer» Hi, I got the error message" 'FORFILES' is not recognized as an internal or external command, it isn't included in XP. Only Vista or later. However it is part of the Windows 2000 Resource Kit. Get it here http://www.dynawell.com/download/reskit/microsoft/win2000/forfiles.zip Unzip it and copy forfiles.exe to: %systemroot%\system32\forfiles.exe and it should work. Where %systemroot% is a system variable normally pointing to "c:\windows". Thanks for your INPUT, but my clients does not allow to install extra programs on their machines. Let's go back to the approach of vbscript. Could anybody teach me how to integrate the vbscript that mentioned by "ghostdog74" into a DOS/Batch file? Code: [Select]Set objFS = CreateObject( "Scripting.FileSystemObject" ) strFile=WScript.Arguments(0) Set objFile = objFS.GetFile(strFile) theDate = objFile.DateLastModified WScript.Echo Second(theDate) Or is there any other alternative to use native Dos command to get the "seconds" field of a file's "last modified date"? Thanks, Thomas Quote from: lwkt on December 29, 2010, 07:54:24 PM Could anybody teach me how to integrate the vbscript that mentioned by Save it somewhere as a .vbs file and call it from the batch file by [path\]name, with the //nologo switch, using the cscript.exe script engine, passing the filename as a parameter (quoted if it contains spaces) Code: [Select]cscript //nologo scriptname.vbs "filename" Note that the file modification time in NTFS or FAT32 is only accurate to 2 seconds anyhow. Are you sure this is the best method? Can't you just examine the last line of the log file and see if it has changed? An accuracy of 2 seconds is not enough as my purpose is to keep track of any update of the log file down to every second. Tracking of the changes on last line of the log file is a good suggestion. Would you mind teach me how to implement in a DOS/batch approach? Thanks, Thomas |
|
| 7489. |
Solve : Request:Bat file (code)for combining tiffs? |
|
Answer» I have |
|
| 7490. |
Solve : Batch program: Compare substring of argument with another string? |
|
Answer» In my batch program I WOULD like to compare two strings. |
|
| 7491. |
Solve : Sound in MS-DOS? |
|
Answer» I wondered if there is some thirdy party tool that can play a sound file. I know there is mplay32 but when it plays a sound it opens a window and I want something that plays in the same command promt as the other commands. I hope I make my point clear. As many will think at first, I have tried some but none of them worked. Also the thing I wanna make is a launcher that's why I need the program to show no window.Had a look at Playwav.exe? As the name suggests it only plays .Wav files but might suit your purpose. See here.Thanks that will do nicely. Now if you happen to know any like that for MP3 files or any that does not wait to keep RUNNING the rest of the commands that would be perfect.I think there is a mp3 player for linux that runs from terminal shell, but that wont help you with M$ OS. The biggest issue is that MP3 is newer than legacy DOS, and all players use a codec written around a GUI. Many software apps still use *.wav for their audio as WELL, since I know there are wave players for DOS, and I have written C++ before many years ago in college, that played out Wave files for games etc. Is there a reason to why you dont want to convert your MP3 to a WAV file?Quote from: DaveLembke on December 29, 2010, 02:40:58 PM I think there is a mp3 player for linux that runs from terminal shell, but that wont help you with M$ OS. The biggest issue is that MP3 is newer than legacy DOS, and all players use a codec written around a GUI. Not all. It's about time somebody mentioned mplayer. Honestly! I despair sometimes. Anyway NT command is not "legacy DOS", and the OP made it clear he means Win32. Code: [Select]C:\MPlayer-rtm-svn-32735>mplayer "04 Don't Go.mp3" MPlayer Sherpya-SVN-r32735-4.2.5 (C) 2000-2010 MPlayer Team 161 audio & 356 video codecs Playing 04 Don't Go.mp3. Audio only file format detected. ========================================================================== Opening audio decoder: [mp3lib] MPEG layer-2, layer-3 AUDIO: 44100 Hz, 2 ch, s16le, 128.0 kbit/9.07% (ratio: 16000->176400) Selected audio codec: [mp3] afm: mp3lib (mp3lib MPEG layer-2, layer-3) ========================================================================== AO: [dsound] 44100Hz 2ch s16le (2 bytes per sample) Video: no video Starting playback... You can pipe the console output to nul if you don't want anything on the screen. There's probably a "quiet" switch (i.e. no screen output) in any case. Hours of fun. And open source too. Code: [Select]C:\MPlayer-rtm-svn-32735>mplayer "04 Don't Go.mp3">nul >nul Cool!!! I was thinking that any Win32 player would pop up a window. That >NUL I guess is the fix to that issue, and I wasnt aware of that ability.Quote from: DaveLembke on December 29, 2010, 04:21:10 PM >nul Cool!!! I was thinking that any Win32 player would pop up a window. That >NUL I guess is the fix to that issue, and I wasnt aware of that ability. No. the >NUL redirects the console output it would otherwise show.Quote from: DaveLembke on December 29, 2010, 04:21:10 PM >nul Cool!!! I was thinking that any Win32 player would pop up a window. That >NUL I guess is the fix to that issue, and I wasnt aware of that ability. Either I did not write my post clearly enough, or you did not read it PROPERLY. Whatever. I know you thought that "any Win32 player" must have a GUI. You were wrong. You wrote this... Quote from: DaveLembke on December 29, 2010, 09:40:58 PM I think there is a mp3 player for linux that runs from terminal shell, but that wont help you with M$ OS. The biggest issue is that MP3 is newer than legacy DOS, and all players use a codec written around a GUI. ...and I wrote this... Not all. It's about time somebody mentioned mplayer. mplayer (Linux and Windows versions available) does not have a GUI. It is a purely console APPLICATION unless you ask it to play a video file, in which case it pops up a very basic window for the duration of the video. All control is by the keyboard. If you ask it to play an audio file any screen output is to the same console window that called mplayer, and, like any other console app, you can redirect the output. However, before using mplayer as a means of playing audio files unattended, it may be as well to study the documentation to find out about the various (huge number!) of command line switches and options. Well the reason I want to use .mp3 is just for saving space as they are significantly smaller in size. As for mplayer I see that I must compile the source code and I really suck at that kind of stuff. I also saw that there is a list of builds for windows but I don't know which one should I pick.Quote from: Irineos on December 30, 2010, 09:44:14 AM Well the reason I want to use .mp3 is just for saving space as they are significantly smaller in size. As for mplayer I see that I must compile the source code and I really suck at that kind of stuff. I also saw that there is a list of builds for windows but I don't know which one should I pick. You don't have to compile the source code. I know the website says it is "recommended" but that's for Linux geeks and people who want to mess around with the code. Just download the latest Windows build. At the moment it is version 32735 http://sourceforge.net/projects/mplayer-win32/files/MPlayer%20and%20MEncoder/revision%2032735/MPlayer-rtm-svn-32735.7z/download Or look here http://sourceforge.net/projects/mplayer-win32/files/MPlayer%20and%20MEncoder/ |
|
| 7492. |
Solve : Missing Operand error in batch script? |
|
Answer» while running a batch script i am getting error as "Missing Operand". STRANGE thing is the same script runs FINE in my local PC while same is throwing error in other test PC. and idea? |
|
| 7493. |
Solve : BAT to read multiple .INI from folders and report a setting? |
|
Answer» Request help building a Batch file to read and report a setting from an ini. from a set of folders, and output result to a text file. |
|
| 7494. |
Solve : I am looking to change filenames sequentially in a given directory? |
|
Answer» I used to know how to do this back in my MS-DOS days (when Windows 3.x was a big thing) but I haven't used batch files since switching to Windows 95 (it's HARD to believe that it's only been 15 years since then; seems a lot longer ago than that! ).
A good copying job, Billrich. Quote from: QBall on December 30, 2010, 10:15:40 PM Microsoft needs to incorporate a batch file-renamer into it's file manager! I wouldn't think that it'd take too much code to add / change the existing file rename utility Windows Explorer has? http://blogs.msdn.com/b/oldnewthing/archive/2010/05/31/10017567.aspx Quote from: QBall on December 30, 2010, 10:07:41 PM Thanks for the help! I'd love to see Billrich's answer to this question. The short answer is that it "enables delayed expansion" which you can look up on Google. Code: [Select]import java.io.*; public class SequentialRename { public static void main (String[] args){ if ( args.length != 1 ){ System.out.println("Usage: java SequentialRename [extension]"); System.exit(1); } String extension = args[0]; String[] directory = (new File(".")).list(); int counter = 1; for( String name : directory ){ if ( name.endsWith( extension) && (new File(name)).isFile() ){ String newName = name.replaceAll( "\\."+extension+"$" , "" ) + counter + "." + extension; System.out.println( "old name: " + name + " , new name: " + newName ); ( new File( name ) ).renameTo ( new File( newName ) ); counter++; } } } } run using Java, Code: [Select]java SequentialRename jpg [recovering disk space - old attachment deleted by admin]would that not also replace files that happen to have only a name part that end with the extension? Such as, in your example, files like testjpg and filejpg and so forth? (probably an easy fix, and it's probably not something that would be encountered frequently) Also- honest question- why did you select the screen name "JavaHater", yet most of the code you've posted here has been exclusively in java? hi, thanks for your comments Quote from: BC_Programmer on December 31, 2010, 01:57:53 AM would that not also replace files that happen to have only a name part that end with the extension? Such as, in your example, files like testjpg and filejpg and so forth? (probably an easy fix, and it's probably not something that would be encountered frequently)No, it will only replace those that are actual files, and those that have a dot "." , as in ".jpg". (the string for the regular expression actually is "\.jpg$" when combined). |
|
| 7495. |
Solve : new on this forum? |
|
Answer» I am new here and LOOKING for DOS programs for my DOS computer. I am currently running DOS 5.0 and am looking for Lotus 123 and WP 5. Any places to buy this software? Thanks While I am thinking about it...which file is executed first or in which order are these FILES executed? .com .exe or .batDo a GOOGLE search |
|
| 7496. |
Solve : RENAME FILE NAME AND INCLUDE SYSTEM DATE IN BATCH FILE? |
|
Answer» I WANT TO RENAME THE FILE NAME THROUGH BATCH SCRIPT. FOR EXAMPLE. salmon how can i change the date format in dos prompt? To do this requires making changes to the registry then logging off then logging on again (or system restart) and is severely not recommended, and is probably not permitted in corporate environment. It is also unnecessary. You can use VBScript date methods to get dd mm yyyy of current date without changing local settings. The batch can write a temporary VBScript .VBS file like here: Code: [Select]@echo off >DateString.vbs ( echo MyD = day^(Date^) echo myM = month^(Date^) echo myY = year^(Date^) echo If MyD ^< 10 Then echo DD = "0" ^& CStr^(MyD^) echo Else echo DD = CStr^(MyD^) echo End If echo If MyM ^< 10 Then echo MM = "0" ^& CStr^(MyM^) echo Else echo MM = CStr^(MyM^) echo End If echo YYYY = CStr^(MyY^) echo wscript.echo DD ^& "-" ^& MM ^& "-" ^& YYYY ) REM Example of use for /f "delims=" %%D in ('cscript //nologo DateString.vbs') do set DString=%%D & del DateString.vbs echo Today's Date is %DString% Output Code: [Select]Today's Date is 02-01-2011 |
|
| 7497. |
Solve : Renaming all files so they have file size and filename? |
|
Answer» Quote from: JavaHater on January 01, 2011, 11:21:06 PM there is only 1 question i have for you. I guess that question was directed at BC_P but here's my answer: nobody can say you must not post Java solutions. Post freely. It is always interesting, and can be instructive, to see different methods of solving (or attempting to) a problem. However be prepared for discussion about it. Quote from: Salmon Trout on January 02, 2011, 02:14:37 AM I guess that question was directed at BC_P but here's my answer: nobody can say you must not post Java solutions.Good then. comments on program bugs or logic errors are welcome on the solutions I post, other than that, useless discussions like whether Java is appropriate or not, or "using a cannon to shoot down sparrows" or "using a sledgehammer to crack a nut" will be strictly ignored by me in future.Quote from: JavaHater on January 02, 2011, 02:37:40 AM Good then. comments on program bugs or logic errors are welcome on the solutions I post, other than that, useless discussions like whether Java is appropriate or not, or "using a cannon to shoot down sparrows" or "using a sledgehammer to crack a nut" will be strictly ignored by me in future. Then you may find robust disagreement from some people. You are exhibiting a curiously short-sighted and narrowly focussed attitude. The perceived merit of any particular solution is not merely a question of whether it contains any bugs or errors of logic or syntax. There are external considerations too, which are often ignored. Many people on here asking for a batch solution are doing so for a work related reason. They are not at home on their own PC where they can download and install whatever they like. Very, very often indeed they are prevented from installing "better" tools than batch or Visual Basic Script such as Java, Awk, Perl, Ruby, SED, grep, or whatever. One reason may be that the system admins won't let them. Another may be that the solution may be for wide deployment and it may be impractical to install 3rd party tools on every desired workstation. Yet another may be that for reasons to do with confidence the person asking the question wants a solution that they can understand now, not later when they have learned a new tool, no matter how desirable or easy you may think that would be. This illustrates a problem that seems to arise often -- forgive me if it does not apply to you, I am remarking generally -- when teenage or introverted adult "code warriors" who know plenty about coding but nothing about people and workplace issues fire up their tools and provide a classroom type solution. In general I would proceed thus: if somebody shows a batch script or a fragment of one, and says "how can I make this work better/at all?" I would answer that question directly because they clearly have already chosen their METHOD and just need a pointer or two. If they show no code at all but explicitly ask for a batch solution I would still answer in that way. If they want to do something which is impossible in batch (and there are surprisingly few things that fit that definition) I would think about Visual Basic Script. (With your Java skills you COULD look at Jscript). If the problem is more suited to a programming language I would say so. I would not impose a different method just because I happened to admire it more than the built-in tools. Posting a java, C#, C, C++, or other compiled language source as a solution to a problem in a forum quite clearly labelled "Microsoft DOS" is in a large part due to hubris. Also, I've FOUND that doing so never has the "OMG you are a genius" effect that one might expect. I learned that in this thread. Generally I don't usually offer batch-based solutions in this section, because I'm less than familiar with most of the extended syntax that the NT interpreter has; when somebody actually posts a request for a pure DOS solution or if their requirements allow the use of the less versatile older DOS style batches I might help out. I mean, I write a short C, C++, C#, Scala, Haskell or F# solution that would "solve their problem" but really, that's sort of the point; it doesn't solve the problem so much as it presents the illusion of solving the problem- it doesn't ADDRESS any issues that may arise, or the possibility that they may in fact be using the original code for a reason. For example- it may be a small part of a larger batch file. In that case now that segment would be calling into a java class file. Not so bad, but what about if they want to change the logic in that class file, and nobody knows how to work with java? or they lose the original source? Then they have to reimplement it in batch again anyway. |
|
| 7498. |
Solve : Remove a directory but save a file within.? |
|
Answer» Long live DOS \ \\// Long live DOS \ \\// And yet, half the commands you use wouldn't work on DOS...I used DOS for years before and during the early years of Windows and frankly I think I knew it fairly well. Frankly, I've FORGOTTEN a lot of what I knew about DOS from years of non-use. I do still use it occasionally, but not as a primary operating system anymore. There are still a lot of things you need the command prompt for, but it seems that some of the questions on the DOS forum could be done fairly easily in Windows. If the object is to learn more about DOS then it's a good thing. If the object is to be productive, then there is a better way.Very well stated... |
|
| 7499. |
Solve : Computer has started automatically saving in public folders - Windows 7? |
|
Answer» My computer is automically saving files into the public folders (Windows 7). It has only recently started doing this. Does anyone KNOW how to stop this HAPPENING? I want the files saved under my user name, rather than PUBLICLY. ThanksConfusion! Much confusion! |
|
| 7500. |
Solve : Make numbered copies of the same short file.? |
|
Answer» I have a small file called 'tone.mp3' which is just a short tone. |
|