I need a batch job to delete files by filename

I have a huge drive with thousands of folders, and I need to scan through the folder and located anything that begins with xname and remove it (the wildcard would be xname*.* to cover all suffixes and extensions).

I've tried to do this with explorer (search and delete), but it just hangs.

Can somebody come up with a batch way of doing this (there will be over 100,000 files to be deleted)?
DebbieFostAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Bill PrewConnect With a Mentor Commented:
The DEL /S approach will work, it searches all subfolders for matching files and deletes them.  If it is saying the file was not found then if may be the files have the Hidden or System attribute, of a permissions problem, etc.

I assume there are no spaces in the file path you are using?  If there are you need to quote it then like:

del /s /q /f "z:\Myfiles\xname*.*"

Try this command to see:

dir /a-d /b /s "z:\Myfiles\xname*.*"

~bp
0
 
Dan CraciunIT ConsultantCommented:
If you're not set on batch, here's a powershell solution:
gci "x:\your\path" -filter "xname*.*" | % {remove-item $_.fullname -force}

Open in new window

HTH,
Dan
0
 
Raheman M. AbdulSenior Infrastructure Support Analyst & Systems DeveloperCommented:
del xname*.* /s /q /f
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Dan CraciunIT ConsultantCommented:
Yup. Sometimes batch is shorter :)
0
 
DebbieFostAuthor Commented:
I need to specify the path for the files deleted within: Z:\Myfiles

There are a lot of sub folders under this location, and the XNAME*.* files are located there.
0
 
Raheman M. AbdulSenior Infrastructure Support Analyst & Systems DeveloperCommented:
del z:\Myfiles\xname*.* /s /q /f
0
 
Santosh GuptaCommented:
already
0
 
DebbieFostAuthor Commented:
The XNAME*.* files are in SUBFOLDERS underneath z:\myfiles - they are not in the root, so "del z:\Myfiles\xname*.* /s /q /f"  does not work.
0
 
Dan CraciunIT ConsultantCommented:
It should. /s is for recursive.
If not, you can always try Powershell :)

gci "Z:\myfiles" -filter "xname*.*" -recurse | % {remove-item $_.fullname -force}

Open in new window

0
 
Santosh GuptaCommented:
forfiles /p z:\Myfiles\ /m xname*.*  /c "cmd /c del @file"

Open in new window

0
 
DebbieFostAuthor Commented:
It does not work - I just tested it - it does not locate any files underneath subfolders.

I am not familiar with powershell  - I would prefer to set this up in a *.bat file if possible to run off my desktop.
0
 
Santosh GuptaCommented:
pls try this.. sub directory as added now.

forfiles /p z:\Myfiles\ /m xname*.* /s  /c "cmd /c del @file"
0
 
DebbieFostAuthor Commented:
Getting closer -t his comes back saying it "could not find <actual path to each xname*.*>"
0
 
Raheman M. AbdulSenior Infrastructure Support Analyst & Systems DeveloperCommented:
DebbieFost:     my command should work with /s    

dir z:\myfiles\xname*.* /s  
will it list all the files you are looking ?
0
 
DebbieFostAuthor Commented:
No -  it returns a message that file is not found (even though there still are files in that location). Not sure if the issue is that this is a network drive....
0
 
Santosh GuptaCommented:
disconnect and map the drive and check.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.