-2

Here is the file name format. The leading number is the layer and the second number is the material (3D printer).

01118_7.tif,
01118_6.tif,
01118_5.tif,
01118_4.tif,
01118_3.tif,
01118_2.tif,
01118_1.tif,
01118_0.tif

What I need to do is shift the files ending in _1, _4, _6 six places higher. So, 01124_1, 01124_4, 01124_6 while the rest of the files stay the same. I need to do it all the way down to layer 00112_*.

I'd like to do this via a batch file if I can. Was trying to follow a guide but the name format is tripping me up. Basic excel format

dbenham
  • 127,446
  • 28
  • 251
  • 390
  • Welcome to Stack Overflow. Please take the [2-minute tour](http://stackoverflow.com/tour). Moreover, open Help Center and read at least _What topics can I ask about here_? Then you know what we expect from questioners: showing us the code on where you stuck solving the task by yourself and explaining why you fail to complete the task. Sorry, but Stack Overflow is not a free code writing service – JosefZ Mar 31 '16 at 21:33
  • More asking for help on how to format the command. I was looking at this site http://mintywhite.com/windows-7/7maintenance/mass-convert-file-names-windows-batch-file/ but the layer number before the material number is giving excel problems. If I can get one file name example then I can populate the spreadsheet and make the .bat file from there. Just wondering if there are wildcard commands that I don't know that could help with parsing the name of the file. – Mike Is-just Mike Mar 31 '16 at 21:53

2 Answers2

1

I can't tell if you need to modify file names that appear within a text file, or if you need to rename files. Either way, I have a simple solution using one of two hybrid JScript/batch regex utilities:


Modify filenames within a text file using JREPL.BAT:

jrepl "^\d{5}(?=_[146]\.tif)" "lpad(Number($0)+6,'00000')" /i /j /f test.txt /O -


Rename files within the current directory using JREN.BAT:

jren "^\d{5}(?=_[146]\.tif$)" "lpad(Number($0)+6,'00000')" /i /j


Use call jrepl or call jren if you put the command within a batch script.

dbenham
  • 127,446
  • 28
  • 251
  • 390
0

It took me awhile to understand that "shift file names six places higher" really means "add six to file name".

@echo off
setlocal EnableDelayedExpansion

set "numbers=/1/4/6/"
for /F "tokens=1,2 delims=_." %%a in ('dir /B /A-D *.tif') do (
   if "!numbers:/%%b/=!" neq "%numbers%" (
      set "newNum=1%%a+6"
      ECHO ren "%%a_%%b.tif" "!newNum:~1!_%%b.tif"
   )
)

If the names are not in files, but are lines of text placed in a text file, change the 'dir /B /A-D *.tif' command by the name of the text file.

Aacini
  • 65,180
  • 12
  • 72
  • 108