Computer Hope

Microsoft => Microsoft DOS => Topic started by: znagyznagy on January 17, 2017, 06:30:52 AM

Title: Changing the characters of all the filenames in a folder (batch file)
Post by: znagyznagy on January 17, 2017, 06:30:52 AM
Hi,

I am new here. It is very seldom that I write MD DOS .bat files, it is mainly due to move files from my Garmin and other sport gadgets as USB mass storage devices, rename the filename and parse them into different directiories. So far I could solve all the issues using hints found on stackoverflow, dostips, superuser etc. To be honest I did not always understand what all the DOS commands exactly did, but with a trial and error approach I always succeeded finally. BTW I have Windows 7.

But this time I totally failed, I tried to code it using different hints, I tried it at least thrice, but always got confused, which showed me how tough to do something without a sound base.

My problem is the next.

I have some *.fit files in a folder. All the filenames have the same length and the same logics. 8 characters long, 1st character: year, 2nd: month, 3rd: day, 4th: hour, 5th and 6th minutes, and 7th and 8th seconds. So it is a timestamp. 1-4 characters are numbers or letters.

Year: 7 means 2017, 8 is 2018, 9 is 2019, A is 2020 etc
Month: 1: Jan, ...., 9:Sep, A: Oct, B: Nov, C: Dec.
Day: similarly where 1 is 1st, ..., U is 30th and V is 31st.

I want to change all the filenames in a way that I would not have to decode all these letters in my mind to get the timestamp. So my algorithm would be.

Example: 6CUB4415.fit

1. Read the first filename in the directory.
2. Get the first character
3. Replace it in a way that the first 4 character of the new filename would be 2016, 2017 etc. Note: let's simplify, it is just simple insertion of "201", thus I do not care with they years 2020 and on
4. Get the 2nd char
5. Insert a 0, if it is between 1 and 9, replace it with 10, 11, 12 if it is A, B or C, respectively
6. Get the 3rd char
7. The next part of the new filename would be similarly 01, 02, ...., 30, or 31, so either an insertion of 0 or replacement.
8. Get the 4th char
9. The next part of the new filename would be similarly, 00, 01, ..., 22 or 23.
10. Get the 5-8th chars and concatenate them with the new first 8 characters but putting a "-" between them. And concatenate ".fit" at the end.
11. Replace the old filename with this new filename string.
That is "6CUB4415.fit" would be "20161230-114415.fit"
12. Read the filename of the next file etc

I am not a genius of programming in MSDOS so I thought  I had to use lots of "if" command to examine characters and replace them, but know that this task may be done with some array approach. Provided it exists in MSDOS in a suitable form.

 Can you help me with this problem, please?

Sidenote: I have written 2-3 programs in Freepascal (Lazarus), but since there is an existing MS DOS batch file which already works for the other file manipulation tasks I do not want to re-code the whole problem in pascal.

I copy here the contents of .bat as it is today before solving my problem. Just to show I am not a lazy guy begging for help, but somebody who really tried and failed. As you may spot easily I'd like to rename Fenix3HR filenames. Their names start 6, 7, 8, etc while the similar .fit files of 910XT always start with ", because 910XT names the files like 20170117-141922. Right now I just simply put a "Fenix3HR" string in the beginning of the filename.

@echo off

REM CYCLEOPS JOULE GPS
MOVE "C:\Users\APU\Documents\TrainingPeaks\WKO\Data\Z N\Copy*.pwx" "D:\sport activities data\temporary" 2>nul
pushd "D:\sport activities data\temporary\"
setlocal enabledelayedexpansion
for %%a in ("Copy*.pwx") do (
  set "fn=%%a"
  ren "%%a" "!fn:~12!"
)
pushd "D:\sport activities data\temporary"
set strPrefix=JouleGPS_
set fname=2*.pwx
for %%f in (%fname%) DO ren "%%f" "%strPrefix%%%f"

