Solved

How to delete *.dot files among *.dotm files with cmd script?

Posted on 2010-08-20
16
588 Views
Last Modified: 2012-05-10
I have a folder with .dot files and .dotm files.  For example I have blank.dot and blank.dotm files. I need to delete those .dot files because they are not used any more. But I noticed using DEL *.dot deletes also .dotm files. What is the right command to use?
0
Comment
Question by:SJARV
  • 6
  • 3
  • 2
  • +3
16 Comments
 
LVL 9

Expert Comment

by:Dan Arseneau
ID: 33485214
Are you sure?  I have 2 files x.abc and x.abcd.  I run del x.abc and only the one deletes.
0
 
LVL 1

Expert Comment

by:ekarls20
ID: 33485302
Dan, the problem is the wild card.

A workaround would be to first "move *.dotm" and then "del *.dot".
0
 
LVL 9

Expert Comment

by:Dan Arseneau
ID: 33485327
Sorry, I worded it wrong.  I ran del *.abc and only the one deletes.
0
 
LVL 52

Expert Comment

by:Bill Prew
ID: 33485415
Well, this isn't pretty, but it will work:

for %A in (*.doc) do if "%~xA"==".doc" del "%A"

~bp
0
 
LVL 16

Expert Comment

by:t0t0
ID: 33488860
This command will do the trick quite nicely.

   for /f "tokens=*" %a in ('dir /a-d /b *.dot') do if /i "%~xa"==".dot" del "%a"
0
 
LVL 16

Expert Comment

by:t0t0
ID: 33488878
Here's a batch file version of the command above.

   ::============================================
   :: Delete just .DOT files
   ::============================================
   @echo off
   for /f "tokens=*" %%a in ('dir /a-d /b *.dot') do (
      if /i "%%~xa"==".dot" del "%a"
   )
   exit /b 0
0
 
LVL 16

Expert Comment

by:t0t0
ID: 33488882
prew, you got there seconds ahead of me.... Isn't your bed calling you?... :)
0
 
LVL 52

Expert Comment

by:Bill Prew
ID: 33488888
==> t0t0

Isn't that what I said?

Although I see I did use the wrong last character of the extension, thought we were working with word 2007 documents...

~bp
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 16

Expert Comment

by:t0t0
ID: 33489033
ah well, there you go then... obviously NOT what you said.

the author stated .DOT and .DOTM files - i'm just going along with what the author asked for.

BTW, I completely overlooked the simplicity of just 'FOR IN (filename)'....
0
 
LVL 52

Expert Comment

by:Bill Prew
ID: 33489053
Yes, I sometimes miss the small details when focusing on the "hard" part of these questions.  Need to get better about rereading the question after I write a solution, but before I submit it.

You'll be happy to know I'll be out for the evening shortly, make hay!

~bp
0
 
LVL 3

Expert Comment

by:Telxon
ID: 33497916
How about just "del *.do?"   ?

This should work even easier.   :-)
0
 
LVL 16

Expert Comment

by:t0t0
ID: 33498514
Telxon

Shockingly enoughm and I really can't understand the reasoning why, if you create 3 files as follows:

    file.ab
    file.abc
    file.abcd

And enter the following command:

    del *.ab?

All 3 files will be deleted.


DEL ignores the fact we want to delete ONLY those files with extension names 3 characters wide therefore, your 'DEL *.DO?' command will not work reliably.
0
 
LVL 16

Accepted Solution

by:
t0t0 earned 500 total points
ID: 33498552
As a command typed directly into a DOS box, this will work nicely:

   for %a in (*.dot) do if /i "%~xa"==".dot" del "%a"




The same command can be ran from within a batch file like this:

   @echo off
   for %%a in (*.dot) do if /i "%%~xa"==".dot" del "%%a"
0
 

Author Comment

by:SJARV
ID: 33498831
Thank you for all the answers. del *.do? will also delete .dotm files - so that does not work.

But those two suggestions with signatures "t0t0" and "billprew" will work when running through the cmd prompt. When I put this code to cmd-file and run it, nothing happens. The files to be removed are located under the user profile in All users\application data\xx path. I use CD "%ALLUSERSPROFILE\Application data\xx" command first to move to the correct folder and then use this for loop. CD works but this does not. I do not understand why? The idea is to run this scripf for multiple workstations.

Thanks again.
0
 

Author Closing Comment

by:SJARV
ID: 33499765
You can ignore my last comment. I am pretty sure I did not see this comment this morning...

I really need to run this code through cmd script and this %% thing works very well.
0
 
LVL 3

Expert Comment

by:Telxon
ID: 33503238
For what it's worth, I did try my suggestion and works as I described on a Win7 machine. Only .DOT files were deleted, not .DOTM files. Your mileage may vary on other OS's.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now