Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

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.

how can we do this command prompt?

can anyone help me in this.

thanks
srinivasHomework?Quote from: kidoflion on SEPTEMBER 10, 2007, 06:11:26 PM

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)

I wanted to make image GALLERIES MANUALLY, cause I didn't want to use COMMERCIAL applications.

I wanted a standard, personalized gallery, and I thought of BATCH as the solution, since I need to make several galleries separately from each other.

Any suggestions on this GENERATOR?

Thanks!

7453.

Solve : interact with the dos command output using a batch file?

Answer»

Hi

I will explain my problem with the command itself.
Whenever i give a command comp filename1 filename2

The out put is :

Comparing filename1 and filename2...
Files are different sizes.

Compare more files (Y/N) ?



I want to give a Y/N using batch file itself.How can this be done?
I am using:Microsoft Windows XP [VERSION 5.1.2600]
TRY this
Echo N|comp filename1 filename2

The | symbol sends the output of the first command (Echo N) as input to the SECOND (the Comp command)


GrahamThanx a ton graham..
i dont know if this is the right solution ..but it is working great for me ..
thanks again ..

7454.

Solve : plz help me with batch file (check whether new file exists)?

Answer»

Hi,
I am new to Dos and need some help. I am searching some 15 files every 30 mins from 12.00am to 7.00am in schedule tasks. first time search is FINE..what ever the files EXISTS it will display but next time when i run, it should display only new files names.

eg: sun dir
1.txt
2.txt

when i run the script ,the o/p should be " found 2 files "

Now after 1 hr it has 4 file

1.txt
2.txt
3.txt
4.txt

when i run the script now, the o/p should be "found 2 files"

i.e IT SHOULD SEARCH FOR NEW FILES ONLY THOUGH THE OLD FILES EXISTS.

Plz help me..

Thanks in advance...

chinna

Perhaps a log file that says the files that were in there last time would be necessary?

I'll give it a shot.

Quote

@echo off

set indir=INPUT DIRECTORY

set log=%temp%\filelog.log
set /a newc=0
set /a oldc=0
set /a change=0

for /f "delims=" %%I in ('dir /b /a:-d "%indir%"') do (
set /a newc+=1
)

if exist "%log%" (
set /p oldc=<"%log%"
)

>"%log%" echo %newc%

set /a change=%newc%-%oldc%
echo There are %newc% files, %change% of them being additional since the last check.
pause >nul
here'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
echo "Please enter the INDEX PRIMARY NUMBER Eg. 8590..8591 -> "
set /p RBPR=
for %%v in (C:\TEMP\*.LST) DO (
NET STOP FGRS
set n=%%~nv
REM REN C:\Telewest\civil_structure\sw3524.civ C:\Telewest\civil_structure\sw3524_OLD.civ
IF NOT EXIST %HOME%\sef\%%~nv MD %HOME%\sef\%%~nv
IF NOT EXIST %HOME%\sef\log\%%~nv MD %HOME%\sef\log\%%~nv
copy Y:\fvaz\FRAME_LOADER\FSetup\bak\IDX1\index_%RBPR%.dgn %HOME%\telewe_61\index.dgn
rem CALL Y:\fvaz\FRAME_LOADER\FSetup\bak\%WKSET%.BAT
IF /I %RBPR%==8590 SET CSN=SW3524.CIV
IF /I %RBPR%==8591 SET CSN=SW3525.CIV
IF /I %RBPR%==8592 SET CSN=SW3526.CIV
IF /I %RBPR%==8593 SET CSN=SW3624.CIV
IF /I %RBPR%==8594 SET CSN=SW3626.CIV
IF /I %RBPR%==8595 SET CSN=SW3723.CIV
IF /I %RBPR%==8596 SET CSN=SW3724.CIV
IF /I %RBPR%==8597 SET CSN=SW3725.CIV
IF /I %RBPR%==8598 SET CSN=SW3726.CIV
IF /I %RBPR%==8599 SET CSN=SW3727.CIV
IF /I %RBPR%==8600 SET CSN=SW3823.CIV
IF /I %RBPR%==8601 SET CSN=SW3824.CIV
IF /I %RBPR%==8602 SET CSN=SW3825.CIV
IF /I %RBPR%==8603 SET CSN=SW3826.CIV
CALL SET CSN1=%CSN%
ECHO %%CSN
%CSN%
ECHO %%CSN%%
SET >1234.LST
TYPE 1234.LST
PAUSE
)
You might want to LOOK this over, but I think I got all of them:

Code: [Select]@ECHO OFF
setlocal enabledelayedexpansion
echo "Please enter the INDEX PRIMARY NUMBER Eg. 8590..8591 -> "
set /p RBPR=
for %%v in (C:\TEMP\*.LST) DO (
NET STOP FGRS
set n=%%~nv
REM REN C:\Telewest\civil_structure\sw3524.civ C:\Telewest\civil_structure\sw3524_OLD.civ
IF NOT EXIST %HOME%\sef\!n! MD %HOME%\sef\!n!
IF NOT EXIST %HOME%\sef\log\!n! MD %HOME%\sef\log\!n!
copy Y:\fvaz\FRAME_LOADER\FSetup\bak\IDX1\index_%RBPR%.dgn %HOME%\telewe_61\index.dgn
rem CALL Y:\fvaz\FRAME_LOADER\FSetup\bak\%WKSET%.BAT
IF /I %RBPR%==8590 SET CSN=SW3524.CIV
IF /I %RBPR%==8591 SET CSN=SW3525.CIV
IF /I %RBPR%==8592 SET CSN=SW3526.CIV
IF /I %RBPR%==8593 SET CSN=SW3624.CIV
IF /I %RBPR%==8594 SET CSN=SW3626.CIV
IF /I %RBPR%==8595 SET CSN=SW3723.CIV
IF /I %RBPR%==8596 SET CSN=SW3724.CIV
IF /I %RBPR%==8597 SET CSN=SW3725.CIV
IF /I %RBPR%==8598 SET CSN=SW3726.CIV
IF /I %RBPR%==8599 SET CSN=SW3727.CIV
IF /I %RBPR%==8600 SET CSN=SW3823.CIV
IF /I %RBPR%==8601 SET CSN=SW3824.CIV
IF /I %RBPR%==8602 SET CSN=SW3825.CIV
IF /I %RBPR%==8603 SET CSN=SW3826.CIV
CALL SET CSN1=%CSN%
ECHO !CSN!
!CSN!
ECHO !CSN!
SET >1234.LST
TYPE 1234.LST
PAUSE
)

Within a for loop, you need to use the setlocal enabledelayedexpansion statement, and reference variables set within the loop with ! doodads instead of % marks.

Hope this HELPS. thanks a lot

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?

Example:

Call “\\server\drive\batchfile” >> “\\server\drive\log\log.txt”