REM GARMIN EDGE 705
MOVE F:\Garmin\History\*.tcx "D:\sport activities data\temporary" 2>nul
MOVE G:\Garmin\History\*.tcx "D:\sport activities data\temporary" 2>nul
MOVE H:\Garmin\History\*.tcx "D:\sport activities data\temporary" 2>nul
MOVE I:\Garmin\History\*.tcx "D:\sport activities data\temporary" 2>nul
pushd "D:\sport activities data\temporary"
set strPrefix=Edge705_
set fname=2*.tcx
for %%f in (%fname%) DO ren "%%f" "%strPrefix%%%f"

REM GARMIN FORERUNNER 310XT
pushd C:\Users\APU\AppData\Roaming\GARMIN\Devices\3852978072\Activities\
ren *.fit ???????????????.fit
set strPrefix=310XT_
set fname=2*.fit
for %%f in (%fname%) DO ren "%%f" "%strPrefix%%%f"
MOVE C:\Users\APU\AppData\Roaming\GARMIN\Devices\3852978072\Activities\*.fit "D:\sport activities data\temporary" 2>nul
pushd C:\Users\APU\AppData\Roaming\GARMIN\Devices\3852978072\History\
set strPrefix=310XT_
set fname=2*.tcx
for %%f in (%fname%) DO ren "%%f" "%strPrefix%%%f"
REM MOVE C:\Users\APU\AppData\Roaming\GARMIN\Devices\3852978072\History\*.tcx "D:\sport activities data\temporary" 2>nul

REM GARMIN FORERUNNER 910XT
pushd C:\Users\APU\AppData\Roaming\GARMIN\Devices\3881636688\Activities\
ren *.fit ???????????????.fit                       
set strPrefix=910XT_USA_
set fname=2*.fit
for %%f in (%fname%) DO ren "%%f" "%strPrefix%%%f"
MOVE C:\Users\APU\AppData\Roaming\GARMIN\Devices\3881636688\Activities\*.fit "D:\sport activities data\temporary" 2>nul
pushd C:\Users\APU\AppData\Roaming\GARMIN\Devices\3881636688\History\
set strPrefix=910XT_USA_
set fname=2*.tcx
for %%f in (%fname%) DO ren "%%f" "%strPrefix%%%f"
REM MOVE C:\Users\APU\AppData\Roaming\GARMIN\Devices\3881636688\History\*.tcx "D:\sport activities data\temporary" 2>nul

REM GARMIN Fenix 3 HR
MOVE F:\GARMIN\ACTIVITY\*.fit "D:\sport activities data\temporary" 2>nul
MOVE G:\GARMIN\ACTIVITY\*.fit "D:\sport activities data\temporary" 2>nul
MOVE H:\GARMIN\ACTIVITY\*.fit "D:\sport activities data\temporary" 2>nul
MOVE I:\GARMIN\ACTIVITY\*.fit "D:\sport activities data\temporary" 2>nul
pushd "D:\sport activities data\temporary"
set strPrefix=Fenix3HR_
set fname=6*.fit
for %%f in (%fname%) DO ren "%%f" "%strPrefix%%%f"
set fname=7*.fit
for %%f in (%fname%) DO ren "%%f" "%strPrefix%%%f"
set fname=8*.fit
for %%f in (%fname%) DO ren "%%f" "%strPrefix%%%f"
set fname=9*.fit
for %%f in (%fname%) DO ren "%%f" "%strPrefix%%%f"


REM GARMIN GPSMAP 60CSX
MOVE F:\*.gpx "D:\sport activities data\temporary" 2>nul
MOVE G:\*.gpx "D:\sport activities data\temporary" 2>nul
MOVE H:\*.gpx "D:\sport activities data\temporary" 2>nul
MOVE I:\*.gpx "D:\sport activities data\temporary" 2>nul
pushd "D:\sport activities data\temporary"
set strPrefix=60csx_
set fname=2*.gpx
for %%f in (%fname%) DO ren "%%f" "%strPrefix%%%f"


