本文简要介绍ruby语言中 FileUtils模块
的用法。
fileutils.rb
版权所有 © 2000-2007 Minero Aoki
该程序是免费软件。您可以在与 ruby 相同的条款下分发/修改此程序。
模块 FileUtils
用于复制、移动、删除等的几种文件实用方法的命名空间。
Module
函数
require 'fileutils'
FileUtils.cd(dir, **options)
FileUtils.cd(dir, **options) {|dir| block }
FileUtils.pwd()
FileUtils.mkdir(dir, **options)
FileUtils.mkdir(list, **options)
FileUtils.mkdir_p(dir, **options)
FileUtils.mkdir_p(list, **options)
FileUtils.rmdir(dir, **options)
FileUtils.rmdir(list, **options)
FileUtils.ln(target, link, **options)
FileUtils.ln(targets, dir, **options)
FileUtils.ln_s(target, link, **options)
FileUtils.ln_s(targets, dir, **options)
FileUtils.ln_sf(target, link, **options)
FileUtils.cp(src, dest, **options)
FileUtils.cp(list, dir, **options)
FileUtils.cp_r(src, dest, **options)
FileUtils.cp_r(list, dir, **options)
FileUtils.mv(src, dest, **options)
FileUtils.mv(list, dir, **options)
FileUtils.rm(list, **options)
FileUtils.rm_r(list, **options)
FileUtils.rm_rf(list, **options)
FileUtils.install(src, dest, **options)
FileUtils.chmod(mode, list, **options)
FileUtils.chmod_R(mode, list, **options)
FileUtils.chown(user, group, list, **options)
FileUtils.chown_R(user, group, list, **options)
FileUtils.touch(list, **options)
可能的 options
是:
:force
-
强制操作(如果存在则重写文件,如果不为空则删除目录等);
:verbose
-
在执行之前以 bash 语法打印要运行的命令;
:preserve
-
在复制时保留对象的组、用户和修改时间;
:noop
-
没有进行任何更改(可与
:verbose
结合使用,它将打印要运行的命令)
每种方法都记录了它所遵循的选项。另请参阅 ::commands
、 ::options
和 ::options_of
方法来检查哪个命令具有哪些选项。
所有具有“source” 文件或目录概念的方法都可以在该参数中采用一个文件或文件列表。有关示例,请参阅方法文档。
有一些“低级”方法不接受关键字参数:
FileUtils.copy_entry(src, dest, preserve = false, dereference_root = false, remove_destination = false)
FileUtils.copy_file(src, dest, preserve = false, dereference = true)
FileUtils.copy_stream(srcstream, deststream)
FileUtils.remove_entry(path, force = false)
FileUtils.remove_entry_secure(path, force = false)
FileUtils.remove_file(path, force = false)
FileUtils.compare_file(path_a, path_b)
FileUtils.compare_stream(stream_a, stream_b)
FileUtils.uptodate?(file, cmp_list)
模块 FileUtils::Verbose
该模块具有 FileUtils
模块的所有方法,但它在执行之前输出消息。这相当于将 :verbose
标志传递给 FileUtils
中的方法。
模块 FileUtils::NoWrite
该模块具有 FileUtils
模块的所有方法,但从不更改文件/目录。这相当于将 :noop
标志传递给 FileUtils
中的方法。
模块 FileUtils::DryRun
该模块具有 FileUtils
模块的所有方法,但从不更改文件/目录。这相当于将 :noop
和 :verbose
标志传递给 FileUtils
中的方法。
相关用法
- Ruby FileUtils.mkdir用法及代码示例
- Ruby FileUtils.compare_file用法及代码示例
- Ruby FileUtils.options_of用法及代码示例
- Ruby FileUtils.ln_s用法及代码示例
- Ruby FileUtils.install用法及代码示例
- Ruby FileUtils.chown_R用法及代码示例
- Ruby FileUtils.cp_lr用法及代码示例
- Ruby FileUtils.rmdir用法及代码示例
- Ruby FileUtils.rm_rf用法及代码示例
- Ruby FileUtils.collect_method用法及代码示例
- Ruby FileUtils.commands用法及代码示例
- Ruby FileUtils.mv用法及代码示例
- Ruby FileUtils.have_option?用法及代码示例
- Ruby FileUtils.mkdir_p用法及代码示例
- Ruby FileUtils.cd用法及代码示例
- Ruby FileUtils.cp用法及代码示例
- Ruby FileUtils.chmod_R用法及代码示例
- Ruby FileUtils.rm_f用法及代码示例
- Ruby FileUtils.rm_r用法及代码示例
- Ruby FileUtils.chmod用法及代码示例
- Ruby FileUtils.cp_r用法及代码示例
- Ruby FileUtils.ln用法及代码示例
- Ruby FileUtils.options用法及代码示例
- Ruby FileUtils.chown用法及代码示例
- Ruby FileUtils.ln_sf用法及代码示例
注:本文由纯净天空筛选整理自ruby-lang.org大神的英文原创作品 FileUtils模块。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。