renaming files with text file contents

Discuss and share scripts and script files...
Post Reply
kotlmg
Posts: 298
Joined: 30 Jun 2010 17:14

renaming files with text file contents

Post by kotlmg »

hello sir,
i want to rename only all file names not extensions in the folder with text file containg names.

example : folder has files unnamed.mp4, unnamed 1.mp4 and unnamed 3.mp4

text file has contents as
grammar usage
verb basics
all about modals


is it possible with script?

kotlmg
Posts: 298
Joined: 30 Jun 2010 17:14

Re: renaming files with text file contents

Post by kotlmg »

files should be named in chronological order.

after execution of script, file names should be

grammar usage.mp4
verb basics.mp4
all about modals.mp4

bdeshi
Posts: 4249
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612 / Dhaka
Contact:

Re: renaming files with text file contents

Post by bdeshi »

Code: Select all

  $txt = inputfile(<curpath>,, "Select file with expected filenames");
  $dir = inputfolder(<curpath>, "Select folder with files to rename");
  tab("new", "$dir");
  sortby "m", "a"; //sort by modified, descending
  $names = replace(formatlist(readfile($txt), 'et', <crlf>), <crlf>, "|");
  $items = listpane('a', "*.mp4", 1+4, "|");
  rename "l", $names, "p", $items;
  
Try this script.
It asks you to first select a txt file containing expected file names per line, and then to select the folder that contains the mp4 files.
then it opens a tab to that folder, sorts files by Modified, Ascending, (ie, the lastest modified file is at the bottom), and renames serially according to the txt content. You will get a prompt before the rename is applied.

To sort descending (so that latest files are at the top), change the "a" in sortby "m", "a"; to a "d".
To sort by created date instead of modified, change the "m" in sortby "m", "a"; to a "c".

No validation is done on the text content. You should make sure the text file only contains valid file names without duplication or other issues.
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

yuyu
Posts: 114
Joined: 19 Jun 2018 12:40

Re: renaming files with text file contents

Post by yuyu »

This can be done also without scripting.
Sort your files chronologically and select them.
Then File>Rename Special>Edit Item Names... and paste text file contents to the box. Rename.
After that: File>Rename Special>Set Extension... mp4.

kotlmg
Posts: 298
Joined: 30 Jun 2010 17:14

Re: renaming files with text file contents

Post by kotlmg »

thanks a lot. both the code and non script solutions are working fine.

Post Reply