Solved

I need a batch job to delete files by filename

Posted on 2014-03-12
16
258 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
  • 5
  • 4
  • 3
  • +2
16 Comments
 
LVL 34

Expert Comment

by:Dan Craciun
Comment Utility
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 18

Expert Comment

by:Raheman M. Abdul
Comment Utility
del xname*.* /s /q /f
0
 
LVL 34

Expert Comment

by:Dan Craciun
Comment Utility
Yup. Sometimes batch is shorter :)
0
 

Author Comment

by:DebbieFost
Comment Utility
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 18

Expert Comment

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

Expert Comment

by:Santosh Gupta
Comment Utility
already
0
 

Author Comment

by:DebbieFost
Comment Utility
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 34

Expert Comment

by:Dan Craciun
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 13

Expert Comment

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

Open in new window

0
 

Author Comment

by:DebbieFost
Comment Utility
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
Comment Utility
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
Comment Utility
Getting closer -t his comes back saying it "could not find <actual path to each xname*.*>"
0
 
LVL 18

Expert Comment

by:Raheman M. Abdul
Comment Utility
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
Comment Utility
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
Comment Utility
disconnect and map the drive and check.
0
 
LVL 51

Accepted Solution

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The way I use Experts Exchange to assist me in analyzing and diagnosing a problem is I first enter a Verbose Question at Experts Exchange like: Office 2007 will hang when opening and saving files I then launch WordPad (any text editor will do) an…
Many admins will agree: WSUS is is a nice invention but using it on the client side when updating a newly installed computer is still time consuming as you have to do several reboots and furthermore, the procedure of installing updates, rebooting an…
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…
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…

771 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now