-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rename_Files.R
37 lines (25 loc) · 949 Bytes
/
Rename_Files.R
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
34
35
36
#!/usr/bin/Rscript
#Rename_Files.R
#rename files matching pattern in specified directory
#Nicholas Clifton
#19 Feb 2020
##################################
# Set the working directory here #
##################################
setwd("~/Documents/Bioinformatics/Matlab/Jack_Peter/C2/")
######################
# Load the filenames #
######################
# This might need changing if there is a different pattern common to all of your files.
# This assumes all your files contain '.tiff'.
old_filenames <- dir(pattern = "*.tif*")
########################
# Adjust the filenames #
########################
# if you want to keep any other special characters, just add them after the '_'
# new_filenames <- gsub("[^[:alnum:]+_]", "", old_filenames)
new_filenames <- gsub("(.*_ome_)(.*).tif", "\\1tiff_\\2_tif.tif", old_filenames)
######################
# Apply to the files #
######################
file.rename(old_filenames, new_filenames)