简体   繁体   English

如何从objective-c或终端创建文件夹的.dmg?

[英]How to create .dmg of a folder from objective-c or terminal?

Scenario 脚本

I need to convert a folder to .dmg using objective-c however, I am not able find any script in obj-c that is why I am looking for a terminal command that can do this. 我需要使用objective-c将文件夹转换为.dmg但是,我无法在obj-c中找到任何脚本,这就是为什么我正在寻找可以执行此操作的终端命令。

Research 研究

I am using the given below terminal command in order to convert a folder to .dmg 我使用下面给出的终端命令将文件夹转换为.dmg

hdiutil create -format UDZO -srcfolder 
"/Users/Paxcel/Desktop/IMG" 
"/Users/Paxcel/Desktop/IMG.dmg"

Problem 问题

The above command is not working and giving no result as shown in the screenshot given below: 上面的命令不起作用,没有给出结果,如下面的截图所示: 在此输入图像描述

Please suggest a solution that can help me create a .dmg file of a folder. 请建议一个可以帮助我创建文件夹的.dmg文件的解决方案。 Many thanks for your attention. 非常感谢您的关注。

PS: I have to use either obj-c or terminal because I am creating an utility in cocoa app. PS:我必须使用obj-c或终端,因为我在cocoa app中创建了一个实用程序。

Using " was a mistake. I am from windows world and there (in windows) you always have to put a path into quotes "c://test.txt" 使用是一个错误。我来自Windows世界,在那里(在Windows中)你总是要把路径放到引号”c://test.txt“

Earlier ( Wrong ) 早些时候( 错了

hdiutil create -format UDZO -srcfolder 
"/Users/Paxcel/Desktop/IMG" 
"/Users/Paxcel/Desktop/IMG.dmg"

Correct 正确

hdiutil create -format UDZO -srcfolder 
/Users/Paxcel/Desktop/IMG
/Users/Paxcel/Desktop/IMG.dmg

However if you path contains spaces then if you use quotes then it will give an error like given below 但是,如果您的路径包含空格,那么如果您使用引号,那么它将给出如下所示的错误 在此输入图像描述

Resolution In order to escape the error you must use '\\' before spaces ' ' as given below: 解决方案为了避免错误,你必须在空格''之前使用'\\',如下所示:

hdiutil create -format UDZO -srcfolder 
/Users/Paxcel/Desktop/IMG\ for\ design
/Users/Paxcel/Desktop/IMG\ for\ design.dmg

I have run both commands and the result is shown in the screen shot given below Quoted path is not working but using '\\' in path is working like a charm 我已经运行了两个命令,结果显示在下面给出的屏幕截图中引用路径不起作用但在路径中使用'\\'就像一个魅力 在此输入图像描述

You have a stray " in your command line. 你有一个流浪"在你的命令行。

The > prompt means more please ; >提示意味着更多请 ; the shell wants you to terminate the " . shell希望你终止"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM