SJARV
asked on
How to delete *.dot files among *.dotm files with cmd script?
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?
Are you sure? I have 2 files x.abc and x.abcd. I run del x.abc and only the one deletes.
Dan, the problem is the wild card.
A workaround would be to first "move *.dotm" and then "del *.dot".
A workaround would be to first "move *.dotm" and then "del *.dot".
Sorry, I worded it wrong. I ran del *.abc and only the one deletes.
Well, this isn't pretty, but it will work:
for %A in (*.doc) do if "%~xA"==".doc" del "%A"
~bp
for %A in (*.doc) do if "%~xA"==".doc" del "%A"
~bp
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"
for /f "tokens=*" %a in ('dir /a-d /b *.dot') do if /i "%~xa"==".dot" del "%a"
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
::========================
:: 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
prew, you got there seconds ahead of me.... Isn't your bed calling you?... :)
==> 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
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
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)'....
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)'....
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
You'll be happy to know I'll be out for the evening shortly, make hay!
~bp
How about just "del *.do?" ?
This should work even easier. :-)
This should work even easier. :-)
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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\Applicat ion 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.
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\Applicat
Thanks again.
ASKER
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.
I really need to run this code through cmd script and this %% thing works very well.
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.