Page 1 of 1
Need to write a batch file that moves files based on name
Posted: 28 Jan 2015 03:51
by chbck
My music directory is a mess. I want to write a batch file that will list the files in my "music" folder and move those files to the corresponding folders that bear their name.
For instance: In "music" I have 10 tracks from BandA, 15 tracks from BandB, and 4 tracks from BandC. I will manually create folders called BandA, BandB, and BandC, and I want a batch file that can analyze the list of tracks and move each file to their folders based on the name of the bands.
Any help would be greatly appreciated!
Re: Need to write a batch file that moves files based on nam
Posted: 28 Jan 2015 07:14
by Squashman
Need to see the format of the file names before we could write any script for you.
Re: Need to write a batch file that moves files based on nam
Posted: 28 Jan 2015 08:07
by chbck
Sorry about that.
The filenames would be:
BandA - Song Name 1.mp3
BandA - Song 1.mp3
BandA - Name of song1.mp3
BandB - Name of song2mp3
BandB - Name1.mp3
BandC - Name of song3.mp3
and so on...
Basically, random combinations of things because they are all song titles. But, they all follow the Band Name - Song title.mp3 naming convention.
Re: Need to write a batch file that moves files based on nam
Posted: 29 Jan 2015 08:48
by foxidrive
chbck wrote:Sorry about that.
The filenames would be:
BandA - Song Name 1.mp3
BandA - Song 1.mp3
BandA - Name of song1.mp3
BandB - Name of song2mp3
BandB - Name1.mp3
BandC - Name of song3.mp3
and so on...
Basically, random combinations of things because they are all song titles. But, they all follow the Band Name - Song title.mp3 naming convention.
If BandA B or C contain - characters then the code has to handle that. There are other situations where the names can break the code...
See here:
viewtopic.php?f=3&t=6108
Re: Need to write a batch file that moves files based on nam
Posted: 29 Jan 2015 11:23
by penpen
This may help you (untested):
Code: Select all
@for /D %%a in (*) do @(2>nul move "%%~a*" "%%~a")
penpen
Re: Need to write a batch file that moves files based on nam
Posted: 29 Jan 2015 11:47
by Squashman
penpen wrote:This may help you (untested):
Code: Select all
@for /D %%a in (*) do @(2>nul move "%%~a*" "%%~a")
penpen
I like that. That should be fairly foolproof.
Re: Need to write a batch file that moves files based on nam
Posted: 29 Jan 2015 18:09
by foxidrive
penpen wrote:This may help you (untested):
Code: Select all
@for /D %%a in (*) do @(2>nul move "%%~a*" "%%~a")
penpen
penpen, how is that going to move files into folders?
EDIT: Oh, he manually created all the band name folders - didn't see that bit.
Re: Need to write a batch file that moves files based on nam
Posted: 29 Jan 2015 21:26
by julesverne
@for /D %%a in (*) do @(2>nul move "%%~a*" "%%~a")
what does the "@" symbol do? I tried googling that, I don't get it.
Re: Need to write a batch file that moves files based on nam
Posted: 30 Jan 2015 00:00
by penpen
The command line interpreter has an echoing feature, which could be switched on (default) and off.
If this feature is enabled the command line interpreter:
- typically displays the full Path (for example "C:\temp>") within the shell.
- echoes a command before this command is executed.
In a batch program the @ character in front of a command tells the command line interpreter not to echo this command before executing it.
penpen
Re: Need to write a batch file that moves files based on nam
Posted: 30 Jan 2015 07:22
by Squashman
Re: Need to write a batch file that moves files based on nam
Posted: 02 Feb 2015 10:31
by Samir
It's cool how @ can be put on the command line in modern DOS/Command line. I don't think you were able to do that back in the 3.3-5.0 days.
Re: Need to write a batch file that moves files based on nam
Posted: 02 Feb 2015 16:01
by foxidrive
Samir wrote:It's cool how @ can be put on the command line in modern DOS/Command line. I don't think you were able to do that back in the 3.3-5.0 days.
Download a dos boot disk, and maybe put it on a USB stick with the right tools, and try it.
Re: Need to write a batch file that moves files based on nam
Posted: 03 Feb 2015 06:09
by Samir
foxidrive wrote:Samir wrote:It's cool how @ can be put on the command line in modern DOS/Command line. I don't think you were able to do that back in the 3.3-5.0 days.
Download a dos boot disk, and maybe put it on a USB stick with the right tools, and try it.
I remember it working in batch, but not command line. Have you had a different experience?