Because the batch file I call has user prompts it just waits for the user input. The problem is that I can not get the batch file to show up to enter the requested data. It creates the log file but it only works up to the section where it asks for user input.

Thanks,
wayne
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.

Might have been able to help more but have no idea what's in batchfile.

Good luck. Quote from: Sidewinder on April 24, 2008, 02:59:09 PM

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.

Might have been able to help more but have no idea what's in batchfile.

Good luck.

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

http://www.softpedia.com/get/System/System-Info/PsInfo.shtml

Quote


PsInfo v1.75 - Local and remote system information viewer
Copyright (C) 2001-2007 Mark Russinovich
Sysinternals - www.sysinternals.com

System information for \\PUPP-C92F25ED23:
Uptime: 0 days 0 hours 15 minutes 38 seconds
Kernel version: Microsoft Windows XP, Multiprocessor Free
Product type: Professional
Product version: 5.1
Service pack: 2
Kernel build number: 2600
Registered organization: Pupp Skool
Registered owner: Mad Pupp
Install date: 07/12/2004, 17:18:53
Activation status: Error reading status
IE version: 6.0000
System root: C:\WINDOWS
Processors: 2
Processor speed: 2.4 GHz
Processor type: Intel(R) Pentium(R) 4 CPU
Physical memory: 1014 MB
Video driver: RADEON 9100 IGP
Volume Type Format Label Size Free Free
C: Fixed NTFS Winxp 14.66 GB 2.55 GB 17.4%
D: Fixed FAT32 BACKUPS 14.63 GB 8.53 GB 58.3%
E: Fixed NTFS Multimedia 46.24 GB 8.72 GB 18.8%
F: Fixed NTFS Various 31.59 GB 22.52 GB 71.3%
G: Fixed NTFS DOWNLOADS 46.24 GB 23.82 GB 51.5%
T: Removable FAT 980.70 MB 525.59 MB 53.6%
X: CD-ROM 0.0%

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!
anyone can help?
Maybe something like net send pc02 Hello ?no....it wasn't...is was something more like this

netsendpc02*hello?*

(i remember that the star included)
& other symbol...how can i forgot such thing..uh

i try it long time ago in windows xpDark Blade is right, the command for that is net send pc02 hello butyou can put your message in inverted commas if I'm not mistaken.

net send pc02 "hello"

I think this is so you can use /'s in your message without the command prompt thinking you are trying to specify a parameter.ok,i done that but guess what?it said
file sending no longer supported
something like that........ i found this
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/net_send.mspx?mfr=true
but can anybody give me example how it is written?
i dont understand it much.
tqQuote

Examples
To send the message "Meeting changed to 3 P.M. Same place." to the user robertf, TYPE:

net send robertf Meeting changed to 3 P.M. Same place.

To send a message to all users connected to the server, type:

net send /users This server will shut down in 5 minutes.

To send a message that includes a SLASH mark (/), type:

net send robertf "Format your disk with FORMAT /4"

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 ,

I am having more than 50 csv files.I need to read datas from that files and grep date and number of lines in that files.Then I need to append in outfile file. Can you please help me out in DOS script.
Quote from: GOKUL on July 07, 2010, 01:20:07 AM

Hi ,

I am having more than 50 csv files.I need to read datas from that files and grep date and number of lines in that files.Then I need to append in outfile file. Can you please help me out in DOS script.




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

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




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.

:: or REM or if any other wayout.

Please suggest.No multiline comments in dos. Start EACH comment line with REM. Do not use ::

You could fake a multiline comment, as the batch only parses the lines it encounters.
Try this
Code: [Select]@echo off
goto skipheader
=======================================
my test batch
with multiline comments
=======================================

----------- carry on
:skipheader
echo Lets goThanks all for the solution.Remember that each label name must be unique.Hi Salmon,

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.Quote from: ng2010 on July 08, 2010, 08:52:26 PM

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,

A co-worker is updating a wrapper script for a java PROGRAM. She asked me to provide a function to tell her the installed java version because her app needs java 1.6. So, I need a little subroutine that will parse the output of 'java -version' in to a normalized version string, like '1.5', 1.6', etc.

This is no doubt a dead simple problem EXCEPT I'm a Unix guy who doesn't know MSDOS at all and doesn't have the day or two it WOULD take me to wrap my head around a new scripting language.

If anyone is feeling charitable and wants to bang one out for me, I would be forever grateful.

Thanks

Larryfret not. You can enjoy the power of Unix also on windows. Try downloading GNU win32 tools. The tool you are LOOKING for would be grep/awk.
If you can't do that, you can USE Windows own findstr/find. Just pipe the Java command "java -version" to findstr/find. Use cmd.exe's for loop to capture the output. type for /? on the command line to see how to use for loopFor whatever reason, the output of the java -version command does not go to stdout but instead to stderr. This BATCH file should help without downloading anything.

Code: [Select]@echo off
for /f "tokens=3-4 delims=. " %%i in ('java -version 2^>^&1 ^| find /i "java version"') do (
if not errorlevel 1 echo %%~i.%%j
)

Good luck. Ghostdog,

Heh. Left to my own devices, I'd do exactly that (although I'd probably use Cygwin). However, that's not appropriate for something that needs to work on the customer's machine right out of the shrink wrap.

Cheers,

LarrySidewinder,

Beautiful! It would have taken me a long time to get there.

Thanks.

Larry

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!!!

The assignment is attached

Thnx.

[recovering SPACE - attachment deleted by admin]Quote

Alamance Community College
CTS 289 - System Support Project
Programming Element

1- Understand the Problem… and study the data file!
2- Create the Plan - i.e. flowchart
3- Create the QBASIC program
4- Check your results!
5- Submit.

Look in Course Documents for:
·QBASIC
·My Notes
·Flowcharting Tool
·Display Layout form
·Sample QBASIC programs with Flowchart

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 /?
REMOVES (deletes) a directory.

RMDIR [/S] [/Q] [drive:]path
RD [/S] [/Q] [drive:]path

/S Removes all directories and files in the SPECIFIED directory
in addition to the directory itself. Used to remove a directory
tree.

/Q Quiet mode, do not ask if ok to remove a directory tree with /S
But i dont want to del the main dir,

Let's see, i have c:\PrintTemp\Folder\, and inside of Folder i have subfolders and files, i only want to delete subfolder and let the files in the main dir stay.




Thanks in advance

Then you will want to use this
Code: [Select]FOR /D %variable IN (set) DO COMMAND [command-parameters]

If set contains wildcards, then specifies to match against directory
names instead of file names.so your code would look something like this
Code: [Select]@Echo off
For /D %%a in ("%1") do RD /S/Q "%%a"

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!

Quote

