当前两个字符为 ZZ 时删除文件

发布于 2024-11-17 19:12:35 字数 67 浏览 2 评论 0原文

我想在前两个字符等于 zzZZ 时删除所有文件。我该怎么做呢?

I want to delete all the files when the first two characters are equal to zz or ZZ. How can I do it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

从名称以“zz”开头的路径中获取所有对象(包括隐藏的、递归的),过滤掉目录对象并删除这些项目。

Get-ChildItem <path> -Recurse -Force -Filter zz* | Where-Object {!$_.PSIsContainer} | Remove-Item

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

Get-ChildItem <path> -Recurse -Force -Filter zz* | Where-Object {!$_.PSIsContainer} | Remove-Item
不回头走下去 2024-11-24 19:12:35

这对我有用:

Remove-Item zz*

This works for me:

Remove-Item zz*
2024-11-24 19:12:35
get-childitem zz* |
  where-object {$_ -cmatch "^(zz|ZZ)"} |
   foreach-item {remove-item $_.fullname}
get-childitem zz* |
  where-object {$_ -cmatch "^(zz|ZZ)"} |
   foreach-item {remove-item $_.fullname}
瑾兮 2024-11-24 19:12:35

使用-filter 速度更快。当您确定这就是您想要的时,请去掉“-whatif”。

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

It's faster with -filter. Take off the -whatif when you're sure it's what you want.

get-childitem -recurse -file -filter zz* | remove-item -whatIf
哀由 2024-11-24 19:12:35

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

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

IFileTxt = [[NSMutableArray alloc] init];
NSString *文件;
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 发布];

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

//Faccio la dir dei file *.txt da preparare
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];

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文