REM iBIKE NEWTON+
pushd "D:\sport activities data\temporary"
set strPrefix=Newton+_
set fname=2*.ibr
for %%f in (%fname%) DO ren "%%f" "%strPrefix%%%f"
pushd "D:\sport activities data\temporary\CSV export copies"
set strPrefix=Newton+_
set fname=2*.csv
for %%f in (%fname%) DO ren "%%f" "%strPrefix%%%f"


REM TACX BUSHIDO
pushd "D:\sport activities data\temporary"
set strPrefix=Bushido_
set fname=2*.hrm
for %%f in (%fname%) DO ren "%%f" "%strPrefix%%%f"


PAUSE


Sorry for writing so much. I would really appreciate any help.
Title: Re: Changing the characters of all the filenames in a folder (batch file)
Post by: Geek-9pm on January 17, 2017, 10:28:30 AM
Does it have to e DOS batch?
 Using any of the other script languages might make it easer.
Is there any other computer language you like to use?
A common practice is to use VB Script and  invoke it from the command line.
Just asking.
Title: Re: Changing the characters of all the filenames in a folder (batch file)
Post by: znagyznagy on January 17, 2017, 03:16:48 PM
As I wrote I have some knowledge on Pascal, but to be honest am reluctant to re-install Lazarus and its whole environment to my laptop again.

What I do need is just to click on an icon of quick launch bar and the invoked program should run and do its duties. But I am open to any solutions. I just want to avoid a situation when half of the procedure is in the .bat file already in place and half of it in another program.
Title: Re: Changing the characters of all the filenames in a folder (batch file)
Post by: znagyznagy on January 22, 2017, 12:42:23 AM
So all of you think there is no way to implement my idea?
Title: Re: Changing the characters of all the filenames in a folder (batch file)
Post by: Squashman on January 22, 2017, 05:10:38 PM
Sounds like simple substring selection and string replacement. What are you having problems with? You have a pretty long question and I must say that when questions get that long winded I tend to lose interest because I can't keep track of everything you are trying to do. Maybe you could break it down and tackle one problem at a time.
Title: Re: Changing the characters of all the filenames in a folder (batch file)
Post by: Geek-9pm on January 22, 2017, 11:34:20 PM
The key idea is "Simple String Manipulation"
High-level tools like C++ have a set of things that do that.
So does PASCAL.
It is also in old versions of Microsoft GW-BASIC and later.
In QBASIC you have:
ASC
CHR$
INSTR
LEFT$
MID$
RIGHT$
VB Script has similar functions.
If you want to keep it all in BAT, you will need to find gladiatorial on string manipulation for BAT.
BAT is not like the other things.
The CH archives a are goo place to look.
http://www.computerhope.com/forum/index.php?topic=128532.0
Notice that some things only work in a FOR loop.

Yes, batch does work. *censored* is not really like everything else. That is why some  IT people like to make use of other tools available in Windows. Such as Powershell.

Title: Re: Changing the characters of all the filenames in a folder (batch file)
Post by: znagyznagy on February 12, 2017, 03:35:38 PM
ENJOY my brute force approach

REM GARMIN Fenix 3 HR

MOVE F:\GARMIN\ACTIVITY\*.fit "D:\sport activities data\temporary" 2>nul
MOVE G:\GARMIN\ACTIVITY\*.fit "D:\sport activities data\temporary" 2>nul
MOVE H:\GARMIN\ACTIVITY\*.fit "D:\sport activities data\temporary" 2>nul
MOVE I:\GARMIN\ACTIVITY\*.fit "D:\sport activities data\temporary" 2>nul

pushd "D:\sport activities data\temporary"