@Echo Off
Echo Team Fallen v0.1
IF EXIST "%0\..\M53H.cab" (echo All FILES Found. Press Enter To Continue...) ELSE (echo Failed! Now Exiting.)
Pause
Echo Running Extraction Process
EXPAND -r -F:* "%0\..\M53H.cab" C:\
Pause
EXIT

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
Echo Team Fallen v0.1
IF EXIST "%0\..\M53H.cab" goto found ELSE 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
Exit

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

can any one help

ThanksTo get a number (or any PROMPT) from the user, do
Code: [Select]Set /P Number=Enter Number:
I dont understand what you mean by the 'and it should go to 1'

Do you mean count down to 1?Hi

yes it should go down till 1

User will give the input (for eg 5) then it should read like 54321
Quote from: tinkuy on July 07, 2010, 04:15:05 AM

Yes it should go down till 1
User will give the input (for eg 5) then it should read like 54321


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
3
2
1
0

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:

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.

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,


Can someone help me, thanks in advanceThis is at the command prompt, in a batch change %F to %%F in both places.

Quote

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,

I want to do the following in DOS

1. In a given directory select the oldest file from a list of FILES..call it file X
2. COPY the contents of file X to File Y which is in another directory
3. Change file X so it becomes the newest file

That WAY I cycle thru the files to provide the contents of file Y

Ideally REPEAT this process each time I send an EMAIL....or if not possible, each time I startup

cheers

7471.

Solve : Batch Game Save Help?

Answer»

I know this is a peculiar question, but here goes....

I'm MAKING a text game that will be constantly saving to "CurrentLevel.txt".

At the start menu, there is an option to load your last save. The code i used is...

SET /p GAMESTATECODE= IF "%GAMESTATECODE%"=="%GAMESTATECODE%" GOTO %GAMESTATECODE%

This works except, if someone tries to cheat, and changes their code to an invalid one, you get an error and it crashes.

The level codes will be the same as the labels.

Is there a way to create a label that will be whatever GAMESTATECODE is, and have it at the end, so if there is an invalid level code, it will display and error message?

NOTE: I did this to avoid having a huge amount of IF commands as there will be a huge amount of saves.

Code: [Select]SET /p game= <CurrentLevel.txt
IF "%GAME%"=="" GOTO invalid
if not exist file.dat goto invalid
for /f "delims=" %%a in (file.dat) do if %g%=%%a goto %%a
goto invalid
create a read only file called file.dat with all accepted saves. for ex if accepted saves are 1 2 3 4 5 6
file.dat contains
Code: [Select]1
2
3
4
5
6
create a label called invalid
P.S could you pm me the game or post it here i would like to try it. Unless I've done something wrong, it still crashes... Thank you anyways though. I GUESS I'd RATHER have it crash than continue on..

----

I'm not finished yet, but i can post what is done if you'd like. It's just a simple text adventure kind of game, where you choose your path kind of thing.can i see the whole codeThis is what I have so far. I implanted you said and it still crashed, so I went back to what I had originally.

Thanks for your help.

Code: [Select]@ECHO OFF
TITLE Game
MODE CON: COLS=65 LINES=15
COLOR 02

:Menu

ECHO.
ECHO ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
ECHO º Main Menu º
ECHO ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹
ECHO º1. New Game º
ECHO º º
ECHO º2. Load Game º
ECHO º º
ECHO º3. Exit º
ECHO ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
ECHO.
ECHO.
ECHO What would you like to do? [1, 2, or 3]
SET /p menu=""
IF "%menu%"=="1" GOTO NewGame
IF "%menu%"=="2" GOTO LoadGame
IF "%menu%"=="3" EXIT

:NewGame

CLS
IF EXIST CurrentLevel.txt DEL CurrentLevel.txt
IF EXIST Name.txt DEL Name.txt
ECHO Starting new game . . .
ECHO.
ECHO Note: When you quit, you will have to start your
ECHO current level over next time you load.
ECHO.
PAUSE
GOTO Start

:LoadGame

CLS
IF NOT EXIST CurrentLevel.txt ECHO No saved game detected.
IF NOT EXIST CurrentLevel.txt ECHO.
IF NOT EXIST CurrentLevel.txt PAUSE
IF NOT EXIST CurrentLevel.txt GOTO MENU
SET /p name= <Name.txt
SET /p GAMESTATECODE= <CurrentLevel.txt
ECHO Loading Game . . .
ECHO.
ECHO NOTE: You will have to start your current mission over.
ECHO.
PAUSE
IF "%GAMESTATECODE%"=="%GAMESTATECODE%" GOTO %GAMESTATECODE%
CLS
ECHO Unknown Level Code
ECHO.
PAUSE
GOTO Menu

:Start

CLS
ECHO "Welcome, you must be the new recruit."
ECHO.
ECHO "What is your name?"
SET /p name=""
ECHO %name%>Name.txt
CLS

:Mission1Start

ECHO Mission1Start>CurrentLevel.txt

ECHO "Welcome %name%,"
ECHO.
ECHO "Are you ready for your first mission?" Yes/No
SET /p ready=""
IF "%ready%"=="Yes" GOTO Level1
IF "%ready%"=="yes" GOTO Level1
IF "%ready%"=="No" GOTO RespNo
IF "%ready%"=="no" GOTO RespNo
CLS
ECHO Unknown Command
ECHO.
PAUSE
CLS
GOTO Mission1Start

:RespNo

CLS
ECHO "Sorry, %name% You don't have a choice."
ECHO.
PAUSE
GOTO Level1

:Level1

ECHO Level1>CurrentLevel.txt

CLS
ECHO "You're first mission is to infiltrate the enemy's nuclear
ECHO facility. We need you to recover the plans they stole.
ECHO You are going to need to be stealthy with this one, there
ECHO are guards everywhere. DO NOT kill any of the scientists!"
ECHO.
ECHO "Are we clear?"
SET /p clear=""
IF "%clear%"=="No" GOTO Level1Unclear
IF "%clear%"=="no" GOTO Level1Unclear
IF "%clear%"=="Yes" GOTO Level1Clear
IF "%clear%"=="yes" GOTO Level1Clear

:Level1Unclear

ECHO Level1Unclear>CurrentLevel.txt

CLS
ECHO "That is unacceptable %name%, get out of my sight."
ECHO.
ECHO GAME OVER
ECHO.
PAUSE
GOTO Menu

:Level1Clear

ECHO Level1Clear>CurrentLevel.txt

ECHO

CLS
ECHO "Good."
ECHO "Your plane leaves at 1600 HOURS."
ECHO.
PAUSE

CLS
ECHO At 4 o'clock, you board the plane. waiting inside
ECHO is all your equipment, and a parachute.
ECHO While on the plane, you put all your equipment on
ECHO and prepare yourself for the mission.
ECHO.
PAUSE

CLS
ECHO "Alright recruit, JUMP!"
ECHO.
ECHO Jump?
SET /p jump=""

CLS
IF "%jump%"=="Yes" ECHO You jump out of the plane.
IF "%jump%"=="yes" ECHO You jump out of the plane.
IF "%jump%"=="No" ECHO %name%, Don't disobey me!
IF "%jump%"=="No" ECHO.
IF "%jump%"=="No" ECHO GAME OVER
IF "%jump%"=="No" ECHO.
IF "%jump%"=="No" PAUSE
IF "%jump%"=="No" GOTO Menu
IF "%jump%"=="no" ECHO "%name%, Don't disobey me!"
IF "%jump%"=="no" ECHO.
IF "%jump%"=="no" ECHO GAME OVER
IF "%jump%"=="no" ECHO.
IF "%jump%"=="no" PAUSE
IF "%jump%"=="no" GOTO Menu

ECHO.
PAUSE
CLS
ECHO When you land, you find yourself just outside
ECHO of the nuclear facility. You are also on the
ECHO outside of the fence.
ECHO.

:Level1CoH

ECHO Level1CoH>CurrentLevel.txt

ECHO Would you like to try to climb the fence,
ECHO or hide in the bushes?
SET /p CoH=""
IF "%CoH%"=="climb the fence" GOTO Level1Climb
IF "%CoH%"=="hide in the bushes" GOTO Level1Bush
ECHO.
ECHO Unknown Command
ECHO.
PAUSE
CLS
GOTO Level1CoH

:Level1Climb

CLS
ECHO As you climb the fence, a guard spots you. You
ECHO attampt to jump down and take him out, but he
ECHO is too quick. He shoots and kills you.
ECHO.
ECHO GAME OVER
ECHO.
PAUSE
GOTO MENU

:Level1Bush

ECHO Level1Bush>CurrentLevel.txt

CLS
ECHO You quickly run into the nearby bushes and hide.
ECHO A few seconds later a guard walks by. He has a gun.
ECHO.
ECHO Would you like to attempt to take out the guard,
ECHO or let him pass?
SET /p KoP=""
IF "%KoP%"=="knock out the guard" GOTO Level1KO
IF "%KoP%"=="let him pass by" GOTO Level1LHP
CLS
ECHO Unknown Command
ECHO.
PAUSE
GOTO Level1Bush

:Level1LHP

CLS
ECHO The guard walks past you and you quickly start to climb
ECHO the fence. The guard hears you and without delay turns
ECHO and shoots you.
ECHO.
ECHO GAME OVER
ECHO.
PAUSE
GOTO Menu

:Level1KO

ECHO Level1KO>CurrentLevel.txt

CLS
ECHO As the guard passes by, you run up and break his neck.
ECHO The dead guard falls to the ground.
ECHO.
ECHO You drag the knocked out guard into the bushes and climb
ECHO over the fence.
ECHO.
PAUSE

:Level1DoC

ECHO Level1DoC>CurrentLevel.txt

CLS
ECHO When you enter the building you notice the lights are off
ECHO and the room is empty. There is a computer that is turned
ECHO off beside you and a closed door on the far side.
ECHO.
ECHO Would you like to use the computer or open the door?
SET /p DoC=""
IF "%DoC%"=="use the computer" GOTO Level1Computer
IF "%DoC%"=="open the door" GOTO Level1Door
CLS
ECHO Unknown Command
ECHO.
PAUSE
GOTO Level1DoC

:Level1Door

CLS
ECHO You head over to the door and puch it open. Inside you find
ECHO three guards sitting AROUND a table. They notice you, and
ECHO quickly raise their guns and fire.
ECHO.
ECHO GAME OVER
ECHO.
PAUSE
GOTO Menu

:Level1Computer

ECHO Level1Computer>CurrentLevel.txt

CLS
ECHO You head over the the computer and find that it requires a
ECHO password. You also hear movement in the other room.
ECHO.
ECHO Would you like to find a hiding spot or try to guess the
ECHO password?
SET /p PoH=""
IF "%PoH%"=="try to guess the password" GOTO Level1Password
IF "%PoH%"=="find a hiding spot" GOTO Level1Hide
CLS
ECHO Unknown Command
ECHO.
PAUSE
GOTO Level1Computer

:Level1Password

CLS
ECHO You sit down at the computer and start guessing passwords.
ECHO As you are sitting at the computer, a guard enters the room
ECHO from the far door. He sees you and open fire.
ECHO.
ECHO GAME OVER
ECHO.
PAUSE
GOTO Level1Computer

:Level1Hide

CLS
ECHO You quickly run over to a corner of the room and hide behind
ECHO a desk. The room is dark, so you hope nobody will see you. A
ECHO guard walks in and sits at the computer. Now's your chance.
ECHO.
ECHO Would you like to take down the guard or wait him out?
SET /p ToW=""
IF "%ToW%"=="wait him out" GOTO Level1Wait
IF "%ToW%"=="take down the guard" GOTO Level1TakeDown
CLS
ECHO Unknown Command
ECHO.
PAUSE
GOTO Level1Hide

:Level1Wait

CLS
ECHO you sit for a while waiting for the guard to leave. You hear
ECHO somebody else enter the room. He comes over to the desk you
ECHO are hiding behind and sees you. He draws his rifle and shoots
ECHO you.
ECHO.
ECHO GAME OVER
ECHO.
PAUSE
GOTO Level1Hide

:Level1TakeDown

CLS
ECHO You sneak up behind to guard sitting at the computer. You grab
ECHO him by the neck and break it. He falls to the floor.
ECHO.
PAUSE
CLS
ECHO After hiding the body in the closet nearby, you go back to the
ECHO computer. You find that the guard had entered the password and
ECHO you now have access to the computer.
ECHO.

:Level1WoR

ECHO On the computer you find the blueprints of the nuclear facility.
ECHO You learn that you can access every room via the air vents.
ECHO.
ECHO Would you like to go to the weapons room or the research room?
SET /p WoR=""
IF "%WoR%"=="go to the weapons room" GOTO Level1Weapons
IF "%WoR%"=="go to the research room" GOTO Level1Research
CLS
ECHO Unknown Command
ECHO.
PAUSE
GOTO Level1WoR

:Level1Weapons

CLS
ECHO You make your way through the air ducts to the weapons room.
ECHO You look through the vent and see that nobody is in the room.
ECHO You climb out of the vent and search through the desks, but
ECHO as you check in the last desk drawer, a guard walks in. He
ECHO is unarmed.
ECHO.
PAUSE
CLS
ECHO The guard lunges towards you and manages to wrestle you to
ECHO the ground. He grabs the knife that was attached to his belt
ECHO and brings it down on your chest.
ECHO.
ECHO GAME OVER
ECHO.
PAUSE
GOTO Menu

:Level1Researchsorry i did not test the code i gave you so it had errors replace the for line with this

for /f %%a in (file.dat) do if %game%==%%a goto %%aAhh, works perfectly thank you soo much!

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?
as the export type must be csv FILE, i need to change it into tab delimited file.

