unitize_dirs: Put files with the same unit measurements into directories

unitize_dirsR Documentation

Put files with the same unit measurements into directories

Description

Say you have a number of files with "5min" in their names, number with "10min" in the names, a number with "15min" in their names and so on, and you'd like to put them into directories named "5min", "10min", "15min" and so on. This function does this, but not just for the unit "min", for any unit.

Usage

unitize_dirs(unit, pattern = NULL, dir = ".")

Arguments

unit

The unit upon which to base the categorizing.

pattern

If set, only files with names matching this pattern will be treated.

dir

In which directory do you want to perform this action (defaults to current)?

Details

This function takes the number to be the last number (as defined in nth_number()) before the first occurrence of the unit name. There is the option to only treat files matching a certain pattern.

Value

Invisibly TRUE if the operation is successful, if not there will be an error.

Examples

## Not run: 
dir.create("UnitDirs_test")
setwd("UnitDirs_test")
files <- c("1litres_1.txt", "1litres_3.txt", "3litres.txt", "5litres_1.txt")
file.create(files)
unitize_dirs("litres", "\\.txt")
setwd("..")
dir.remove("UnitDirs_test")

## End(Not run)

filesstrings documentation built on May 29, 2024, 3:32 a.m.