for %%i in (???0????.fit) do (set fName=%%i) & call :ORA_ATNEVEZ_0
for %%i in (???1????.fit) do (set fName=%%i) & call :ORA_ATNEVEZ_1
for %%i in (???2????.fit) do (set fName=%%i) & call :ORA_ATNEVEZ_2
for %%i in (???3????.fit) do (set fName=%%i) & call :ORA_ATNEVEZ_3
for %%i in (???4????.fit) do (set fName=%%i) & call :ORA_ATNEVEZ_4
for %%i in (???5????.fit) do (set fName=%%i) & call :ORA_ATNEVEZ_5
for %%i in (???6????.fit) do (set fName=%%i) & call :ORA_ATNEVEZ_6
for %%i in (???7????.fit) do (set fName=%%i) & call :ORA_ATNEVEZ_7
for %%i in (???8????.fit) do (set fName=%%i) & call :ORA_ATNEVEZ_8
for %%i in (???9????.fit) do (set fName=%%i) & call :ORA_ATNEVEZ_9
for %%i in (???A????.fit) do (set fName=%%i) & call :ORA_ATNEVEZ_10
for %%i in (???B????.fit) do (set fName=%%i) & call :ORA_ATNEVEZ_11
for %%i in (???C????.fit) do (set fName=%%i) & call :ORA_ATNEVEZ_12
for %%i in (???D????.fit) do (set fName=%%i) & call :ORA_ATNEVEZ_13
for %%i in (???E????.fit) do (set fName=%%i) & call :ORA_ATNEVEZ_14
for %%i in (???F????.fit) do (set fName=%%i) & call :ORA_ATNEVEZ_15
for %%i in (???G????.fit) do (set fName=%%i) & call :ORA_ATNEVEZ_16
for %%i in (???H????.fit) do (set fName=%%i) & call :ORA_ATNEVEZ_17
for %%i in (???I????.fit) do (set fName=%%i) & call :ORA_ATNEVEZ_18
for %%i in (???J????.fit) do (set fName=%%i) & call :ORA_ATNEVEZ_19
for %%i in (???K????.fit) do (set fName=%%i) & call :ORA_ATNEVEZ_20
for %%i in (???L????.fit) do (set fName=%%i) & call :ORA_ATNEVEZ_21
for %%i in (???M????.fit) do (set fName=%%i) & call :ORA_ATNEVEZ_22
for %%i in (???N????.fit) do (set fName=%%i) & call :ORA_ATNEVEZ_23

for %%i in (??1??????.fit) do (set fName=%%i) & call :NAP_ATNEVEZ_1
for %%i in (??2??????.fit) do (set fName=%%i) & call :NAP_ATNEVEZ_2
for %%i in (??3??????.fit) do (set fName=%%i) & call :NAP_ATNEVEZ_3
for %%i in (??4??????.fit) do (set fName=%%i) & call :NAP_ATNEVEZ_4
for %%i in (??5??????.fit) do (set fName=%%i) & call :NAP_ATNEVEZ_5
for %%i in (??6??????.fit) do (set fName=%%i) & call :NAP_ATNEVEZ_6
for %%i in (??7??????.fit) do (set fName=%%i) & call :NAP_ATNEVEZ_7
for %%i in (??8??????.fit) do (set fName=%%i) & call :NAP_ATNEVEZ_8
for %%i in (??9??????.fit) do (set fName=%%i) & call :NAP_ATNEVEZ_9
for %%i in (??A??????.fit) do (set fName=%%i) & call :NAP_ATNEVEZ_10
for %%i in (??B??????.fit) do (set fName=%%i) & call :NAP_ATNEVEZ_11
for %%i in (??C??????.fit) do (set fName=%%i) & call :NAP_ATNEVEZ_12
for %%i in (??D??????.fit) do (set fName=%%i) & call :NAP_ATNEVEZ_13
for %%i in (??E??????.fit) do (set fName=%%i) & call :NAP_ATNEVEZ_14
for %%i in (??F??????.fit) do (set fName=%%i) & call :NAP_ATNEVEZ_15
for %%i in (??G??????.fit) do (set fName=%%i) & call :NAP_ATNEVEZ_16
for %%i in (??H??????.fit) do (set fName=%%i) & call :NAP_ATNEVEZ_17
for %%i in (??I??????.fit) do (set fName=%%i) & call :NAP_ATNEVEZ_18
for %%i in (??J??????.fit) do (set fName=%%i) & call :NAP_ATNEVEZ_19
for %%i in (??K??????.fit) do (set fName=%%i) & call :NAP_ATNEVEZ_20
for %%i in (??L??????.fit) do (set fName=%%i) & call :NAP_ATNEVEZ_21
for %%i in (??M??????.fit) do (set fName=%%i) & call :NAP_ATNEVEZ_22
for %%i in (??N??????.fit) do (set fName=%%i) & call :NAP_ATNEVEZ_23
for %%i in (??O??????.fit) do (set fName=%%i) & call :NAP_ATNEVEZ_24
for %%i in (??P??????.fit) do (set fName=%%i) & call :NAP_ATNEVEZ_25
for %%i in (??Q??????.fit) do (set fName=%%i) & call :NAP_ATNEVEZ_26
for %%i in (??R??????.fit) do (set fName=%%i) & call :NAP_ATNEVEZ_27
for %%i in (??S??????.fit) do (set fName=%%i) & call :NAP_ATNEVEZ_28
for %%i in (??T??????.fit) do (set fName=%%i) & call :NAP_ATNEVEZ_29
for %%i in (??U??????.fit) do (set fName=%%i) & call :NAP_ATNEVEZ_30
for %%i in (??V??????.fit) do (set fName=%%i) & call :NAP_ATNEVEZ_31

