天天看点

ds_store在写html力的作用,关于“.DS_Store”文件

说明解析

“.DS_Store”文件:DS_Store 是用来存储这个文件夹的显示属性的:比如文件图标的摆放位置。删除以后的副作用就是这些信息的失去。(当然,这点副作用其实不是太大)

“.DS_Store”是Mac OS中 保存文件夹自定义属性的隐藏文件** ,比如:文件的图标位置、视图设置 或 背景色(相当于Windows下的desktop.ini )。

尽管这些文件本来是为Finder所使用,但它们被设想作为一种更通用的有关显示设置的元数据存储,诸如图标位置和视图设置。

例如,在Mac OS X 10.4 "Tiger"中“.DS_Store”包含了一文件夹的所有文件的Spotlight注释。 然而,在Mac OS X 10.5 "Leopard"中这种方式又被更改了,注释(现称为关键字 )被改成存储在了扩展文件属性 中。

让隐藏文件 显示出来的方式,请参考:展示Mac里面Finder的隐藏文件

网站上的“.DS_Store” 文件 处理

若在和别人交换文件(或你做的网页需要上传的时候),应该把 “.DS_Store” 文件删除比较妥当,因为里面包含了一些你不一定希望别人看见的信息(尤其是网站,通过 “.DS_Store” 可以知道这个目录里面所有文件的清单,很多时候这是一个不希望出现的问题)

$filepath = images;

$handle = opendir($filepath);

while (false != ($file = readdir($handle))) {

if ($file != . && $file != .. && $file != .DS_Store && $file != index.html && $file != index.htm && $file != index.php) {

if ($output) $output .= |;

$output .= $file;

closedir($handle);

echo &files=$output&; //输出遍历此文件夹所有的内容

?>

常见的处理:

点击这个网址:http://asepsis.binaryage.com/ ,下载、安装好之后,重启mac。ASEPSIS 会把所有的“.DS_Store” 重定向到 "/usr/local/.dscage"路径

然后可以用以下指令删除mac上所有的“.DS_Store”:

find ~ -name ".DS_Store" -delete

// 或者

find -name ".DS_Store" -delete

对“.DS_store”的 生死操作:

1.禁止 “.DS_store”生成:

打开terminal,复制黏贴下面的命令,回车执行,重启Mac即可生效。

defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool TRUE

2.恢复 “.DS_store”生成:

defaults delete com.apple.desktopservices DSDontWriteNetworkStores

3.删除 所有目录的“.DS_store”文件:

在terminal中输入:

sudo find / -name ".DS_Store" -depth -exec rm {} \;

⭐️:删除 当前目录的“.DS_store”文件

find . -name '*.DS_Store' -type f -delete

项目工程中 处理

而在xcode中,使用 集中式的svn、分布式的git等版本管理工具 进行管理的时候,也会多出一个“.DS_Store”文件(用于存储当前文件夹的一些 Meta 信息)。

而在每次提交代码时,都需要在代码仓库的 “.gitignore”文件 中 声明,忽略这类文件。

⭐️当然有方法可以全局性的忽略:

1.创建 “~/.gitignore_global” 文件,把需要全局忽略的文件类型塞到这个文件里。

# .gitignore_global

####################################

######## OS generated files ########

####################################

.DS_Store

.DS_Store?

*.swp

._*

.Spotlight-V100

.Trashes

Icon?

ehthumbs.db

Thumbs.db

####################################

############# packages #############

####################################

*.7z

*.dmg

*.gz

*.iso

*.jar

*.rar

*.tar

*.zip

2.在自己的 “~/.gitconfig” 中引入 “.gitignore_global”。

“.gitconfig” 文件 🌰:

[user]

name = goyohol

email = [email protected]

[push]

default = matching

[core]

excludesfile = /Users/goyohol/.gitignore_global

搞定之后!在所有的文件夹下 “.DS_Store”、“.swp”、“.zip” 等文件类型会被 Git 自动忽略。

goyohol's essay