ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Main Area and Open Discussion > General Software Discussion

Easy way to rename a file using the contents of a text file in batch or script

<< < (2/2)

4wd:

--- Code: Text ---set /p name=<whose.txtmove /Y photo.jpg %name%.jpg
But if the txt and jpg files have no such matching pattern, like in your whose.txt and photo.jpg example, then I guess the only option is a script that accept two files (the txt and jpg) as input. You'd then manually run that on each txt/jpg pair you have. If you can remember which txt belongs to which jpg that is  ;D-Nod5 (March 13, 2018, 05:54 AM)
--- End quote ---

Given @questorfla's previous requests it's likely to be an automated/timed script that only has to do one thing, (probably something to do with internal website generation), and this is just one step in it.

My guess anyway  :)

questorfla:
Absolutely correct 4WD.  It would be an automatic setup that I would add to another "master housekeeping" routine.  I have a lot of submissions from people that contain the necessary data for a specific job.  Part of this is a text file that contains the name that the final output should use.  Once the first program has it all compiled, it is just named "finished".jpg  The final step is to rename finished to the name of the person t belongs to which is included in their file name.txt.  I was hoping to find a way to use the contexts of the text file to rename the jpg file which , currently, i just go through foldcer by folder for each "finished".jpg and copy the contents of the name.txt file to use for renaming the finished.jpg file.
Tedious but gets the job done.
If i find a better way, i will be sure to post it in case anyone else could ever use as it appears there is a lack of utilities or scripts with that ability. I'm probably the only one who ever asked for one.
Thanks All.

4wd:
I was hoping to find a way to use the contexts of the text file to rename the jpg file ...-questorfla (March 18, 2018, 12:46 PM)
--- End quote ---

It's there:


--- Code: Text ---set /p name=<whose.txtmove /Y photo.jpg %name%.jpg
set reads the contents of the text file into a variable, move renames the file to the variable value with .jpg as the extension.

questorfla:
Everything works BUT I end up with two extra spaces in the filename which i need to avoid if i can.
<edit>  the leading space in the name turned out to be from the text file itself.  a glitch.  The only problem is the center space between the variable and the added text  <edit>

Your code to extract the text file contents into a variable works but for some reason it leaves a leading space in the variable/  At the end,  i need to add the words "menucopy" to that variable without a space between that and original value

the output of the script gets to a file named  "%dmn%menucopy.png"
where %dmn% was the variable created from the text file and "menucopy" is just added text
But i cannot seem to get rid of a leading space added in the variable %dmn% and another one between it and the text "menucopy".

<Edit>  I forgot to setlocal EnableDelayedExpansion before adding the variables.  Problem solved.  Thanks for the input 4wd i needed your code to load the text into variables  <Edit>

I was gettong something like " jimsmith menucopy.png"  :)  Now I get "jimsmithmenucopy.png" !"!!  Perfect

Navigation

[0] Message Index

[*] Previous page

Go to full version