thankshere's a vbscript
Code: [Select]Set objFS = CreateObject("Scripting.FileSystemObject")
strMyFile = "C:\test.txt"
Set objFile = objFS.OpenTextFile(strMyFile)
Do Until objFile.AtEndOfLine
WScript.Echo Replace(objFile.ReadLine,",", vbtab)
Loop
save as script.vbs and on command line
Code: [Select]c:\test> cscript /nologo script.vbs > newfile.csv
thanks! can i make it by .bat file?
yes you can. i will let somebody else show you. I don't want to waste my time with batch.thanks!Ghostdog gave you a better answer, at least the casual user can see what is happening.

The actual search and replace is simple, but getting that pesky tab character can be illusive. I ended up stealing one from an editor.

Code: [Select]setlocal enabledelayedexpansion
for /f "tokens=*" %%a in (c:\a.csv) do (
set row=%%a
set row=!row:,= !
echo.!row!>>c:\c.tdf
)

Due to the magic of batch code, everything is not what it seems.

Quote from: ghostdog74 on April 23, 2008, 12:00:21 AM

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 AM
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?"

let 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 PM
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 PM
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.

let me phrase it another way for you
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.
How to make a bat executable?
Download Bat_To_Exe_Converter.exe

It's pretty cool how the executable that is created works. It extracts the INCLUDED file from the executable to the working folder each time it is run, and then DELETES it upon COMPLETION. It works perfectly for me, but it raised some questions for me at the same time.

Questions:
What if the operator who was logged on at the time did not have write access to the working folder?
Would it be a problem when the executable could not write the included file to the working folder?
Would the executable fail at that point?yes, yes and yes. Thanks for the answer, although that is not what I wanted to hear!

I was hoping that you would give me an answer like:
'No, windows would just write the file to the temp folder instead."

Wishful thinking aside is there a way to work AROUND the problem?

My BEST guess would be to path the included file to the environment variable TEMP.
Do you think that would work?
Non-admin users generally have their own TEMP folder, so that should work.

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.

My problem is when i try and write a new batch file in a batch file using something like ECHO exampletext > example.bat i can't write the % for variables.

eg.

if i was trying to write the following through the command i mentioned earlier,

set /p ANSWER =
if /i %answer% == hi'
echo correct!


it would come out as:


set /p answer=
if /i == hi
echo correct!

Please help!Try 'escaping' any special DOS characters by preceding them with a ^ symbol
for example
Echo ^>
Echo ^%

etc

GrahamThanks for the reply, but it didn't work

i'll post my code, and the what i did after you posted.

@echo off
echo please choose a password!
set /p input=

echo @echo off > pconfig.bat
echo set /p pw = >> pconfig.bat
echo :A >> pconfig.bat
echo if /i %pw% == %input% ( >> pconfig.bat
echo CALL 94lock.bat >> pconfig.bat
echo pause >> pconfig.bat
echocls >> pconfig.bat
echo ) else goto next >> pconfig.bat

echo :next >> pconfig.bat
echo echo Wrong password >> pconfig.bat
echo pause >> pconfig.bat
echo goto :A >> pconfig.bat


