China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-09 11:34
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Help] Batch create directories by artist name and move songs into the directories View 2,730 Replies 36
Original Poster Posted 2008-08-20 13:43 ·  日本 东京都 千代田区 KDDI公司
初级用户
Credits 32
Posts 15
Joined 2007-08-02 12:44
19-year member
UID 94499
Gender Male
Status Offline
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.
Floor 2 Posted 2008-08-20 13:56 ·  中国 广东 广州 天河区 电信
银牌会员
★★★
Credits 1,206
Posts 517
Joined 2007-03-25 01:18
19-year member
UID 82819
Gender Male
Status Offline
@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 ]
知,不觉多。不知,乃求知
Floor 3 Posted 2008-08-20 14:00 ·  中国 江苏 苏州 吴江区 电信
银牌会员
★★★
Credits 1,608
Posts 780
Joined 2007-10-07 10:19
18-year member
UID 99089
Gender Male
Status Offline
```
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 ]
Floor 4 Posted 2008-08-20 14:05 ·  日本 东京都 千代田区 KDDI公司
初级用户
Credits 32
Posts 15
Joined 2007-08-02 12:44
19-year member
UID 94499
Gender Male
Status Offline
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.
Floor 5 Posted 2008-08-20 14:07 ·  中国 江苏 苏州 吴江区 电信
银牌会员
★★★
Credits 1,608
Posts 780
Joined 2007-10-07 10:19
18-year member
UID 99089
Gender Male
Status Offline
Floor 6 Posted 2008-08-20 14:09 ·  中国 广东 广州 天河区 电信
银牌会员
★★★
Credits 1,206
Posts 517
Joined 2007-03-25 01:18
19-year member
UID 82819
Gender Male
Status Offline
'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.
知,不觉多。不知,乃求知
Floor 7 Posted 2008-08-20 14:11 ·  中国 广东 广州 天河区 电信
银牌会员
★★★
Credits 1,206
Posts 517
Joined 2007-03-25 01:18
19-year member
UID 82819
Gender Male
Status Offline
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?
知,不觉多。不知,乃求知
Floor 8 Posted 2008-08-20 14:11 ·  中国 江苏 苏州 吴江区 电信
银牌会员
★★★
Credits 1,608
Posts 780
Joined 2007-10-07 10:19
18-year member
UID 99089
Gender Male
Status Offline
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.
Floor 9 Posted 2008-08-20 14:13 ·  中国 广东 广州 天河区 电信
银牌会员
★★★
Credits 1,206
Posts 517
Joined 2007-03-25 01:18
19-year member
UID 82819
Gender Male
Status Offline
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?
知,不觉多。不知,乃求知
Floor 10 Posted 2008-08-20 14:14 ·  日本 东京都 千代田区 KDDI公司
初级用户
Credits 32
Posts 15
Joined 2007-08-02 12:44
19-year member
UID 94499
Gender Male
Status Offline
The directory is all set up, but all the files are gone, and the folders are all empty.
Floor 11 Posted 2008-08-20 14:18 ·  日本 东京都 千代田区 KDDI公司
初级用户
Credits 32
Posts 15
Joined 2007-08-02 12:44
19-year member
UID 94499
Gender Male
Status Offline
Originally posted by huahua0919 at 2008-8-20 02:00 PM:

for /f "tokens=1* delims=-" %%i in ('dir/b/a-d *.mp3') do (
md %%i 2>nul&copy "%%i-%%j" %%i
)

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.
Floor 12 Posted 2008-08-20 14:19 ·  中国 广东 广州 天河区 电信
银牌会员
★★★
Credits 1,206
Posts 517
Joined 2007-03-25 01:18
19-year member
UID 82819
Gender Male
Status Offline
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
知,不觉多。不知,乃求知
Floor 13 Posted 2008-08-20 14:20 ·  日本 东京都 千代田区 KDDI公司
初级用户
Credits 32
Posts 15
Joined 2007-08-02 12:44
19-year member
UID 94499
Gender Male
Status Offline
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 ]
Floor 14 Posted 2008-08-20 14:21 ·  中国 江苏 苏州 吴江区 电信
银牌会员
★★★
Credits 1,608
Posts 780
Joined 2007-10-07 10:19
18-year member
UID 99089
Gender Male
Status Offline
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.
Floor 15 Posted 2008-08-20 14:21 ·  中国 广东 广州 天河区 电信
银牌会员
★★★
Credits 1,206
Posts 517
Joined 2007-03-25 01:18
19-year member
UID 82819
Gender Male
Status Offline
Since there are prompts? Why are all the folders empty?
知,不觉多。不知,乃求知
Forum Jump: