Any ideas/suggestions would be helpful.
Thanks in advance.
Here is the bat file:
@echo off
REM HNACP00012012
if "%1"=="" goto usage
if "%2"=="" goto usage
if "%3"=="" goto usage
for /f "skip=1 delims=" %%a in ('DIR "%~1\%~2*.%3" /A-D /O-D /B /TW')
do ECHO %1\%%a
for /f "skip=1 delims=" %%a in ('DIR "%~1\%~2*.%3" /A-D /O-D /B /TW')
do del "%1\%%a"
goto xit
:usage
echo Usage: %0 directory fileprefix fileextension
echo.
echo This will change to the specified directory.
echo It will delete all files named fileprefix*.fileextension except
the one last written to.
echo.
echo Example: %0 c:\INFOSTAT\temp HISRpt txt
echo.
echo This will delete all files named HISRpt*.txt in the
c:\INFOSTAT\temp directory
echo except the one with the latest write date.
:xit
Here is what I get when I issue the command: CleanAllButLast
Usage: CleanAllButLast.bat directory fileprefix fileextension
'echo.' is not recognized as an internal or external command,
operable program or batch file.
This will change to the specified directory.
It will delete all files named fileprefix*.fileextension except the one
last wri
tten to.
'echo.' is not recognized as an internal or external command,
operable program or batch file.
Example: CleanAllButLast.bat c:\INFOSTAT\temp HISRpt txt
'echo.' is not recognized as an internal or external command,
operable program or batch file.
This will delete all files named HISRpt*.txt in the c:\INFOSTAT\temp
directory
except the one with the latest write date.
Since you insist on forcing 3 seperate arguments (ill advised), you may well
be advised you only need check if the third (last required) was given. The
first two argument checks are redundant. Also, if any arguments include
spaces, then you are in effect doubling the quoting. To prevent this from
occuring use the %~ syntax.
if "%~3"=="" goto usage
> for /f "skip=1 delims=" %%a in ('DIR "%~1\%~2*.%3" /A-D /O-D /B /TW')
> do ECHO %1\%%a
DIR's /TW seems to be the default behaivor, but your system may vary. The
following single argument batch should do what you want to acomplish.
@echo off
if [%1]==[] echo Syntax %~n0 [drive:][\path\]filespec.ext&goto :EOF
for /f "skip=1 delims=" %%a in ('DIR %1 /A-D/O-D/B') do del "%~dp1%%a"
> for /f "skip=1 delims=" %%a in ('DIR "%~1\%~2*.%3" /A-D /O-D /B /TW')
> do del "%1\%%a"
> goto xit
> :usage
> echo Usage: %0 directory fileprefix fileextension
> echo.
snip...
> Here is what I get when I issue the command: CleanAllButLast
>
> Usage: CleanAllButLast.bat directory fileprefix fileextension
> 'echo.' is not recognized as an internal or external command,
> operable program or batch file.
snip...
What program are you using to save your batch file?
BTW, for anyone not aware, there are groups specifically for NT/2K/XP
related batch discussions. Here are 2 such groups...
<news:alt.msdos.batch.nt>
<news://news.microsoft.com/microsoft.public.win2000.cmdprompt.admin>
And if you don't have access to those, try using...
<http://groups.google.com/groups?as_ugroup=alt.msdos.batch.nt>
--
Todd Vargo (double "L" to reply by email)
*** There are other characters which can be used, but I can't remember
them. One method which I do remember is to use TYPE to "display" a text
file that contains a carriage return.
Richard Bonner
http://www.chebucto.ca/~ak621/DOS/
Tom Lavedas
============
http://my.fcc.net/~tglbatch (new URL - old content)
eso...@cerner.com wrote:
> I have tried using echo. (echo followed by period) to create a blank
> line. I get the error:
> 'echo.' is not recognized as an internal or external command,
> operable program or batch file.
>
> Any ideas/suggestions would be helpful.
> Thanks in advance.
{snip}
It is obvious from the rest of you code that you are not using
MS-DOS+Win../95/98/Me but NT/2000/XP. I prefer to post my own
NT/2000/XP answers to news:alt.msdos.batch.nt so for my own posting
thread I have included and redirected.
Your problem is a common one
89} All of a sudden "echo." doesn't work any more. What's wrong?
144994 Dec 7 2005 ftp://garbo.uwasa.fi/pc/link/tscmd.zip
tscmd.zip Useful NT/2000/XP script tricks and tips, T.Salmi
All the best, Timo
--
Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance ; University of Vaasa
mailto:t...@uwasa.fi <http://www.uwasa.fi/~ts/> ; FIN-65101, Finland
Useful batch files and tricks ftp://garbo.uwasa.fi/pc/link/tsbat.zip
It is obvious from the omitted rest of your code that you are not
tlav...@hotmail.com wrote:
> Try
> substituting another punctuation mark for the period, like a comma or
> and equal sign to see if that will get you out of this situation. All
> are valid in all versions of Windows abd even in 'real DOS, AFAIK.
> Tom Lavedas
*** Not the `=' sign. It gives the status of "echo".
Richard Bonner
http://www.chebucto.ca/~ak621/DOS/
PS: Please don't top post.
R.
In what OS and version does the equal sign give ECHO status?
> "Richard Bonner" <ak...@chebucto.ns.ca> wrote:
(Re:( Echo=")
> > *** Not the `=' sign. It gives the status of "echo".
> In what OS and version does the equal sign give ECHO status?
> --
> Todd Vargo
*** All stand-alone MS versions. I also think PC-DOS exhibits this, but
can't remember. I haven't used PC-DOS in many years. Does anyone here have
a PC-DOS setup who could test this?
DR-DOS will give a blank line with most of the common punctuation
characters, and will also do so with the `=' sign.
Richard Bonner
http://www.chebucto.ca/~ak621/DOS/
Looking at a posting in alt.msdos.batch.nt, it appears the problem is I
had a file called "echo" (don't know how it got there) in the same
directory as my bat file. Deleting the file and using echo. (echo
followed by period) then worked as expected.
BTW - using echo, (echo followed by comma) or echo= (echo followed by
equal sign) did work even if I had a file called "echo" in the
directory.
Now which file might that be?
If you're referring to your BATCH file, then it might be an idea to use
Notepad or EDIT (from the prompt) for this purpose. Wordpad tends to save
formatting information that makes CMD.EXE very ill indeed.
HTH
...Bill
I understand you want to do things your own way but have you tried using the
modified foxidrive code as I posted? There is no harm in taking a look at
other methods. You may change your mind after you compare it's usage.
By using your example arguments as a single parameter (as shown below) the
code I posted works in Windows 2K/XP, and IMO, typing this way is more
natural and meaningful than using multiple parameters with the wildcard
excluded.
CleanAllButLast c:\INFOSTAT\temp\HISRpt*.txt
> I am using Wordpad to edit and save my file.
It seems the file named ECHO was the culprit but I agree with billious on
preference to using Notepad over Wordpad to avoid accidental formatted
saves. Good luck in your batch expeditions.
Thanks for all the help and suggestions.
*** I suspect the reason for that was that "ECHO." is a legal file name.
It would be similar to the format of "ECHO.txt" but without the extension.
Richard Bonner
http://www.chebucto.ca/~ak621/DOS/
*** I heartily endorse this method. There are many solutions for a
given batch file problem, and each that works is just as valid as any
others that work.
Trying various alternate methods is a good learning tool. One may also
find advantages for one method over another.
Richard Bonner
http://www.chebucto.ca/~ak621/DOS/
Thanks so much to all of you. I know I would not have had the
efficient (and correct) code and approach without your help.