Rename a line from a text file and then save

Post any Bulk Rename Utility support requirements here. Open to all registered users.

Rename a line from a text file and then save

Postby Zohan » Sat Jul 06, 2019 4:30 am

Hello,

Is it possible for Bulk Rename Command to read and rename a line from a .txt file and then saves it?


The reason is because I have a batch file that writes the path and file name of a newly created file in a folder (it is always one file at a time), which is a temp file for a running download, the line looks like this:

Code: Select all
D:\Temp\53 - Bdownloader_2019-07-02_21-00-21.rar-{ea57c4d9-b2b6-4c74-90f3-0507f0c5e5b6}.dtapart


And then i have another batch file that sends this line to an email, but i want to rename this line first before emailing it by removing these parts: "D:\Temp\" and "-{ea57c4d9-b2b6-4c74-90f3-0507f0c5e5b6}.dtapart"

I think the part after ".rar" always has the same number of random characters including extension which is 47



To simplify it:

1- Download starts, temp file created.
2- A batch file detects temp file, creates a .txt file of filename and path.
3- Another batch file reads line from .txt file and sends to an email.

All i want is to have that line renamed before sending it as i mentioned above.
Zohan
 
Posts: 1
Joined: Sat Jul 06, 2019 4:05 am

Re: Rename a line from a text file and then save

Postby therube » Wed Jul 10, 2019 5:34 pm

Add sed to your script.

Code: Select all
sed  -e  "s/D:\\Temp\\53 - //"  -e  "s/-{.*//"



You'll need sed & its' dependencies; sed-4.2.1-bin.zip, sed-4.2.1-dep.zip.
https://sourceforge.net/projects/gnuwin32/files/sed/4.2.1/


Pull the .exe/.dll files from the /bin/ directories & put them some place convenient (in your path or however you want to handle it).


go.txt:
Code: Select all
D:\Temp\53 - Bdownloader_2019-07-02_21-00-21.rar-{ea57c4d9-b2b6-4c74-90f3-0507f0c5e5b6}.dtapart

Code: Select all
cat.exe (or type)  go.txt  |  sed -e "s/D:\\Temp\\53 - //" -e "s/-{.*//"


Result:
Code: Select all
Bdownloader_2019-07-02_21-00-21.rar
therube
 
Posts: 1317
Joined: Mon Jan 18, 2016 6:23 pm

Re: Rename a line from a text file and then save

Postby dude » Fri Jul 12, 2019 12:56 pm

Zohan wrote:including extension which is 47


So the actual filename is
Code: Select all
D:\Temp\53 - Bdownloader_2019-07-02_21-00-21.rar-{ea57c4d9-b2b6-4c74-90f3-0507f0c5e5b6}.dtapart.47
?

batch file


Code: Select all
@echo off
setlocal

   set NAME=D:\Temp\53 - Bdownloader_2019-07-02_21-00-21.rar-{ea57c4d9-b2b6-4c74-90f3-0507f0c5e5b6}.dtapart.47
   
   echo Old name : "%NAME%"


   setlocal ENABLEDELAYEDEXPANSION


      for /l %%a in (1,1,3) DO for  %%x in ("!NAME!") DO set NAME=%%~nx

   endlocal & set NAME=%NAME%.rar


   echo New name : "%NAME%"
   
endlocal



Output:
Code: Select all
T:\>TEST.cmd
Old name : "D:\Temp\53 - Bdownloader_2019-07-02_21-00-21.rar-{ea57c4d9-b2b6-4c74-90f3-0507f0c5e5b6}.dtapart.47"
New name : "53 - Bdownloader_2019-07-02_21-00-21.rar"

T:\>


therube wrote:You'll need sed & its' dependencies

For a "stand-alone" sed:http://sed.sourceforge.net/grabbag/ssed/

(That's what I use the most)
dude
 


Return to BRU Support