Need to write a batch file that moves files based on name
Moderator: DosItHelp
Need to write a batch file that moves files based on name
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!
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
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
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.
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
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
This may help you (untested):
penpen
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
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
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.
-
- Posts: 81
- Joined: 19 Nov 2013 00:41
Re: Need to write a batch file that moves files based on nam
@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
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
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
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
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
I remember it working in batch, but not command line. Have you had a different experience?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.