CMD for unable to move files due to string butcher

2019-09-04 23:42发布

I'm trying to format my USB stick for use in my car as music database. However, my radio can only playback one folder at a time, so I thought it would be helpful to move all titles of an artist to the artist's folder.

Since this are like 32GB of music that would be a lot of work by hand.

I've come up with the following script to do the job (G:\ being the USB drive)

FOR /F %%T IN ('dir G:\ /B /A:D') DO (
    FOR /R %%D IN (G:\%%T\*.*) DO MOVE "%%d" "G:\%%T"
)

So far this works, but the 'dir G:\ /B /A:D' command ends up butchering the folder names in this fashion: "FOLDER NAME" -> "FOLDER". So it essentially just picks up the first word for some reason.

Please help.

2条回答
狗以群分
2楼-- · 2019-09-05 00:11

Change your outer FOR command:

for /f "tokens=*" %%T in ('dir /b /a:d "G:\"') DO (
 ...
)
查看更多
贪生不怕死
3楼-- · 2019-09-05 00:12

The FOR metavariable is one of the few places in batch that is case-sensitive. The %%D mst match the %%d - or vice-versa.

(but you'd probably do well to include "delims=" between the FOR/f and the metavariable...) to ensure that the entire string is assigned to the metavariable.

查看更多
登录 后发表回答