Rename files or directories to generate portable names. Names of directories passed to this function cause them to be traversed recursively.
Either character vector with names of files or directories, or data frame as generate by a previous call of this function.
Logical vector of length 1 that indicates
whether file and directory names should also be converted
to lowercase characters. Has only an effect if
Logical vector of length 1 that
indicates whether directory names should also be modified
when not portable. Has only an effect if
Numeric vector of length 1 that indicates
under which circumstances renaming of files should be
attempted. Has only an effect if
When applied to a vector of path names this function does not actually rename anything but generates a data frame that indicates which files or directories should be renamed to what. This data frame can be inspected by the user prior to doing anything dangerous. Rows can be removed or set to a non-empty value in the ‘Problem’ column, which will cause them to be skipped when passed to the function again. Sorting the data frame in a different way is strongly discouraged, however.
When applied to a data frame as generated by a previous
call of this function, it will conduct the renaming of
files and directories as proposed in this data frame,
subject to the conditions controlled by the
enforce argument. The returned data frame will
indicate in the ‘Problem’ column whether renaming
was attempted and, if so, whether it was successful.
Here ‘Portable Filename’ is used as defined by the
Open Group (see ‘References’ section), i.e.
only ASCII letters, numbers, period,
hyphen-minus and underscore are permitted. To create
portable but reasonably informative names, an attempt is
made to replace non-Latin characters by their Latin
counterparts and these by their ASCII
counterparts. Some modifications from the
sanity.pl script (see ‘References’ section)
are also applied. All remaining special characters get
removed by underscores. For further details see the code.
Data frame with three columns ‘From’, ‘To’ and ‘Problem’, which contain character vectors.
Renaming files or directories may fail for various
reasons. See the documentation of
Markus Goeker, with contributions by Heike Freese and Johannes Sikorski
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
## call 1: generate data frame but never rename tasks <- sanitize() head(tasks) # it may well be that nothing was found ## call 2: use data frame for renaming (if enforce >= 0) result <- sanitize(paths = tasks, enforce = -1) head(result) # additional problems may now be listed ## Not run: ## immediately rename a single file sanitize(sanitize("mydir/file with spaces.txt")) ## immediately rename two entire directories sanitize(sanitize(c("ugly directory", "../bad folder"))) ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.