NiceFileNums

0th

Percentile

Make file numbers comply with alphabetical order

If files are numbered, their numbers may not comply with alphabetical order, i.e. "file2.ext" comes after "file10.ext" in alphabetical order. This function renames the files in the specified directory such that they comply with alphabetical order, so here "file2.ext" would be renamed to "file02.ext".

Usage
NiceFileNums(dir = ".", pattern = NA)
Arguments
dir

Path (relative or absolute) to the directory in which to do the renaming (default is current working directory).

pattern

A regular expression. If specified, files to be renamed are restricted to ones matching this pattern (in their name).

Details

It works on file names with more than one number in them e.g. "file01part3.ext" (a file with 2 numbers). All the file names that it works on must have the same number of numbers, and the non-number bits must be the same. One can limit the renaming to files matching a certain pattern. This function wraps NiceNums(), which does the string operations, but not the renaming. To see examples of how this function works, see the examples in that function's documentation.

Value

A logical vector with a TRUE for each successful rename (should be all TRUEs) and FALSEs otherwise.

Aliases
  • NiceFileNums
Examples
setwd(tempdir())
dir.create("NiceFileNums_test")
setwd("NiceFileNums_test")
files <- c("1litres_1.txt", "1litres_30.txt", "3litres_5.txt")
file.create(files)
NiceFileNums()
NiceFileNums(pattern = "\\.txt$")
setwd("..")
RemoveDirs("NiceFileNums_test")
Documentation reproduced from package filesstrings, version 0.4.0, License: GPL-3

Community examples

Looks like there are no examples yet.