I would like to identify files that meet certain string criteria in subdirectories, then rename those files with the final portion of the directory name, 2 directories up ("pd1"?), then I would like to move all of the renamed files to a separate directory.
More detail: say I run the hypothetical code from
/x/y/z directory and in that directory are directories with names like '
20150416_110508_3006'. The files I'm looking to rename are in (example) '
/x/y/z/20150416_110508_3006/dicom', example file name '
o20150416_110508MPRAGESAGs002a1001.nii'. The important elements of the filename needed to differentiate it from like files are the prefix "
o", the '
s002a' in the middle and the extension "
I wanted to rename these files with the final portion of the pd1 directory, in this case '
3006', so '
3006.nii'. Then after doing this for all applicable files, I would like to move the renamed files to a directory in '