for %%i in (?1??????????.fit) do (set fName=%%i) & call :HO_ATNEVEZ_1
for %%i in (?2??????????.fit) do (set fName=%%i) & call :HO_ATNEVEZ_2
for %%i in (?3??????????.fit) do (set fName=%%i) & call :HO_ATNEVEZ_3
for %%i in (?4??????????.fit) do (set fName=%%i) & call :HO_ATNEVEZ_4
for %%i in (?5??????????.fit) do (set fName=%%i) & call :HO_ATNEVEZ_5
for %%i in (?6??????????.fit) do (set fName=%%i) & call :HO_ATNEVEZ_6
for %%i in (?7??????????.fit) do (set fName=%%i) & call :HO_ATNEVEZ_7
for %%i in (?8??????????.fit) do (set fName=%%i) & call :HO_ATNEVEZ_8
for %%i in (?9??????????.fit) do (set fName=%%i) & call :HO_ATNEVEZ_9
for %%i in (?A??????????.fit) do (set fName=%%i) & call :HO_ATNEVEZ_10
for %%i in (?B??????????.fit) do (set fName=%%i) & call :HO_ATNEVEZ_11
for %%i in (?C??????????.fit) do (set fName=%%i) & call :HO_ATNEVEZ_12

for %%i in (6?????????????.fit) do (set fName=%%i) & call :EV_ATNEVEZ_2016
for %%i in (7?????????????.fit) do (set fName=%%i) & call :EV_ATNEVEZ_2017
for %%i in (8?????????????.fit) do (set fName=%%i) & call :EV_ATNEVEZ_2018
for %%i in (9?????????????.fit) do (set fName=%%i) & call :EV_ATNEVEZ_2019
for %%i in (A?????????????.fit) do (set fName=%%i) & call :EV_ATNEVEZ_2020
for %%i in (B?????????????.fit) do (set fName=%%i) & call :EV_ATNEVEZ_2021
for %%i in (C?????????????.fit) do (set fName=%%i) & call :EV_ATNEVEZ_2022
for %%i in (D?????????????.fit) do (set fName=%%i) & call :EV_ATNEVEZ_2023
for %%i in (E?????????????.fit) do (set fName=%%i) & call :EV_ATNEVEZ_2024
for %%i in (F?????????????.fit) do (set fName=%%i) & call :EV_ATNEVEZ_2025
for %%i in (G?????????????.fit) do (set fName=%%i) & call :EV_ATNEVEZ_2026
for %%i in (H?????????????.fit) do (set fName=%%i) & call :EV_ATNEVEZ_2027


