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
Solved

I need a batch job to delete files by filename

Posted on 2014-03-12
16
263 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
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 34

Expert Comment

by:Dan Craciun
ID: 39924500
Yup. Sometimes batch is shorter :)
0
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 

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 34

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 53

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to run this powershell script inside  a batch file ? 19 508
regex to extract ip:john 17 74
How can i echo a ! to end of a file? 8 23
Convert .csv to tab delimited text 11 33
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…
When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …

809 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