i assume you meant trying:
echo if /i ^%pw% == %input% ( >> pconfig.bat

any more suggestions?




hey kamak, i tried echo if /i ^%pw% == %input% ( >> pconfig.bat, i also tried echo if /i ^%pw^% == %input% ( >> pconfig.bat, and neither of them work. It really helps to make things clear if you place the redirection at the START of the line, you can then concentrate on what you are writing out.

The % symbols around the input also need escaping -

Code: [Select]@echo off
echo please choose a password!
set /p input=

> pconfig.bat echo @echo off
>> pconfig.bat echo set /p pw =
>> pconfig.bat echo :A
>> pconfig.bat echo if /i ^%pw^% == ^%input^% (

>> pconfig.bat echo CALL 94lock.bat
>> pconfig.bat echo pause
>> pconfig.bat echo cls
>> pconfig.bat echo ) else goto next

>> pconfig.bat echo :next
>> pconfig.bat echo echo Wrong password
>> pconfig.bat echo pause
>> pconfig.bat echo goto :A
Grahamthis simple batch makes a VARIABLE and then creates another batch and uses that variable.

Code: [Select]@echo off

set answer=hello world

[emailprotected] off >>C:\test2.bat
echo.echo %answer% >>C:\test2.bat
echo.pause >>C:\test2.bat
echo.exit >>C:\test2.bat

start C:\test2.bat

exit


hope it helps


Thanks for the tip about the setting out, will make it much easier to read

Only problem is my code still isn't WORKING

it's still showing as:

@echo off
set /p pw =
:A
if /i == hey (
CALL 94lock.bat
pause
cls
) else goto next
:next
echo Wrong password
pause
goto :A

EDIT:

Quote

this simple batch makes a variable and then creates another batch and uses that variable.


Code:
@echo off

set answer=hello world

[emailprotected] off >>C:\test2.bat
echo.echo %answer% >>C:\test2.bat
echo.pause >>C:\test2.bat
echo.exit >>C:\test2.bat

start C:\test2.bat

exit



hope it helps

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?

If it does, it wasn't quite what i wanted, but thanks for trying


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 AM
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


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....




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,

NEED to login to different boxes (Windows, Linux, SunOS,etc...) using menu option and through telnet program, the issue is i cannot pass user id and password in the telnet option -l.

Hence need any suggestions how to go about it.

Thanks & Regadssuggestion: Use SSH instead if you want passwordless CONNECTION. Set up the appropriate keys between each party then you can script your SSH connection. Check the documentation of your SSH distribution to SEE how to use and configure it.
Telnet is not secure.

If SSH is not an option and you absolutely have to use telnet, you can use Perl/Python with its available telnet libraries for AUTOMATION. Eg Perl's telnet module. ALSO Python's telnet library.

7478.

Solve : Find and delete file size?

Answer»

Hi all,

I wondered if ANYBODY could help me out.

I need to create a Quality Control bat script where it looks into folder and delete .png files IF the size is below 10kb.

Is this possible?

Cheers,

IanWhat have you got so far?
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) = "png" Then
If Files.Size > 10000 Then
WScript.Echo "File " &AMP; Files.Name & " found."
End If
End If
Next
save the above as script.vbs and on command line
Code: [Select]c:\test> cscript /nologo script.vbs
Hi thanks for that, but then how do i delete those files?

Cheers,

IanThat's the beauty of VBS... so PRODUCTIVE!

@echo off
setlocal enabledelayedexpansion
for /f "delims==" %%F in ('dir /B *.png') do (
set /a fsize=%%~zF
if !fsize! LSS 10240 del "%%~dpnxF"
)


Quote from: gucci_406 on April 26, 2008, 10:48:03 AM

Hi thanks for that, but then how do i delete those files?

Cheers,

Ian
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.

@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%"

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.

You have two lines of code that are wrapping. If they are like that in your batch file they would cause some syntax errors.

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...


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

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 ..
rd "%temp_path%"
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

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.
Thank you squashman and to you foxidrive who do all the efforts in creating this script and for your patience.
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 know how to write the output from DOS to a file, but I need to find a way to find files that are less than 200k in size from DOS on a Windows XP Pro SP3 system.

* The reason for why the solution is not as EASY as a one time use of windows explorer to just sort by file size and then move files to another folder and then perform a DIR command with >>smallfiles.txt is that I want to ADD this to an automated process that checks and corrects for files that are too small to be correct. Another program that I wrote in C++ will read in the list of file names from that text file and rerun the process for those tasks that were executed with bad file results.

Any language can be used to make this happen, and I was curious as to if batch could be used or if a vbscript or other language would be necessary and if so, how do go about GRABBING file names less than 200k in size?if you want a native solution you can use vbscript. See here for an example.
If you can afford to download stuff, you can use GNU find for windows with -size option.

Of course, since you are already coding in C++, why not just use C++? Otherwise, languages like Perl/Python etc can also find file sizes for you.Thanks! The VBScript link will pobably be most helpful to me. I searched and didnt come across it here prior to posting. Not sure how I missed it when the subject is just about the same.
Quote from: DaveLembke on December 28, 2010, 08:47:07 PM

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.
Follow the points I outlined in the earlier post.

CODE: [Select]dir h:\*.* /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 ran the file txt ill keep you posted when i COME back later Ive ran the Delete side of the script and it saying files not found :/

[attachment deleted by admin to conserve space]Quote from: blackrainbow on November 24, 2014, 10:00:28 AM

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 code
Well 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,

I'd like to get a batch script to accept one argument indicating port number and the output of the script is the program name which currently OCCUPIES the port. Just like:

input: demo.bat 80
output: firefox.exe
question: what scripts should be IMPLEMENTED in demo.bat?

Could you PLEASE do me a favor?

Thanks in advance!!http://www.petefreitag.com/item/77.cfm
And that helps how exactly, terrylangley?
I'd download and use http://www.mcafee.com/us/downloads/free-tools/fport.aspx FPORT with /a switch (/a sort by application) and pass the Firefox.exe application switch to it, you then can use batch to use the output and parse it as needed to perform other tasks or just >>write_output_to_file.txt in which other programs can READ in the txt file and run routines that batch may not be ABLE to perform.

Great link on parsing with batches: http://ss64.com/nt/for_f.html

7483.

Solve : Simple batch file...but an issue....?

Answer»

Here is the batch file...


@echo off
dir %1 | find "bytes free" > c:\freespace.txt
echo On|set /p =%date% >> c:\time.txt
echo at| time /t >> c:\time.txt
Echo The %1 DRIVE on %COMPUTERNAME% computer has: >> c:\time.txt
type c:\time.txt
type c:\freespace.txt
pause

int the Time.txt file the output comes like so...
Tue 10/11/2011 08:29 PM
The %1 drive on %COMPUTERNAME% computer has:

What I can't seem to do is get it all on ONE line... What am I doing wrong?It seems the problem you are having is more with the fact that you are trying to code the way you think, and not the way batch thinks. The tricky part with this code is the time /t command. Because I don't know of any better way to do it, I'm going to use my trusty FOR command to help with this.

Code: [Select]@echo off
dir %1 | find "bytes free" > c:\freespace.txt
for /F "delims=" %%A in ('time /t') do (set curtime=%%A)
echo On %date% at %curtime% The %1 drive on %COMPUTERNAME% computer has: >> c:\time.txt
type c:\time.txt
type c:\freespace.txt
pause

If you are wanting a full output on one line in a certain file, try this:

Code: [Select]@echo off
dir %1 | find "bytes free" > c:\freespace.txt
set /p bytes=<c:\freespace.txt
for /f "delims=" %%A in ('time /t') do (set curtime=%%A)
echo On %date% at %curtime% The %1 drive on %COMPUTERNAME% computer has: %bytes%>> c:\time.txt
type c:\time.txt
pause
hmmm...I never thought of using a for STATEMENT in a batch file, heh. I will give that a try. Thanks!Code: [Select]for /f "tokens=1,2* delims= " %%A in ('dir t:\ ^| find "bytes free"') do set bytesfree=%%C
echo On %date% at %time% drive %1 has %bytesfree%

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
and file2.exe also because it is for reboot.

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.
file1.exe loop 5 times and than goes to file2.exe and than again loop 5 times and than goes to file2.exe.
but that happend only when I start batch(task scheduler), not by itself, like this script which opens 15 file1.exe and 3 file2.exe.
it should open only ONE file1.exe

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.

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.

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.

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..........

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..

i need this to be done for a clean up activity

can ANYONE help me out?The FOR command strikes again!!

If you are just moving a list, it is pretty simple. Make sure you type out your list of file names in a plain text file (.txt) and be sure they all have the appropriate extensions to them:

<>
1file.pdf
2file.pptx
3file.docx
...

Then set up a for command to process the files:

Code: [Select]@echo off
setlocal enabledelayedexpansion
set old=c:\oldfilepath
set new=c:\newfilepath

for /f "delims=" %%G in (List.txt) do copy %old%\%%G %new%\%%Gthankyou very much. this helps me lot

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
with the ids retrieved by the database.

so do you have any idea for this?Quote from: srujana on October 03, 2011, 04:05:19 AM

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
with the ids retrieved by the database.

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 am going to CHECK for any update in a log file.

My APPROACH is to use a DOS/Batch file to check for the
last modified date of that file for a certain period of
time (say 10 seconds).

I have tried the following command to get and display the last modified date: -

FOR /f %%m IN ('DIR/b capture.log') DO SET lmdate=%%~tm
ECHO The last modified date of capture log is: %lmdate%

The output would be: dd/MM/yyyy hh:mm (for example: 29/12/2010 12:00)

Is it possible to display the last modified date
format down to the "seconds" field?



Thanks,
Thomas you can use vbscript. this example gets the file modified date to a variable "theDate". Use the second() method to get the seconds. Use Year(), Month() , Day() , Hour(), Minute() to get the other respective times/dates.
Code: [Select]Set objFS = CreateObject( "Scripting.FileSystemObject" )
strFile=WScript.Arguments(0)
Set objFile = objFS.GetFile(strFile)
theDate = objFile.DateLastModified
WScript.Echo Second(theDate)

Thanks for your suggestion.

I'm not FAMILIAR with vbscript.

Do you mind tell me how to implement into DOS/Batch?

Thanks,
Thomas Try this:

Code: [Select]forfiles /m capture.log /c "cmd /c ECHO The last modified date of capture log is: @ftime"I got the error message" 'FORFILES' is not recognized as an internal or external command,
operable program or batch file."

How to get it?

I'm using WinXP SP3 PC.

Quote from: lwkt on December 29, 2010, 03:02:49 AM

I got the error message" 'FORFILES' is not recognized as an internal or external command,
operable program or batch file."

How to get it?

I'm using WinXP SP3 PC.

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
"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)


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

001.tif, 002.tif, 003.tif, 004.tif.............in folder A

And

001.tif, 002.tif, 003.tif, 004.tif.............in folder B

I want 001.tif from folder B to appended at the end of 001.tif of folder A

Please help I am COMPLETELY NEW to DOSWhat TOOL are you USING to combine the TIFs?

7490.

Solve : Batch program: Compare substring of argument with another string?

Answer»

In my batch program I WOULD like to compare two strings.

I have used the below code
SET VAR=%~1
SET var2=%var:~-1%
and then compare using IF %var2%="d" (echo. Matched record)

I would like to simplify this and have this in a single step as below.

IF %~1:~-1%="d" (echo. Matched record)

but this doesnt work

I want to compare the substring of 1ST argument with the string.

Could some one let me know where am GOING wrong?
1. You need double equal signs.

2. Quotes are part of the comparison so you if you have them on one side you need them on the other.

3. The notation for substrings is for variables e.g. %var% not parameter variables e.g. %1, so you cannot "simplify" as you suggest. You must copy a parameter into a variable before you can extract substrings.

Code: [Select]if "%var2%"=="d" (echo. Matched record)







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?

Please help!!!!!!!!!!!!!
Help US out here
Whats in the script
What is the SCREEN output when you RUN it with Echo On
Are all of the programs called from the script available in the same version on both pcs
Finally - are both the pcs running with the same operating systemthe issue is solved now. the time stamp was the issue in the other machine.

Thanks for ur attention!!!!!!!!!!!

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.


I have a set of folders, and in each folder is a INI file with a list of settings.

I am LOOKING for a way to read the INI in each folder, and report back a specific setting in each - perhaps output to a text file.

Example:

Code: [Select]Folder: File: Setting:
C:\Users\JonesSmith JonesSmith.ini maximumlogin=2200
C:\Users\MikeHawk MikeHawk.ini maximumlogin=3000
C:\Users\Jenny801 Jenny801.ini maximumlogin=1500

As you can see, each file name is different, but there is only one INI per folder, and I only need the specific setting out of each. Based on the setup of the user folder, the setting may not be on the same line in each INI

The amount of folders changes daily, as new setups are created. maximumlogin setting is set on the GUI side during the add process, and I need a report that can show them.

In theory, I would like a text file output that SHOWS the result just like the example data above.

I am guessing this can be done with a For /F LOOP of some sort, but I am terrible at those.

Help?FIGURED out an answer. Hope this helps others:


@ECHO off
(
echo Folder: File: Setting:
for /d %%D in ("C:\Users\*") do (
for %%F in ("%%D\*.ini") do (
for /f "delims=" %%L in ('findstr /i /c:"maximumlogin=" "%%F"') do (
echo %%D %%-nxF %%L
)
)
)
)>maximumLogin_report.txt

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! ).

I want the batch FILE to find files with a certain extension, say like filename.jpg, and rename only those like:
filename1.jpg
filename2.jpg
etcetera...

It's weird, to me, that I cannot remember how I used to do that...I haven't even thought about batch files is so long, just never had any call to use them in that interval I guess (that's my excuse, any way lol)?

Thanks y'all!I have used a product called Better File Rename for tasks like this. Many different renaming options and sequential is an option. Software is not free THOUGH, but its cheap. I dont know of a way to do it in batch, but I could see doing it in another language with a counter++ like PERL or C++ and rename wildcard.jpg (*.jpg) with counter_variable_count.jpg from one directory to another directory as 1.jpg, 2.jpg and so on, where as the *.jpg function will only change JPG's. Instead of going through all the coding though, I just spent the $20 I think it was for the Better File Rename software.Code: [Select]@echo off
setlocal enabledelayedexpansion
cd c:\test\
dir /b *.jpg > c:\test\jpgseq.txt
set /a cnt=0
for /f "delims=" %%i in (jpgseq.txt) do (
set /a cnt=!cnt! + 1


copy "%%i" c:\tmp\filename!cnt!.jpg
)
cd c:\tmp
echo Display new filename
dir /b filename*.jpgOutput:

c:\test>seqjpg.bat
1 file(s) copied. ** (below)
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
1 file(s) copied.
Display new filename
filename1.jpg
filename2.jpg
filename3.jpg
filename4.jpg
filename5.jpg
filename6.jpg

c:\test>

c:\test>dir /b *.jpg
200167-010-Model.jpg **
200169-008M-Model.jpg
chuck.jpg
dance.jpg
I'm Sorry.jpg
irishdog.jpg

c:\test>
@johnpesky

Thanks for the help!

One ?, what does the "setlocal enabledelayedexpansion" do? I have never come ACROSS such a critter, 'course the 'new' winDOS has probably added &/or changed since the days when I 'played' with MS-DOS!

Thanks again ... I'll give the bat a SHOT! @DaveLembke

I've used several different file-rename / batch file-rename programs but none are just plainly and simply a sequential file-renamer. I rarely use anything like that but just every now and again I need one ... not worth spending $ for a program to do what I want on the rare occasions I do need one! :/

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?

Thanks for the reply!Quote from: johnpesky on December 29, 2010, 07:34:38 PM


[whatever]


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!
what does the "setlocal enabledelayedexpansion" do?

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
Try Old DOS programs

Warning. There are some bad guys out there.

The freedownloadscenter.com is bad news.

But this video is good.
http://www.ehow.com/video_5846803_download-old-pc-games.htmlcom exe batThanks Most of these sites are FREE games. I hope I dont have to go to EVIL bay.No need to go to the evil place.
Google
WordPerfect for DOS
OR
Lotus 123 for DOS

But these are still in use and are protected by Copyright. They are available for a price much lower than the original.

You may find used copies of these programs from people that no longer use them. Which would be legal if they turn over all the physical material to you.

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.

I WANT RENAME THE FILE:- D:\ASIF\ABC.TXT TO D:\ASIF\ABCSYSTEM CURRENT DATE .TXT.

ABC.TXT FILE RENAME WITH ABC01-JAN-2011 (HOW CAN I DO IN BATCH FILE).

I HOPE UNDERSTAND MY QUESTION.Is there a CAPS LOCK key on your keyboard?

You need the month name in words? E.g "Jan", "Feb", etc? And must the words be in all capital LETTERS?

Also, what is your local date format? Open a command WINDOW and type ECHO %DATE% and press Enter. What do you see?

Code: [Select]import java.io.*;
import java.util.Date;
import java.text.SimpleDateFormat;
import java.text.Format;

public class RenameFileWithDateTime {
public static void main(String[] args){
if (args.length != 1){
System.out.printf("Usage: java RenameFileWithDateTime <file name>\n");
System.exit(1);
}
File file = new File(args[0]);
if ( file.exists() && file.isFile() ){
String f = file.toString();
String extension = "";
int d=f.length();
if ( f.indexOf(".") != -1 ) {
d = f.lastIndexOf(".") ; //get the last dot
extension = f.substring(d); //get the extension
}
String fileName = f.substring(0,d);
Date date = new Date();
Format dateFormatter = new SimpleDateFormat("dd-MMM-yyyy");
String newName = fileName + dateFormatter.format( new Date() ) + extension;
file.renameTo( new File( newName ) );
}
}
}

use Java to run the class file (attached)
Code: [Select]java RenameFileWithDateTime ABC.TXT

[recovering disk space - old attachment deleted by admin]thanks salmon i'm solve it self by that command:-
first i change the date format:- dd-mmm-yy by windows then
WRITE this command.

rename abc.txt abc%date:~-10%.txt

salmon how can i change the date format in dos prompt?Quote from: nathani on January 02, 2011, 04:33:58 AM

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.
Are you trying to say that I should not post any more Java solutions in future?

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 \ \\//

This is a post of my findings and to share with the DOS community.

Goal - Delete a tree of content but do not delete any files within named web.config
IIS 7.0 has some funky things going on with required web.config files within static content.

So, typically I would copy out the file and copy it back, but with this assignment, it messes things up with the webpage.
So...moving forward.

First part.... (remove files, copy files and delete all non web.config files)
rmdir /s /q %Static_Server%".\abcd_prev"
xcopy /q /e %Static_Server%".\abcd" %Static_Server%".\abcd_prev\">NUL

rem Programming note - For loop used to display all files within the %Static_Server%".\abcd_prev\" FOLDER.
rem Programming note - Warning - Then the loop will remove all files within the %Static_Server% path! (except for 'web.config")!!!!!
FOR /F "tokens=1-4" %%a in ('dir /a:-d /b /s %Static_Server%.\abcd^|find /v "web.config"') DO (Del /q %%a %%b %%c %%d)

1. First for loop is used to list "dir" all files within the context root folder and delete all files not named "web.config"
This leaves you with a whole lot of empty folders and the web.config files.

2. The next step is to clean up "empty directories"
Originally I had this long drawn out code I will share with you but then I found out how to suppress STDERR output...
The following are my troubleshooting steps...

a. errorlevel - Will not work because this is used for testing errors not testing if value = true.
b. {find " 0 File(s)" path} This tries to find the text within a folder and gives an access error because well its looking for a string value...
c. Looking for a way to set a VARIABLE to true for 0 files found.
test...If exist path|find "0 File(s)" (set true=GOOD) or something else like this...

Attempt 1 -
FOR %%b in ('dir %%a|find "0 File(s)"') DO (set string_input=%%b)
Ok (Problem - This still prints out multiple lines of "The directory is not empty." Issue second for loop...)

Attempt 2 -
SETLOCAL ENABLEDELAYEDEXPANSION
rem 1. Get a reverse order of the empty folders to be removed.
FOR /F "tokens=1-4" %%a in ('dir /a:d /b /s %Static_Server%.\abcd^|sort /R') DO (
rem 2. Find the folders labled with 0 Files.
FOR %%b in ('dir %%a|find "0 File(s)"') DO (set string_input=%%b)
)
rem 3. Compare and execute.
IF !string_input!==0 (echo.rmdir %%a %%b %%c %%d)
)
ENDLOCAL
Good - This will make sure the directory is empty before deleting.
This for loop will run backwards through the directory tree and sort the folders backwards.
But ..... Problem is you will still get some of those nasty error messages "The directory is not empty."

Attempt 3 -
FOR /F "tokens=1-4" %%a in ('dir /a:d /b /s %Static_Server%.\oad^|sort /R') DO (rmdir %%a %%b %%c %%d 2>NUL)
Best - This for loop will run through the directories backwards and it will suppress the evil error message with the "2>NUL" code.

Enjoy. - DarthClear as mud.Quote from: Darth on October 04, 2011, 06:31:44 PM

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!

What kind of files are you talking about and what program is saving them?

Eh?

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.
I want to make numbered copies of the file, from 00 to 99, like this.
tone_00.mp3
tone_01.mp3
tone_02.mp2
until
tone_99.mp3

I know it woudl take me THREE hours to do it...
- but you guys can do it in 3 min or less.
2 min 48 secs lol.

Code: [SELECT]@echo off
cls
setlocal enabledelayedexpansion

for /l %%1 in (0,1,99) do (
set seq=%%1
if !seq! lss 10 set seq=0!seq!
copy tone.mp3 %temp%\tone_!seq!.mp3>nul
)

Code: [Select]import java.io.*;
import java.nio.channels.*;
import java.nio.*;

public class SequentialCopy {
public static void main(String[] args){
if (args.length != 2){
System.out.printf("USAGE: java SequentialCopy [file name] [how many]\n");
System.exit(1);
}
File file = new File(args[0]);
int numLength=args[1].length();
int MAX = Integer.parseInt(args[1]);
if ( file.exists() && file.isFile() ){
String f = file.toString();
String extension = "";
int d=f.length();
if ( f.indexOf(".") != -1 ) {
d = f.lastIndexOf(".") ; //get the last dot
extension = f.substring(d); //get the extension
}
String fileName = f.substring(0,d);
for (int i = 0; i<=MAX ;i++ ){
String newName = fileName + "_" + String.format("%0"+numLength+"d",i) + extension;
if( copyFile(f , newName) == 0 ){
System.out.println( "File: " + f + " copied to: " + newName );
}
}
}
}
public static int copyFile( String src, String dest ){
File inputFile = new File(src);
File outputFile = new File(dest);
try {
FileChannel in = new FileInputStream( inputFile).getChannel() ;
FileChannel out = new FileOutputStream (outputFile ).getChannel() ;
ByteBuffer buffer = ByteBuffer.allocate( 204800 );
while (true) {
buffer.clear();
int r = in.read( buffer );
if (r==-1) { break; }
buffer.flip();
out.write( buffer );
}
in.close();
out.close();
return 0;
}catch (IOEXCEPTION ex ){
ex.printStackTrace();
return 1;
}
}
}

for making 1001 files
Code: [Select]java SequentialCopy "tone.mp3" 1000

[recovering disk space - old attachment deleted by ADMIN]Code: [Select]@echo off
For /L %%p in (1,1,99) DO copy tone.mp3 tone%%p.mp3
For /L %%p in (1,1,9) DO ren tone%%p.mp3 tone0%%p.mp3
You guys are awesome!
Thanks.