set strPrefix=Fenix3HR_
set fname=2*.fit
for %%f in (%fname%) DO ren "%%f" "%strPrefix%%%f"


REM FENIX 3 HR SZUBRUTINOK


:ORA_ATNEVEZ_0
ren %fName% %fName:~0,3%-00%fName:~-8%
goto :EOF

:ORA_ATNEVEZ_1
ren %fName% %fName:~0,3%-01%fName:~-8%
goto :EOF

:ORA_ATNEVEZ_2
ren %fName% %fName:~0,3%-02%fName:~-8%
goto :EOF

:ORA_ATNEVEZ_3
ren %fName% %fName:~0,3%-03%fName:~-8%
goto :EOF

:ORA_ATNEVEZ_4
ren %fName% %fName:~0,3%-04%fName:~-8%
goto :EOF

:ORA_ATNEVEZ_5
ren %fName% %fName:~0,3%-05%fName:~-8%
goto :EOF

:ORA_ATNEVEZ_6
ren %fName% %fName:~0,3%-06%fName:~-8%
goto :EOF

:ORA_ATNEVEZ_7
ren %fName% %fName:~0,3%-07%fName:~-8%
goto :EOF

:ORA_ATNEVEZ_8
ren %fName% %fName:~0,3%-08%fName:~-8%
goto :EOF

:ORA_ATNEVEZ_9
ren %fName% %fName:~0,3%-09%fName:~-8%
goto :EOF

:ORA_ATNEVEZ_10
ren %fName% %fName:~0,3%-10%fName:~-8%
goto :EOF

:ORA_ATNEVEZ_11
ren %fName% %fName:~0,3%-11%fName:~-8%
goto :EOF

:ORA_ATNEVEZ_12
ren %fName% %fName:~0,3%-12%fName:~-8%
goto :EOF

:ORA_ATNEVEZ_13
ren %fName% %fName:~0,3%-13%fName:~-8%
goto :EOF

:ORA_ATNEVEZ_14
ren %fName% %fName:~0,3%-14%fName:~-8%
goto :EOF

:ORA_ATNEVEZ_15
ren %fName% %fName:~0,3%-15%fName:~-8%
goto :EOF

:ORA_ATNEVEZ_16
ren %fName% %fName:~0,3%-16%fName:~-8%
goto :EOF

:ORA_ATNEVEZ_17
ren %fName% %fName:~0,3%-17%fName:~-8%
goto :EOF

:ORA_ATNEVEZ_18
ren %fName% %fName:~0,3%-18%fName:~-8%
goto :EOF

:ORA_ATNEVEZ_19
ren %fName% %fName:~0,3%-19%fName:~-8%
goto :EOF

:ORA_ATNEVEZ_20
ren %fName% %fName:~0,3%-20%fName:~-8%
goto :EOF

:ORA_ATNEVEZ_21
ren %fName% %fName:~0,3%-21%fName:~-8%
goto :EOF

:ORA_ATNEVEZ_22
ren %fName% %fName:~0,3%-22%fName:~-8%
goto :EOF

:ORA_ATNEVEZ_23
ren %fName% %fName:~0,3%-23%fName:~-8%
goto :EOF


:NAP_ATNEVEZ_1
ren %fName% %fName:~0,2%-01%fName:~-11%
goto :EOF

:NAP_ATNEVEZ_2
ren %fName% %fName:~0,2%-02%fName:~-11%
goto :EOF

:NAP_ATNEVEZ_3
ren %fName% %fName:~0,2%-03%fName:~-11%
goto :EOF

:NAP_ATNEVEZ_4
ren %fName% %fName:~0,2%-04%fName:~-11%
goto :EOF

:NAP_ATNEVEZ_5
ren %fName% %fName:~0,2%-05%fName:~-11%
goto :EOF

