与所有软件一样,macOS 也无法避免偶尔出现的错误或问题。虽然这种情况很少发生,但 macOS 上的文件夹偶尔会从显示为常规文件夹变为显示为包,例如用于安装新 macOS 应用程序的文件夹。这也可能是设计使然,尤其是在您创建新软件时。
值得庆幸的是,如果需要,在Mac上恢复文件夹是一个简单的过程。有几种方法可以做到这一点,但最简单的方法是使用Mac 终端(Mac Terminal)应用程序。以下是在Mac(Mac)上恢复文件夹的方法,无论格式如何。
使用终端恢复 Mac 上的文件夹(Restore a Folder on Mac Using The Terminal)
Mac Finder 应用程序(Mac Finder app)会尝试自动检测文件或文件夹的真正用途,以便知道如何正确处理它。如果对文件夹应用了错误的属性,那么Finder会将您的文件夹视为一个包,并且不允许您访问其中的文件。
如果您的文件夹具有错误的扩展名,例如.app(.app),它也会执行此操作。要使这些说明生效,您需要安装macOS Xcode 开发人员工具(macOS Xcode Developer Tools),因为默认情况下 macOS 上未安装getfileinfo和setfile命令。(setfile)
- 要从 macOS 文件夹中删除这些属性,请打开终端(Terminal )应用程序(Launchpad > Other > Terminal)并使用cd命令进入包含“损坏”文件夹的目录。
- 此问题的主要原因是has bundle属性位,因此要检查这一点,请在终端(Terminal)应用程序中键入getfileinfo -aB 文件夹(getfileinfo -aB folder),将文件夹替换为您要检查的文件夹的位置。(folder)如果该命令返回1,则该属性已应用于您的文件夹,这意味着它需要被删除。
- 要从文件夹中删除has bundle属性位并恢复访问权限,请在终端应用程序中键入setfile -ab folder ,将(setfile -a b folder)文件夹(folder )替换为您的文件夹位置。
- 键入getfileinfo -aB folder(替换folder)以在此之后检查has bundle属性状态 - 如果返回0,则该属性已被删除。
删除has bundle属性后,尝试访问Finder应用程序中的文件夹,该文件夹位于(Finder)Dock或Launchpad中的图标。如果您仍然无法访问该文件夹,请检查您的文件夹是否没有附加异常扩展名。
- 在Finder(Finder)中找到文件夹,右键单击(right-click)并按Get Info以加载您的属性信息。
- 这将加载一个单独的窗口,其中包含有关您的文件夹的其他信息。单击(Click)名称和扩展(Name & Extension)子类别以查看文件夹的“真实”名称。如果它具有文件扩展名(例如.app),请将其删除并按键盘上的Enter键保存。
- Finder将要求您确认是否要从文件夹中删除扩展名。单击删除(Remove)按钮进行确认。
删除扩展后,您的文件夹应该在Finder(Finder)中恢复正常,让您可以正常打开它。
您可能还想访问正版 macOS 包(如PKG或DMG文件)中的文件和文件夹。如果是这种情况,最简单的方法是将内容提取到新文件夹中。
使用终端提取 Mac 文件夹(Extracting Mac Folders Using The Terminal)
真正的 macOS 软件包有多种文件格式,包括PKG和DMG文件。您如何恢复或提取这些格式的文件夹略有不同。如果您想从真正的 macOS 包文件中恢复文件夹,终端(Terminal)应用程序允许您执行此操作。
这些方法假定您正在尝试从打包的PKG或DMG文件中访问文件夹。如果文件已损坏(或不是真正的PKG或DMG文件),则这些说明将不起作用。
- 如果要从DMG文件中恢复文件夹,则需要先将其挂载为虚拟驱动器。您可以通过从 Launchpad > Other > Terminal终端(Terminal)来做到这一点。
- 键入hdiutil attach file.dmg,将file.dmg替换为(file.dmg)DMG文件的位置和文件名,然后按Enter键运行命令。
- 您的DMG文件夹将作为文件夹安装在 macOS 驱动器上的Volumes目录下。(Volumes)要将DMG文件的内容复制到新的 macOS 文件夹,请键入cp -r /Volumes/File/ /Users/Username/Folder,将File替换为(File)DMG文件的原始名称,并将Username/Folder替换为要复制文件。
- 键入hdiutil info以找到挂载的DMG文件的驱动器标识符,然后键入hdiutil detach /dev/drive以卸载DMG文件,将/dev/drive替换为正确的设备标识符。
您的DMG文件的内容将恢复到一个新文件夹,供您访问。
- 要将文件和文件夹从PKG文件提取到标准 macOS 文件夹,请打开终端(Terminal )应用程序(Launchpad > Other > Terminal)。
- 从那里输入pkgutil -expand /location/file.pkg newpkgfolder,将/location/file.pkg PKG文件的位置和文件名,并将newpkgfolder替换为正确的提取文件夹。
PKG包文件的内容将被提取到您指定的位置。
处理 MacOS 文件和文件夹(Handling MacOS Files & Folders)
如果您不知道如何在Mac上恢复文件夹,请先尝试这些方法。在许多情况下,您可以通过修复扩展名或删除某些文件属性来恢复损坏的 macOS 文件夹。如果您有PKG或DMG格式的正版 macOS 包文件,您可以使用(DMG)终端(Terminal)应用程序提取内容。
但是,并非每个文件夹都可以恢复。您应该考虑使用 Time Machine 备份您的 Mac,(backing up your Mac with Time Machine)以确保您始终可以检索您的文件,即使将来某个文件夹损坏或无法访问。
How to Restore a Folder that has Turned into a Package in OS X
Like all software, macOS isn’t immune to the occаsional bug or problem. While it’s a rare occurrence, folders on mаcOS can occasionally change from apрearing as regular folders to appearing as pаckages, like those used to install new macОS apps. This might also happen by design, especially if you’re creаting new software.
Thankfully, it’s an easy process to restore a folder on a Mac, if you need to. There are a few ways to do this, but the easiest method is to use the Mac Terminal app. Here’s how to restore a folder on Mac, regardless of the format.
Restore a Folder on Mac Using The Terminal
The Mac Finder app tries to automatically detect what a file or folder’s true purpose is so that it knows how to handle it correctly. If the wrong attributes have been applied to the folder, then Finder will treat your folder as a package and won’t allow you to access the files held within.
It’ll also do this if your folder has the wrong extension, like .app. For these instructions to work, you’ll need the macOS Xcode Developer Tools installed, as the getfileinfo and setfile commands aren’t installed on macOS by default.
- To remove these attributes from macOS folders, open the Terminal app (Launchpad > Other > Terminal) and use the cd command to enter the directory containing your “broken” folder.
- The main cause of this problem is the has bundle attribute bit, so to check this, type getfileinfo -aB folder in the Terminal app, replacing the folder with the location of the folder you want to check. If the command returns a 1, this attribute has been applied to your folder, meaning it needs to be removed.
- To remove the has bundle attribute bit from your folder and restore access, type setfile -a b folder in the Terminal app, replacing folder with your folder location.
- Type getfileinfo -aB folder (replacing folder) to check the has bundle attribute status after this—if a 0 is returned, the attribute has been removed.
Once you’ve removed the has bundle attribute, attempt to access the folder in the Finder app, located as an icon on the Dock or in Launchpad. If you still can’t access the folder, check that your folder doesn’t have an unusual extension attached to it.
- Locate the folder in Finder, right-click and press Get Info to load your attribute information.
- This will load a separate window containing additional information on your folder. Click on the Name & Extension sub-category to see the “true” name for your folder. If it has a file extension (for instance, .app), remove it and hit enter on your keyboard to save.
- Finder will ask you to confirm whether you want to remove the extension from your folder. Click the Remove button to confirm.
With the extension removed, your folder should return to normal in Finder, allowing you to open it as normal.
You may also want to access files and folders from a genuine macOS package (like a PKG or DMG file). If that’s the case, the easiest method is to extract the contents into a new folder.
Extracting Mac Folders Using The Terminal
A true macOS package comes in various file formats, including PKG and DMG files. How you approach restoring or extracting folders in these formats differ slightly. If you want to restore folders from genuine macOS package files, the Terminal app allows you to do this.
These methods assume that you’re attempting to access folders from packaged PKG or DMG files. If the files are corrupted (or aren’t true PKG or DMG files), then these instructions won’t work.
- If you want to restore folders from DMG files, you’ll need to mount it as a virtual drive first. You can do that by opening the 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 under the Volumes directory on your macOS drive. To copy the contents of your DMG file to a new macOS folder, type 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.
- Type hdiutil info to locate the drive identifier for your mounted DMG file, then type hdiutil detach /dev/drive to unmount your DMG file, replacing /dev/drive with the correct device identifier.
The contents of your DMG file will be restored to a new folder, ready for you to access.
- To extract files and folders from a PKG file to a standard macOS folder, open the Terminal app (Launchpad > Other > Terminal).
- From there, type pkgutil -expand /location/file.pkg newpkgfolder, replacing /location/file.pkg with the location and filename of your PKG file, and newpkgfolder with the correct extraction folder.
The contents of the PKG package file will be extracted to the location you specified.
Handling MacOS Files & Folders
If you don’t know how to restore a folder on Mac, try these methods first. In many cases, you can restore a broken macOS folder by fixing the extension or removing certain file attributes. If you have a genuine macOS package file in the PKG or DMG formats, you can extract the contents using the Terminal app.
Not every folder can be recovered, however. You should consider backing up your Mac with Time Machine to make sure you can always retrieve your files, even if a folder becomes corrupted or inaccessible in the future.