删除超过2周的特定文件夹,但有一些例外

时间:2016-11-28 08:40:19

标签: powershell

我只需要删除特定目录中各种作业文件夹中包含的超过2周的工作区文件夹。

示例:我的根目录C:\DeleteTest包含4个文件夹:

Job1
Job2
Job3
Job4

每个文件夹都包含一个文件列表和一个workspace文件夹。 我需要使用workspace中工作空间文件夹的例外删除超过2周Job2文件夹。

3 个答案:

答案 0 :(得分:0)

Get-ChildItem C:\DeleteTest -Directory -Filter Workspace | % {
  if ($_.Parent.Name -notin $array_of_folders_not_to_be_deleted -and $_.CreationTime -le (Get-Date).Adddays(-14)) {
    Remove-Item $_.FullName -Recurse -Force 
    }
}

请注意,-notin需要完全匹配,因此Job2Job将不匹配。

答案 1 :(得分:0)

我会两次调用 AFHTTPSessionManager *manager = [AFHTTPSessionManager manager]; manager.responseSerializer = [AFJSONResponseSerializer serializer]; [manager GET:@"http://chkdin.com/dev/api/peoplearoundmexy/?" parameters:@{@"skey":@"sa6rw9er7twefc9a7dvcxcheckedin",@"user_id":@"3225"} progress:nil success:^(NSURLSessionTask *task, id responseObject) { NSLog(@"%@",responseObject); } failure:^(NSURLSessionTask *operation, NSError *error) { }]; cmdlet。第一次,检索@Override public boolean onNavigationItemSelected(MenuItem item) { int id = item.getItemId(); switch (id) { R.id.nav_camera: Log.d("MainActivity", "Not null"); break; } } 的所有子文件夹,其中排除了@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.dashboard, menu); return true; } 中的所有文件夹。第二次检索此文件夹中的所有工作区目录并按所需的创建时间过滤它们。最后,使用Get-ChildItem cmdlet删除文件夹:

C:\DeleteTest

答案 2 :(得分:-1)

gci "C:\temp\DeleteTest\Job*\workspace" -directory | 
    ? { $_.FullName -notlike "C:\temp\DeleteTest\Job2\*" -and $_.CreationTime -le (get-date).AddDays(-14)} | 
        Remove-Item -Recurse -Force
相关问题