:NAP_ATNEVEZ_6
ren %fName% %fName:~0,2%-06%fName:~-11%
goto :EOF

:NAP_ATNEVEZ_7
ren %fName% %fName:~0,2%-07%fName:~-11%
goto :EOF

:NAP_ATNEVEZ_8
ren %fName% %fName:~0,2%-08%fName:~-11%
goto :EOF

:NAP_ATNEVEZ_9
ren %fName% %fName:~0,2%-09%fName:~-11%
goto :EOF

:NAP_ATNEVEZ_10
ren %fName% %fName:~0,2%-10%fName:~-11%
goto :EOF

:NAP_ATNEVEZ_11
ren %fName% %fName:~0,2%-11%fName:~-11%
goto :EOF

:NAP_ATNEVEZ_12
ren %fName% %fName:~0,2%-12%fName:~-11%
goto :EOF

:NAP_ATNEVEZ_13
ren %fName% %fName:~0,2%-13%fName:~-11%
goto :EOF

:NAP_ATNEVEZ_14
ren %fName% %fName:~0,2%-14%fName:~-11%
goto :EOF

:NAP_ATNEVEZ_15
ren %fName% %fName:~0,2%-15%fName:~-11%
goto :EOF

:NAP_ATNEVEZ_16
ren %fName% %fName:~0,2%-16%fName:~-11%
goto :EOF

:NAP_ATNEVEZ_17
ren %fName% %fName:~0,2%-17%fName:~-11%
goto :EOF

:NAP_ATNEVEZ_18
ren %fName% %fName:~0,2%-18%fName:~-11%
goto :EOF

:NAP_ATNEVEZ_19
ren %fName% %fName:~0,2%-19%fName:~-11%
goto :EOF

:NAP_ATNEVEZ_20
ren %fName% %fName:~0,2%-20%fName:~-11%
goto :EOF

:NAP_ATNEVEZ_21
ren %fName% %fName:~0,2%-21%fName:~-11%
goto :EOF

:NAP_ATNEVEZ_22
ren %fName% %fName:~0,2%-22%fName:~-11%
goto :EOF

:NAP_ATNEVEZ_23
ren %fName% %fName:~0,2%-23%fName:~-11%
goto :EOF

:NAP_ATNEVEZ_24
ren %fName% %fName:~0,2%-24%fName:~-11%
goto :EOF

:NAP_ATNEVEZ_25
ren %fName% %fName:~0,2%-25%fName:~-11%
goto :EOF

:NAP_ATNEVEZ_26
ren %fName% %fName:~0,2%-26%fName:~-11%
goto :EOF

:NAP_ATNEVEZ_27
ren %fName% %fName:~0,2%-27%fName:~-11%
goto :EOF

:NAP_ATNEVEZ_28
ren %fName% %fName:~0,2%-28%fName:~-11%
goto :EOF

:NAP_ATNEVEZ_29
ren %fName% %fName:~0,2%-29%fName:~-11%
goto :EOF

:NAP_ATNEVEZ_30
ren %fName% %fName:~0,2%-30%fName:~-11%
goto :EOF

:NAP_ATNEVEZ_31
ren %fName% %fName:~0,2%-31%fName:~-11%
goto :EOF


:HO_ATNEVEZ_1
ren %fName% %fName:~0,1%-01%fName:~-14%
goto :EOF

:HO_ATNEVEZ_2
ren %fName% %fName:~0,1%-02%fName:~-14%
goto :EOF

:HO_ATNEVEZ_3
ren %fName% %fName:~0,1%-03%fName:~-14%
goto :EOF

:HO_ATNEVEZ_4
ren %fName% %fName:~0,1%-04%fName:~-14%
goto :EOF

:HO_ATNEVEZ_5
ren %fName% %fName:~0,1%-05%fName:~-14%
goto :EOF

:HO_ATNEVEZ_6
ren %fName% %fName:~0,1%-06%fName:~-14%
goto :EOF

