Problem: The "del" command won't delete certain files when it is executed from a batch file but it will delete those files if it is executed from the CMD shell command line interpreter. The problem appears to be related to the fact that the filenenames contain an ellipsis character.
I am not new to batch files, I have been writing and using batch files since 1988 with MSDOS 3.2, through Windows 7. Now I am using Windows 10 Pro 21H1. What follows is a description of the problem.
A directory list dir
shows that the folder contains the following five files:
Volume in drive E has no label.
Volume Serial Number is 3D74-5A3F
Directory of E:\Backups\Magpie\2016-12-14-P\mike\Correspondence\Friends\Berg\In
10/21/2021 03:27 PM <DIR> .
10/21/2021 03:27 PM <DIR> ..
08/16/2021 03:15 AM 40,888 20160114-Fwd_ [New post] Biologist's comments to save White Mountain & Little Colorado wild horses (Today is the last day YOU can comment)-29324528.eml
08/16/2021 03:15 AM 21,095 20160229-More.-13257179.eml
08/16/2021 03:15 AM 47,526 20160229-Re_More…-13334902.eml
08/16/2021 03:15 AM 11,256,759 20160819-(Duplicate) Whew. Re_ Good thurs am God bless your first day back to work-10.eml
10/21/2021 02:48 PM 182 DeleteDuplicatesDC.bat
10/20/2021 06:19 PM <DIR> Photos
10/21/2021 02:00 PM <DIR> Temp
6 File(s) 11,366,450 bytes
4 Dir(s) 199,814,967,296 bytes free
I want to delete the third file whose name is 20160229-Re_More…-13334902.eml
Note the three dots following the word More
in the filename. It is a single ellipsis character. It is NOT three separate dots.
The batch file was generated by a macro I wrote to assemble instructions to delete hundreds or thousands of individual files that meet certain criteria.
My batch file has the following commands:
Echo 271
CD "E:\Backups\Magpie\2016-12-14-P\mike\Correspondence\Friends\Berg\In\"
del "20160229-Re_More…-13334902.eml"
Echo 271
The Echo commands simply write a number to the screen to show the progress of the batch file.
The batch file contains hundreds of similar lines which delete hundreds of files in various directories.
When I ran the batch command it deleted most of the files it was supposed to delete but it would not delete the file:
20160229-Re_More…-13334902.eml
In order to check if the commands were valid and correct I ran them one at a time from a command line using the following steps. In a CMD shell CLI (Command-Line-Interpreter" I Copy-Pasted the command
CD "E:\Backups\Magpie\2016-12-14-P\mike\Correspondence\Friends\Berg\In\"
from the batch file into a CMD command line shell and executed it. It took me to the correct directory which was
E:\Backups\Magpie\2016-12-14-P\mike\Correspondence\Friends\Berg\In\
.
I then Copy-Pasted the following command from batch file into the CMD shell to delete the file:
del "20160229-Re_More…-13334902.eml"
and executed it. The del
command deleted the file successfully (as it was supposed to do). The file also disappeared from a File Explorer window that I had open to monitor progress.
This test showed that the two commands did what they were supposed to do, which was to move to a certain directory (folder) and delete a certain file.
But the del
command did NOT delete the file with the ellipsis character when I executed it from the batch file.
I don't understand why these commands cd
and del
work when I execute them individually from a CMD shell CLI but the del
command did not delete the file I wanted to delete when I ran it in a batch file?
Does anyone have the answer to this problem? Thank you Michael