中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-09 12:28
47,811 topics / 349,895 posts / today 0 new / 48,254 members
DOS批处理 & 脚本技术(批处理室) » [Help] Batch create directories by artist name and move songs into the directories
Printable Version  2,736 / 36
Floor1 iuiu Posted 2008-08-20 13:43
初级用户 Posts 15 Credits 32
Now there are thousands of songs, and the file names are like this:
Wang Leehom - Forever Love.mp3
Wang Leehom - I'm Lovin'it.mp3
Wan Fang - Bu Huan.mp3
Now I want to create folders respectively according to the singer names in the file names, and move the songs to the corresponding singer's directory. How to write this batch processing? Please expert teach without stint. Thanks a lot.
Floor2 flyinspace Posted 2008-08-20 13:56
银牌会员 Posts 517 Credits 1,206
@echo off & setlocal EnableDelayedExpansion
set "Total=0"
for /f "delims=- tokens=1,* " %%i in (' dir /b *.mp3') do (
set /a "Total+=1"
echo 正在处理第!Total!首歌:
if not exist "%%i" md "%%i"
if exist "%%i-%%j" copy "%%i-%%j" "%cd%\%%i"
if exist "%cd%\%%i\%%i-%%j" del "%%i-%%j"
)
echo 处理完毕,共处理首歌~!&pause>nul

[ Last edited by flyinspace on 2008-8-20 at 02:40 PM ]
Floor3 huahua0919 Posted 2008-08-20 14:00
银牌会员 Posts 780 Credits 1,608
```
for /f "tokens=1* delims=-" %%i in ('dir/b/a-d *.mp3') do (
md %%i 2>nul&copy "%%i-%%j" %%i
)
```
It is necessary to change copy to move if needed.

[ Last edited by huahua0919 on 2008-8-20 at 02:01 PM ]
Floor4 iuiu Posted 2008-08-20 14:05
初级用户 Posts 15 Credits 32
Originally posted by flyinspace at 2008-8-20 01:56 PM:
@echo off & setloacl EnableDelayedExpansion
set "Total=0"
for /f "delims=- tokens=1,* " %%i in (' dir /b *.mp3') do (
set /a "Total+=1"
echo 正在处 ...


Boss, the directory is there, but all the songs are gone, feeling like crying without tears.
Floor5 huahua0919 Posted 2008-08-20 14:07
银牌会员 Posts 780 Credits 1,608
Floor6 flyinspace Posted 2008-08-20 14:09
银牌会员 Posts 517 Credits 1,206
'dir/b/a-d *.mp3'

1. I don't understand. Since it's already sorted by.mp3, what's the use of /a-d?
Does it still need to exclude the folders with *.mp3?

2. Instead of a large number of md operations, it's better to verify.

3. According to your code, the move instruction should be used instead of copy. Because you don't have the del operation.
Floor7 flyinspace Posted 2008-08-20 14:11
银牌会员 Posts 517 Credits 1,206
Don't cry. Now you don't do anything.

I'll give you something.. The code was written wrong just now? But the song should have been copied to the directory, right?
Floor8 huahua0919 Posted 2008-08-20 14:11
银牌会员 Posts 780 Credits 1,608
I'm seeking insurance, not running on my side, it's hard to say anything. So the code you wrote may execute successfully but has problems.
1. Using.mp3 as a folder must be correct.
2. The efficiency of 2 >nul is higher than that of if exist.
3. Just what I said above.
Floor9 flyinspace Posted 2008-08-20 14:13
银牌会员 Posts 517 Credits 1,206
if exist "%cd%\%%i" del "%%i-%%j"

It should be: if exist "%cd%\%%i\%%i-%%j" del "%%i-%%j"

What is your QQ number? MSN is also okay?
Floor10 iuiu Posted 2008-08-20 14:14
初级用户 Posts 15 Credits 32
The directory is all set up, but all the files are gone, and the folders are all empty.
Floor11 iuiu Posted 2008-08-20 14:18
初级用户 Posts 15 Credits 32
Originally posted by huahua0919 at 2008-8-20 02:00 PM:

You can change copy to move if necessary

[ Last edited by hu ...

I tried this boss's code too. Now the problem is that the directories are built, but there are many extra empty directories.
Originally there were 302 files about 1.6g, but after copying, there are only 902m.

But still thank you two.
Floor12 flyinspace Posted 2008-08-20 14:19
银牌会员 Posts 517 Credits 1,206
Hey. Sorry about that.

1 file(s) copied.

Is there such a prompt??

It seems that I should add if errorlevel to all code in the future
Floor13 iuiu Posted 2008-08-20 14:20
初级用户 Posts 15 Credits 32
Processing song number !Total!:
0 files copied.
Processing song number !Total!:
0 files copied.
Processing song number !Total!:
0 files copied.
Processing song number !Total!:
0 files copied.
Processing song number !Total!:
0 files copied.
Processing song number !Total!:
0 files copied.
Processing song number !Total!:
0 files copied.
Processing song number !Total!:
0 files copied.
Processing song number !Total!:
0 files copied.
Processing song number !Total!:
0 files copied.
Processing song number !Total!:
0 files copied.
Processing song number !Total!:
0 files copied.
Processing song number !Total!:
0 files copied.
Processing song number !Total!:
0 files copied.
Processing song number !Total!:
0 files copied.
Processing song number !Total!:
0 files copied.
Processing song number !Total!:
0 files copied.
Processing song number !Total!:
0 files copied.
Processing song number !Total!:
0 files copied.
Processing song number !Total!:
0 files copied.
Processing song number !Total!:
0 files copied.
Processing song number !Total!:
0 files copied.
Processing song number !Total!:
0 files copied.
Processing completed, total of songs processed~!

[ Last edited by iuiu on 2008-8-20 at 02:25 PM ]
Floor14 huahua0919 Posted 2008-08-20 14:21
银牌会员 Posts 780 Credits 1,608
That is, there is a problem with your file name structure. It cannot have special characters, otherwise it will be empty. So that's why I used copy.
Floor15 flyinspace Posted 2008-08-20 14:21
银牌会员 Posts 517 Credits 1,206
Since there are prompts? Why are all the folders empty?
1 2 3  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023