【问题标题】:Erlang: In erlang shell, How to assign file permissions using write_file_info functionErlang:在 erlang shell 中,如何使用 write_file_info 函数分配文件权限
【发布时间】:2017-03-18 09:43:14
【问题描述】:

我正在尝试使用 erlang shell 将 -rxrxr-x 分配给文件说 file.txt。 但是我们需要在分配给它之前定义一个记录。 而这一切都是我想在 erlang shell 中完成的。

【问题讨论】:

    标签: erlang erlang-shell


    【解决方案1】:

    您可以在 shell 中使用 rr(Module) 从给定模块加载记录定义。有关详细信息,请参阅shell 文档。

    例如:

    1> rr(file).
    [file_descriptor,file_info]
    2> {ok, Info} = file:read_file_info("hello.erl").
    {ok,#file_info{size = 0,type = regular,access = read_write,
               atime = {{2016,11,4},{14,8,35}},
               mtime = {{2016,11,4},{14,8,35}},
               ctime = {{2016,11,4},{14,8,35}},
               mode = 33188,links = 1,major_device = 64512,
               minor_device = 0,inode = 5769215,uid = 1000,gid = 1000}}
    3> Info2 = Info#file_info{ mode = 8#00600 }.
    #file_info{size = 0,type = regular,access = read_write,
               atime = {{2016,11,4},{14,8,35}},
               mtime = {{2016,11,4},{14,8,35}},
               ctime = {{2016,11,4},{14,8,35}},
               mode = 384,links = 1,major_device = 64512,minor_device = 0,
               inode = 5769215,uid = 1000,gid = 1000}
    4> ok = file:write_file_info("hello.erl", Info2).
    

    【讨论】:

    • 谢谢罗杰..我知道..很棒的信息..我现在可以更改文件信息..:)
    猜你喜欢
    • 2018-07-14
    • 2014-02-10
    • 1970-01-01
    • 1970-01-01
    • 2012-12-14
    • 2015-11-13
    • 1970-01-01
    • 2011-01-05
    • 2020-04-05
    相关资源
    最近更新 更多