15

CMD for the inability to move files due to string deletion

 3 years ago
source link: https://www.codesd.com/item/cmd-for-the-inability-to-move-files-due-to-string-deletion.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

CMD for the inability to move files due to string deletion

advertisements

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.


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.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK