File: fileOps.r

package info (click to toggle)
littler 0.3.22-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 848 kB
  • sloc: ansic: 586; sh: 132; makefile: 5
file content (33 lines) | stat: -rwxr-xr-x 777 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env r
#
# A simple example to do operations on files
#
# Copyright (C) 2014  Dirk Eddelbuettel
#
# Released under GPL (>= 2)

## read files
files <- dir("..", full.names=TRUE)

## creation time as Date
ctimes <- as.Date(file.info(files)$ctime)

## select based on time window -- something arbitrary
now <- Sys.Date()
## these are appromiximative, could be refined using DateTimeClasses
sixmon <- now - 365.25/2
twelvemon <- now - 365.2

ind <- ctimes >= twelvemon & ctimes <= sixmon

if (sum(ind) > 0) {
    cat("The following files are between six and twelve months old\n")
    print(files[ind])
}

## do something
##   print(files[ind])
## or rename / move to subdir
##   mkdir("newDir")
##   file.rename(files[ind], "newDir")
## can also use gsub() etc to rename