目录的详细描述

gue*_*tli 2 directory metadata filemanager

我将我的图像存储在这种结构中:

YYYY/MM/DD-foo
Run Code Online (Sandbox Code Playgroud)

-foo 是可选的,是事件的简短描述。

有时我想为这个目录存储一个很长的描述

我认为“您可以将程序 X 用于您的图像”的答案无济于事。

我也想要一个适用于包含文本或音频文件的目录的解决方案。

问题:如何给一个目录一个详细的描述?可以包含换行符和其他字符(如斜杠)的描述?

更新

并且您不能简单地在目录中存储带有描述的文本文件?

是的,我可以做到这一点。但我认为已经有一个约定或规范。

我很想在鹦鹉螺中看到这个:

  • 01-short-directory-name,长而冗长的文本,
  • 02-short-directory-name,长而冗长的Text2,
  • ...

我自己找不到目录的元数据规范。

需要的功能

  • 使用rsynctar、 dropbox 或 owncloud备份应该可以工作。
  • 文本应允许包含任何 unicode 字符。
  • 任意键值映射(如json)
  • 通用解决方案,而不是自制的脚本黑客。

Ser*_*nyy 5

Rinzwind 已经说明了为什么在文件名和目录名中不希望使用斜杠和其他特殊字符的原因。我的回答通过 Nautilus 脚本提供了一个简单的解决方法。

介绍

以下脚本依赖.directory_description于每个目录中文件的存在(注意前导点)。如果该文件不存在,将提示用户创建一个。

这种方法的优点是:

  1. 使用简单:.directory_description只是文本文件,因此可以通过文本编辑器轻松编辑。它只是右键单击操作,因此即使是非技术用户也可以使用它。

  2. 描述是目录的一部分,所以当正确备份目录(包括所有文件,包括点文件)时,描述也会被备份。

获取脚本

该脚本可作为我的github 存储库的一部分以及以下内容。对于已经git安装的用户,请在终端中使用以下步骤。

  1. cd ~/.local/share/nautilus/scripts
  2. git clone https://github.com/SergKolo/nautilus_scripts

没有的人请git按照以下步骤操作:

  1. 直接从这个答案复制源代码。
  2. 将代码保存为~/.local/share/nautius/scripts/read_dir_description.py文件。
  3. 确保它是可执行的 chmod +x ~/.local/share/nautius/scripts/read_dir_description.py

现在,每次右键单击目录并转到scripts菜单时,您都可以read_dir_description.py在该目录上运行。

脚本源代码:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Author: Serg Kolo
Date: Aug 16,2016
Written for: http://askubuntu.com/q/809925/295286
"""
import subprocess
import sys
import os.path

def display_file(textfile):
    """ Displays file containing
        directory description if 
        the file exists
    """
    subprocess.call([
                    'zenity', 
                    '--text-info', 
                    '--filename=' + textfile
                    ])

def create_file(textfile):
    """ Creates text file containing
        directory description
        if the description doesn't exist
    """
    try:
        err_text = '"This directory doesn\'t have description.' +\
                   'Would you like to create one now?"'
        subprocess.check_call([
                              'zenity',
                              '--error',
                              '--text=' + err_text
                              ])
    except subprocess.CalledProcessError:
        sys.exit()

    # ensure we create the file
    with open(textfile,'w') as text:
        text.write('')                

    try:
         
        output = subprocess.check_output([
                           'zenity', 
                           '--text-info', 
                           '--editable',
                           '--filename=' + textfile
                           ])
    except subprocess.CalledProcessError:
        sys.exit()

    with open(textfile,'w') as text:
        text.write(output.decode())
                              


def main():

    file_name = '.directory_description'
    directory = os.path.abspath(sys.argv[1])
    file_path = os.path.join(directory, file_name)
    
    if os.path.isfile(file_path):
        display_file(file_path)
    else:
        create_file(file_path )

if __name__ == '__main__':
    main()
Run Code Online (Sandbox Code Playgroud)

行动中的脚本

通过右键单击访问脚本

在此处输入图片说明


通知描述不存在的对话框

在此处输入图片说明


示例目录说明

在此处输入图片说明