Extract text from inside one text file and rename another file using that extracted text

56 Views Asked by At

In my script below I am trying to create a new filename for a step file. I am just not able to get the script to find the revision "0A" in the param_table.txt file.

Below is my script, followed by an example of the Param_table.txt file. The word I am trying to extract from it is 0A.

@ECHO OFF
REM rename_step_files.bat
REM // Retrieve part number from file by skipping the first 3 digits and page number 
FOR %%a IN (c:\step\in\*.stp) DO SET partnumber=%%~na
SET PART_NUMBER=%partnumber:~0,7%
REM // Add ate to filename
set CUR_YYYY=%date:~10,4%
set CUR_MM=%date:~4,2%
set CUR_DD=%date:~7,2%
REM // Find Revsion of step file in parameter text file
SET RevInFile=C:\step\in\param_table.txt
FOR /F "tokens=*" %%B IN ('FINDSTR "REVISION,String" "%RevInFile%" ^| FINDSTR ",No,Full,User-     Defined,,,,"') DO CALL :FindString "%%B"
:FindString
SET Rev=%~1
SET Rev=%String:*REVISION,String=%
SET Rev=%String:No,Full,User-Defined=`%
FOR /F "tokens=1 delims=`" %%B IN ('ECHO.%Rev%') DO ECHO.%%B
REM // Rename file to standard file name
c:\step\in\*.stp %PART_NUMBER%(%rev%)_PRELIM_%DATE%.stp
exit
RELEASED_BY,String,LASTNAME X.,No,Full,User-Defined,,,,
RELEASED_DATE,String,DDD-MMM-YY,No,Full,User-Defined,,,,
REVISION,String,0A,No,Full,User-Defined,,,,
PTC_MASTER_MATERIAL,String,ALUMINUM_2024-T3,No,Full,User-Defined,,OK,,

What I want my script to do is rename the original step file from 'part number'.stp, to 'part number'(rev)_PRELIM_Date.stp

Example 1010001.stp --> 1010001(0A)_PRELIM_2023-05-12.stp

I have tried a few similar explanations on here, but have not found one to work. Any help is much appreciated!

0

There are 0 best solutions below