none
Find and delete .DS_Store files

    Question

  • I have a 2008 server where some mac clients connect. They create .DS_Store, ._.TemporaryItems and other files that starts with "._".
    I want to find them and delete them every night.
    What kind of script can I run.
    Thank you so much for your help.
    Monday, October 26, 2009 10:23 AM

Answers

  • Hello

    you are trying different commands than i suggested.

    please try the same as i wrote.

    the complete script could be something like this:


    cd c:\
    dir * -include "._*",".DS*" -Recurse -Force | Remove-Item

    the weird thing about get-chilitem (dir) is that when you use the -recurse paramtere, you have to use both the name parameter (position 1), and the include paramter.

    thats why i have the * to get all files (actually it could be "dir -LitheralPath * -include "._*",".DS*" -Recurse -Force") , and then ask's it to include only the files with the names you want , seperated by comma.

    the -name parameter is not for specifing filenames to list.

    good luck :)


    Best Regards
    Jakob Gottlieb Svendsen
    Trainer/Consultant - Coretech A/S - Blog
    MCT - MCTS - VB.NET - C#.NET - Powershell - VBScript
    • Marked as answer by b.bbdo Monday, October 26, 2009 12:40 PM
    Monday, October 26, 2009 12:30 PM
    Moderator

All replies

  • Hello

    i very simple (but maybe not the most fail-safe)

    would be a powershell script that calls this command in the root of each drive, you want to check.


    dir * -include "._*",".DS*" -Recurse | del


    you could call the script from a .bat file, and schedule the bat to be run by the scheduled tasks in control panel.


    Best Regards
    Jakob Gottlieb Svendsen
    Trainer/Consultant - Coretech A/S - Blog
    MCT - MCTS - VB.NET - C#.NET - Powershell - VBScript
    Monday, October 26, 2009 11:42 AM
    Moderator
  • It doesn't work.
    The dir * -include "._*" doesn't show the files.
    If I run this command: Get-ChildItem -force -name "._*" | del
    It tries to delete the files, but I get an 'not enough permissions to perform' but I'm the owner of the files.
    And I'm running powershell as administrator.
    Any other way?
    • Edited by b.bbdo Monday, October 26, 2009 12:04 PM
    Monday, October 26, 2009 11:59 AM
  • It might be because the files are system or hidden??

    try

    dir * -include "._*",".DS*" -Recurse -Force

    instead

    :)

    Best Regards
    Jakob Gottlieb Svendsen
    Trainer/Consultant - Coretech A/S - Blog
    MCT - MCTS - VB.NET - C#.NET - Powershell - VBScript
    Monday, October 26, 2009 12:01 PM
    Moderator
  • I tried this:
    get-ChildItem -force -name ".DS*", "._*" | Remove-Item -force
    And it works, but it doesn't go though directories, then I tried.
    get-ChildItem -force -recurse -name ".DS*", "._*" | Remove-Item -force
    But that doesn't work

    Monday, October 26, 2009 12:24 PM
  • Hello

    you are trying different commands than i suggested.

    please try the same as i wrote.

    the complete script could be something like this:


    cd c:\
    dir * -include "._*",".DS*" -Recurse -Force | Remove-Item

    the weird thing about get-chilitem (dir) is that when you use the -recurse paramtere, you have to use both the name parameter (position 1), and the include paramter.

    thats why i have the * to get all files (actually it could be "dir -LitheralPath * -include "._*",".DS*" -Recurse -Force") , and then ask's it to include only the files with the names you want , seperated by comma.

    the -name parameter is not for specifing filenames to list.

    good luck :)


    Best Regards
    Jakob Gottlieb Svendsen
    Trainer/Consultant - Coretech A/S - Blog
    MCT - MCTS - VB.NET - C#.NET - Powershell - VBScript
    • Marked as answer by b.bbdo Monday, October 26, 2009 12:40 PM
    Monday, October 26, 2009 12:30 PM
    Moderator
  • Thank you so much, it works.
    Cheers
    • Marked as answer by b.bbdo Monday, October 26, 2009 12:39 PM
    • Unmarked as answer by b.bbdo Monday, October 26, 2009 12:40 PM
    Monday, October 26, 2009 12:39 PM
  • I tried this in powershell and get Not enough permission error:

     

    dir * -include "._*",".DS*" -Recurse -Force | Remove-Item

     

    The error can see the files but just gives me the permission issue.  The files are hidden and all are ._somethingname and .ds_store.

     

    Thanks for any help

     

     

     

    Wednesday, June 15, 2011 3:08 AM
  • hello

     

    i must be a permission problem.

     

    1. do you have enough permission to be able to delete the files?

    2. did you start powershell as adminitrator?


    Best Regards
    Jakob Gottlieb Svendsen
    Trainer/Consultant - Coretech A/S - Blog
    MCT - MCTS - VB.NET - C#.NET - Powershell - VBScript
    Wednesday, June 15, 2011 7:31 AM
    Moderator
  • I am running as an admin and I can delete the files in the GUI no problem.  I am new to powershell so maybe I am doing something really silly.

    I have 2 files in a folder located at c:\test  In that folder are 2 files .Ds_store.txt and ._something.text, they are both hidden.  I use powershell to path into that folder, then I run the command and this is what I get:

    Windows PowerShell
    Copyright (C) 2009 Microsoft Corporation. All rights reserved.

    PS C:\Users\hawk2> cd c:/test
    PS C:\test> dir * -include "._*",".DS*" -Recurse -Force | Remove-Item
    Remove-Item : Cannot remove item C:\test\.ds_store.txt: Not Enough permission to perform operation.
    At line:1 char:58
    + dir * -include "._*",".DS*" -Recurse -Force | Remove-Item <<<<
        + CategoryInfo          : PermissionDenied: (C:\test\.ds_store.txt:FileInfo) [Remove-Item], IOException
        + FullyQualifiedErrorId : RemoveFileSystemItemUnAuthorizedAccess,Microsoft.PowerShell.Commands.RemoveItemCommand
    Remove-Item : Cannot remove item C:\test\._something.txt: Not Enough permission to perform operation.
    At line:1 char:58
    + dir * -include "._*",".DS*" -Recurse -Force | Remove-Item <<<<
        + CategoryInfo          : PermissionDenied: (C:\test\._something.txt:FileInfo) [Remove-Item], IOException
        + FullyQualifiedErrorId : RemoveFileSystemItemUnAuthorizedAccess,Microsoft.PowerShell.Commands.RemoveItemCommand
    PS C:\test>

    Wednesday, June 15, 2011 3:48 PM
  • Well, I got the solution to delete hidden .ds and ._ files with the del command:

     

    del /f /s /q /a:H "._*",".ds*"

     

    I have a user that moved from a mac to a PC and she had around 70k files.  This saved me. 

    Wednesday, June 15, 2011 11:39 PM
  • I know this is an old thread, I just came across this problem myself when I was moving my files back to PC from Mac.  Here is the approach I took:

    # Check to see what files are in the directory, you may want to save this to a variable or CS

    ls -Recurse -force | Where-Object {$_.Name -like "._*"} | Select Name, Directory, Length

    # See how many files exist that meet the criteria

    ls -Recurse -force | Where-Object {$_.Name -like "._*"} | Measure-Object

    # Use the -Force switch to get past the permissions restrictions on the hidden files

    ls -Recurse -force | Where-Object {$_.Name -like "._*"} | Remove-Item -Force

    # Rinse and repeat for the .DS Store files

    ls -Recurse -force | Where-Object {$_.Name -like ".DS*"} | Measure-Object

    ls -Recurse -force | Where-Object {$_.Name -like ".DS*"} | Remove-Item -Force

    Sunday, February 09, 2014 11:36 PM