Solved

I need a batch job to delete files by filename

Posted on 2014-03-12
16
262 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 18

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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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 18

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 18

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Have you ever had a hard drive that you can't boot into, but need to change the registry? Here is the solution! This article guides you through accessing and editing a registry of a non-primary drive. To read registry information on a non-prim…
INTRODUCTION The purpose of this document is to demonstrate the Installation and configuration of the Data Protection Manager product. Note that this demonstration was prepared on the basis of Windows OS is 2008 R2 and DPM 2010. DATA PROTECTI…
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…
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