Delete files when the first two characters are ZZ

I want to delete all files when the first two characters are equal to zzor ZZ. How should I do it?

+6
source share
5 answers

Get all objects (including hidden ones, recursively) from a path with names starting with 'zz', filter out catalog objects and delete items.

Get-ChildItem <path> -Recurse -Force -Filter zz* | Where-Object {!$_.PSIsContainer} | Remove-Item
+12
source
get-childitem zz* |
  where-object {$_ -cmatch "^(zz|ZZ)"} |
   foreach-item {remove-item $_.fullname}
0
source

:

Remove-Item zz*
0

-filter. -whatif, , .

get-childitem -recurse -file -filter zz* | remove-item -whatIf
0

NSFileManager * FileManager = [NSFileManager defaultManager]; NSArray * Paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);

//Faccio la dir dei file *.txt da prepare NSDirectoryEnumerator * DirFile = [FileManager enumeratorAtPath: [Paths objectAtIndex: 0]];

IFileTxt = [[NSMutableArray alloc] init]; NSString * file; while ((file = [DirFile nextObject])) {

//In your case you need to test substring = "ZZ"
if ([[file pathExtension] isEqualToString: @"txt"]){ 
    [FileManager removeItemAtPath:[NSString stringWithFormat:@"%@/%@",[Paths objectAtIndex:0],file] error:nil];
}

}

[IFileTxt release];

-1
source

All Articles