Batch to copy and rename files based on a textlist

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
rjarvinen
Posts: 1
Joined: 03 Oct 2017 01:58

Batch to copy and rename files based on a textlist

#1 Post by rjarvinen » 03 Oct 2017 02:36

Hi!

I know a bit of coding but not that much that I could do the following.. I wonder could anyone here help me out with this? I have googled around but not found solution to this specific case.

I have lots of songs on a network drive. I also have a list of songs in a textfile in a specific order starting from 1 and ending up to number 40.
What I would like to is:
Check the first song in the textfile if it exists on a specified folder, copy it to a specified location and give it a prefix 01 + original filename.
Check the second song in the textfile if it exists on a specified folder, copy it to a specified location and give it a prefix 02 + original filename.
...and so on through the whole list.

Script should skip a song if it doesn't exist, and also that song number. For example: if song number 3 on the list doesn't exist, next song should get number 04 prefix as in the list.
Is it also possible to somehow eliminate special characters because they could cause errors? And also file extensions because a song could be .wav or .mp3
What I mean is, if I have a song called "John Parr-St. Elmo's Fire (Live).wav" the script ignores " - " and " ' " and " . " -charcters, because the song could be spelled also like this "John Parr - St Elmos Fire (Live).mp3"
Is this something one can do with Dos, or do I need to look somewhere else..?

And help or pointing to right direction will be greatly appreciated!

//reynolds


By the way, I have this, but this don't rename or check filenames, it just copies exactly what is in the list:

@echo off
set Source=R:\song source
set Target=R:\song target
set FileList=R:\songlist.txt
echo.

if not exist "%Source%" echo Source folder "%Source%" not found & goto Exit
if not exist "%FileList%" echo File list "%FileList%" not found & goto Exit
if not exist "%Target%" md "%Target%"

for /F "delims=" %%a in ('type "%FileList%"') do copy "%Source%\%%a" "%Target%"

:Exit
echo.
echo press the Space Bar to close this window.
pause > nul

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Batch to copy and rename files based on a textlist

#2 Post by aGerman » 03 Oct 2017 05:36

rjarvinen wrote:Is it also possible to somehow eliminate special characters because they could cause errors? And also file extensions because a song could be .wav or .mp3
What I mean is, if I have a song called "John Parr-St. Elmo's Fire (Live).wav" the script ignores " - " and " ' " and " . " -charcters, because the song could be spelled also like this "John Parr - St Elmos Fire (Live).mp3"

This needs some further clarification. Does it mean it could happen you have "John Parr-St. Elmo's Fire (Live).wav" in your list file but the audio file in your source folder is named "John Parr - St Elmos Fire (Live).mp3"?

Steffen

Post Reply