Deleting files named "._*"

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
batchcc
Posts: 137
Joined: 17 Aug 2015 06:05
Contact:

Deleting files named "._*"

#1 Post by batchcc » 01 Dec 2017 14:08

Hello everyone! I am trying to delete all files in a certain directory and its sub-directories that has the name "._*" but this is the code I have but it is giving me an error.

Code: Select all

@echo off

setlocal

set count=0
set pattern=._*

for /f %%i in ('dir /b /a-d %pattern% ^| find /c /v ""') do @call set count=%%i

del /s /q /f ._*.txt
echo  %count% files deleted

endlocal

Error Message:

Code: Select all

Could Not Find H:\directory\._*
This batch file is located in "H:\directory" and some example file names include:

Code: Select all

._random.txt
._Day 1.docx
._Screen Shot 2017-05-26 at 2.16.41 PM.png
._Workbook1.xlsx
._Zoomin.mov
._Zoomout.mov

aGerman
Expert
Posts: 3890
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Deleting files named "._*"

#2 Post by aGerman » 01 Dec 2017 14:24

Since you're already trying to count the files you can also use the loop to delete them.

Code: Select all

for /f "delims=" %%i in ('dir /b /a-d /s ^| findstr /rec:"\\\._[^\\]*"') do (del /f "%%~i" &&set /a "count+=1")
Steffen

Squashman
Expert
Posts: 4178
Joined: 23 Dec 2011 13:59

Re: Deleting files named "._*"

#3 Post by Squashman » 01 Dec 2017 15:54

You sure the files have a txt extension.

I had no problems using your code.

Code: Select all

H:\period>dir /b
._File1
._File2.txt

H:\period>del ._*.txt

H:\period>dir /b
._File1

H:\period>echo blah>._File2.txt

H:\period>dir /b
._File1
._File2.txt

H:\period>del ._*

H:\period>dir /b

H:\period>

batchcc
Posts: 137
Joined: 17 Aug 2015 06:05
Contact:

Re: Deleting files named "._*"

#4 Post by batchcc » 02 Dec 2017 09:56

aGerman wrote:
01 Dec 2017 14:24
Since you're already trying to count the files you can also use the loop to delete them.

Code: Select all

for /f "delims=" %%i in ('dir /b /a-d /s ^| findstr /rec:"\\\._[^\\]*"') do (del /f "%%~i" &&set /a "count+=1")
Steffen
The code is giving me this error and not deleting anything
Could Not Find H:\testing\._random.txt
Could Not Find H:\testing\._Day 1.docx
Could Not Find H:\testing\._Screen Shot 2017-05-26 at 2.16.41 PM.png

aGerman
Expert
Posts: 3890
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Deleting files named "._*"

#5 Post by aGerman » 02 Dec 2017 10:14

Are you trying to delete hidden files? Update the DEL command

Code: Select all

del /a /f "%%~i"
Steffen

batchcc
Posts: 137
Joined: 17 Aug 2015 06:05
Contact:

Re: Deleting files named "._*"

#6 Post by batchcc » 03 Dec 2017 17:06

Thanks aGerman this works great!

Post Reply