How to Restore a Folder that has Turned into a Package in OS X.
Like all software, macOS is not immune to random bugs or problems. Although rare, folders in macOS can sometimes change from showing regular folders to packages like those used to install new macOS applications. This can also happen on purpose, especially if you are creating new software.
Fortunately, recovering a folder on a Mac is easy when needed. There are several ways to do this, but the easiest is to use the Mac Terminal app. Here’s how to recover a folder on Mac regardless of format.
Restore a folder on a Mac using Terminal
The Mac Finder tries to automatically determine the true purpose of a file or folder so it knows how to handle it properly. If the wrong attributes have been applied to a folder, Finder will treat your folder as a package and prevent you from accessing the files stored inside.
The same will happen if your folder has the wrong extension like .app. For these instructions to work, you need the macOS developer tools Xcode installed, as the getfileinfo and setfile commands are not installed by default on macOS.
- To remove these attributes from macOS folders, open the Terminal application (Launcher Other Terminal) and cd to the directory containing your “broken” folder.
- The root cause of this issue is the has bundle bit, so to check, enter getfileinfo -aB folder in your Terminal application, replacing the folder with the location of the folder you want to check. If the command returns 1, this attribute has been applied to your folder, which means it needs to be removed.
- To remove the has bundle attribute bit from your folder and regain access, enter setfile -a b folder in the Terminal application, replacing the folder with the location of your folder.
- Enter getfileinfo -aB folder (replacing the folder) to then check if the status of the package attribute is present – if 0 is returned, the attribute has been removed.
After removing the has bundle attribute, try to access the folder in the Finder, located as an icon in the Dock or Launcher. If you still can’t access the folder, make sure that your folder doesn’t have an unusual extension attached.
- Find a folder in Finder, right click and click Get Info to download your attribute information.
- This will load a separate window containing additional information about your folder. Click the Name and Extension subcategory to see the “true” name for your folder. If it has a file extension (like .app), remove it and press Enter on your keyboard to save.
- Finder will ask you to confirm if you want to remove the extension from your folder. Click the “Delete” button to confirm.
After removing the extension, your folder should be back to normal in Finder, allowing you to open it normally.
You can also access files and folders from a genuine macOS package (such as a PKG or DMG file). In this case, the easiest way is to extract the content to a new folder.
Extract Mac folders using Terminal
This macOS package comes with a variety of file formats, including PKG and DMG files. The approaches to recovering or extracting folders in these formats differ slightly. If you want to restore folders from the original macOS package files, Terminal allows you to do so.
These methods assume that you are trying to access folders from packed PKG or DMG files. If the files are damaged (or are not real PKG or DMG files), these instructions will not work.
- If you want to restore folders from DMG files, you will need to first mount it as a virtual disk. You can do this by opening Terminal from Launchpad Other Terminal.
- Type hdiutil attach file.dmg, replacing file.dmg with the location and filename of your DMG file, then press Enter to run the command.
- Your DMG folder will be mounted as a folder in the Volumes directory on your macOS drive. To copy the contents of your DMG file to a new macOS folder, enter cp -r / Volumes / File / / Users / Username / Folder, replacing File with the original name of your DMG file and replacing Username / Folder with the location to copy the files.
- Enter hdiutil info to find the drive ID for the mounted DMG file, then type hdiutil detach / dev / drive to detach the DMG file, replacing / dev / drive with the correct device ID.
The contents of your DMG file will be restored to a new folder, ready for your access.
- To extract files and folders from a PKG file to a standard macOS folder, open the Terminal application (Launchpad Other Terminal).
- From there enter pkgutil -expand /location/file.pkg newpkgfolder, replacing /location/file.pkg with the location and filename of your PKG file, and newpkgfolder with the correct folder to extract.
The contents of the PKG package file will be extracted to the location you specified.
Work with MacOS files and folders
If you don’t know how to recover a folder on Mac, please try these methods first. In many cases, you can repair a corrupted macOS folder by fixing the extension or removing certain file attributes. If you have a genuine macOS package file in PKG or DMG format, you can extract its contents using the Terminal application.
However, not all folders can be restored. You should consider backing up your Mac with Time Machine to make sure you can always get your files back even if the folder becomes corrupted or inaccessible in the future.