Solved

I need a batch job to delete files by filename

Posted on 2014-03-12
16
266 Views
Last Modified: 2014-04-04
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)?
0
Comment
Question by:DebbieFost
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 3
  • +2
16 Comments
 
LVL 35

Expert Comment

by:Dan Craciun
ID: 39924490
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
 
LVL 19

Expert Comment

by:Raheman M. Abdul
ID: 39924492
del xname*.* /s /q /f
0
 
LVL 35

Expert Comment

by:Dan Craciun
ID: 39924500
Yup. Sometimes batch is shorter :)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:DebbieFost
ID: 39924531
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
 
LVL 19

Expert Comment

by:Raheman M. Abdul
ID: 39924536
del z:\Myfiles\xname*.* /s /q /f
0
 
LVL 13

Expert Comment

by:Santosh Gupta
ID: 39924539
already
0
 

Author Comment

by:DebbieFost
ID: 39924578
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
 
LVL 35

Expert Comment

by:Dan Craciun
ID: 39924593
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
 
LVL 13

Expert Comment

by:Santosh Gupta
ID: 39924607
forfiles /p z:\Myfiles\ /m xname*.*  /c "cmd /c del @file"

Open in new window

0
 

Author Comment

by:DebbieFost
ID: 39924614
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
 
LVL 13

Expert Comment

by:Santosh Gupta
ID: 39924624
pls try this.. sub directory as added now.

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

Author Comment

by:DebbieFost
ID: 39924643
Getting closer -t his comes back saying it "could not find <actual path to each xname*.*>"
0
 
LVL 19

Expert Comment

by:Raheman M. Abdul
ID: 39924698
DebbieFost:     my command should work with /s    

dir z:\myfiles\xname*.* /s  
will it list all the files you are looking ?
0
 

Author Comment

by:DebbieFost
ID: 39924755
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
 
LVL 13

Expert Comment

by:Santosh Gupta
ID: 39924812
disconnect and map the drive and check.
0
 
LVL 55

Accepted Solution

by:
Bill Prew earned 500 total points
ID: 39977862
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

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

This article describes how to set permissions to allow a limited-permissions user to start and stop a particular System Service.   It is always best to give users only the permissions that they need to perform their job, so tweaking particular permi…
Citrix XenApp, Internet Explorer 11 set to Enterprise Mode and using central hosted sites.xml file.
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

707 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