0

A beta software I installed accidentally created a log file with file name longer than 100 characters in each folder. It's taking a very long time to delete them one by one

Is it possible to bulk delete all the files whose names are longer or equal to 100 characters without deleting files shorter than 100 characters?

3
  • 1
    can you please clarify your question? are you talking about 100 characters or 100 units of size? what folders did it create these files in? etc.
    – mael'
    Commented Jul 3, 2019 at 14:42
  • I assume it's a file name that's like "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore.txt" (as a length). Do they have a common extension? Commented Jul 3, 2019 at 14:49
  • I'm talking about 100 characters. The extension is ".log". I edited the question above
    – 0xabc
    Commented Jul 3, 2019 at 19:24

2 Answers 2

1

In PowerShell, if this lists your files:

gci -file -recurse | ?{$_.name.length -gt 100} | select name | ft -Wrap

Then this will delete them:

gci -file -recurse | ?{$_.name.length -gt 100} | remove-item
1
  • this command does the job. PS. i'm new to powershell
    – 0xabc
    Commented Jul 4, 2019 at 16:05
2

Run the below command in PowerShell

ls | where { $_.Name.Length -ge 100 } | rm -WhatIf

ls is one of the aliases for Get-ChildItem and rm is Remove-Item. If the files you want to delete is not in the current folder then put the full path to the folder after ls

After confirming the files are correct remove the -WhatIf part to do the real deletion. If you also want to delete files in subdirectories add -Recurse to ls

2
  • It's comfirming that it want to remove files with filename below 100 characters. I'm doing something wrong?
    – 0xabc
    Commented Jul 3, 2019 at 19:26
  • @prouser135 it'll remove files with filenames longer than or equal to 100 characters. For more than 100 characters use -ge 101 or -gt 100. But I missed the BaseName or Name to get the filename without or with extension
    – phuclv
    Commented Jul 4, 2019 at 2:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .