[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 269
  • Last Modified:

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)?
0
DebbieFost
Asked:
DebbieFost
  • 5
  • 4
  • 3
  • +2
1 Solution
 
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. AbdulCommented:
del xname*.* /s /q /f
0
 
Dan CraciunIT ConsultantCommented:
Yup. Sometimes batch is shorter :)
0
Technology Partners: 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!

 
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. AbdulCommented:
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. AbdulCommented:
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
 
Bill PrewCommented:
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 5
  • 4
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now