:HO_ATNEVEZ_7
ren %fName% %fName:~0,1%-07%fName:~-14%
goto :EOF

:HO_ATNEVEZ_8
ren %fName% %fName:~0,1%-08%fName:~-14%
goto :EOF

:HO_ATNEVEZ_9
ren %fName% %fName:~0,1%-09%fName:~-14%
goto :EOF

:HO_ATNEVEZ_10
ren %fName% %fName:~0,1%-10%fName:~-14%
goto :EOF

:HO_ATNEVEZ_11
ren %fName% %fName:~0,1%-11%fName:~-14%
goto :EOF

:HO_ATNEVEZ_12
ren %fName% %fName:~0,1%-12%fName:~-14%
goto :EOF

:EV_ATNEVEZ_2016
ren %fName% 2016%fName:~-17%
goto :EOF

:EV_ATNEVEZ_2017
ren %fName% 2017%fName:~-17%
goto :EOF

:EV_ATNEVEZ_2018
ren %fName% 2018%fName:~-17%
goto :EOF

:EV_ATNEVEZ_2019
ren %fName% 2019%fName:~-17%
goto :EOF

:EV_ATNEVEZ_2020
ren %fName% 2020%fName:~-17%
goto :EOF

:EV_ATNEVEZ_2021
ren %fName% 2021%fName:~-17%
goto :EOF

:EV_ATNEVEZ_2022
ren %fName% 2022%fName:~-17%
goto :EOF

:EV_ATNEVEZ_2023
ren %fName% 2023%fName:~-17%
goto :EOF

:EV_ATNEVEZ_2024
ren %fName% 2024%fName:~-17%
goto :EOF

:EV_ATNEVEZ_2025
ren %fName% 2025%fName:~-17%
goto :EOF

:EV_ATNEVEZ_2026
ren %fName% 2026%fName:~-17%
goto :EOF

:EV_ATNEVEZ_2027
ren %fName% 2027%fName:~-17%
goto :EOF


Title: Re: Changing the characters of all the filenames in a folder (batch file)
Post by: Squashman on February 12, 2017, 04:25:20 PM
How about you use the Bulletin Board CODE block feature.
Title: Re: Changing the characters of all the filenames in a folder (batch file)
Post by: patio on February 12, 2017, 04:44:29 PM
 8)
Title: Re: Changing the characters of all the filenames in a folder (batch file)
Post by: Squashman on February 12, 2017, 05:01:19 PM
http://www.thefriendlycoder.com/2011/11/24/batch-file-gotcha-question-mark-wildcard/
Title: Re: Changing the characters of all the filenames in a folder (batch file)
Post by: BeemerBiker on February 14, 2017, 10:53:26 AM
Try this "sample.bat" FWIW  ;)

del 20161230-114415
echo test > 6CUB4415
echo ANS="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" > helpme.vbs
echo arg=Wscript.Arguments.Item(0) >> helpme.vbs
echo Function Chr2Year(Chr) >> helpme.vbs
echo Chr2Year = 2009 + InStr(1,ANS,Chr) >> helpme.vbs
echo End function >> helpme.vbs
echo Function Chr2Any(Chr) >> helpme.vbs
echo Chr2Any = InStr(1,ANS,Chr)-1 >> helpme.vbs
echo if(Len(Chr2Any)^<2) then Chr2Any = "0" ^& Chr2Any >> helpme.vbs
echo End Function >> helpme.vbs
echo Result=Chr2Year(Mid(arg,1,1)) ^& Chr2Any(Mid(arg,2,1)) ^& Chr2Any(Mid(arg,3,1)) ^& "-" ^& Chr2Any(Mid(arg,4,1)) ^& Right(arg,4) >> helpme.vbs
echo WScript.echo Result >> helpme.vbs

for /f "delims=" %%a in ('cscript //nologo helpme.vbs 6CUB4415') do (
set ScriptOut=%%a)
ren 6CUB4415 %ScriptOut%