3

I have a bunch of folders, each containing a number of shortcut link files to mp3 files existing in completely separate folders. eg:

/rock-mp3-shortcuts
/jazz-mp3-shortcuts
/funk-mp3-shortcuts

what command would I run (or program to use) to copy all the underlying mp3 files back into the folders of shortcuts that are pointing to them.

I basically want to get all the files in each genre folder of shortcuts to then copy into my portable mp3 player.

2 Answers 2

3

This should work:

@echo off
FOR /r %%i in (*.lnk) do call :COPYFILE "%%i"
GOTO:EOF
:COPYFILE
set "filename=%1"
set "filename=%filename:"=%"
set "filename=%filename:\=\\%"
for /f "tokens=1* delims==" %%I in ('wmic path win32_shortcutfile where "name='%filename%'" get target /format:list ^| find "="') do (
    set tatgetFile=%%J
    copy /y "%tatgetFile%"
)

You'll have to create a bat file and paste my code into it. The file must be located in the folder where all your *.lnk (shortcut) files are. As you have three of them, you will have to copy the bat to each folder and execute it once. You also can automate this and use only one bat but I guess you'll figure out yourself how to do this. It will iterate over all shortcuts and copy the target files to the current folder.

Unfortunately, handling shortcuts in cmd is a pain in the 'a'. That's why we have to use wmic and win32_shortcutfile here.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks Michael, I'm on Win 7 and that doesn't work: i.imgur.com/GE9wJCr.png
Cant you use directly /format:value and use variable Target?
@MichaelS that copied 25 files, but ceased with another 54 to go. Also, there are 4 subdirectories hanging off "shorts" and it did not go into those. i.imgur.com/BP4vd23.png
2

You can check shortcutJS.bat with which you can create or check info about .lnk.You will need it in the same directory with this code:

@echo off

setlocal
::set your location on the line bellow
set "mp3_dir=c:\mp3_dir"
pushd "%mp3_dir%"
for /r %%# in (*.lnk) do (

    for /f "tokens=1* delims=: " %%a in ('shortcutJS.bat -examine "%%~f#"^|find /i "target"') do (
        echo location of %%# : %%~fb
        rem !!!!  remove the echo on the line bellow if everything is ok !!!!
        echo copy "%%~fb" "%%~dp#"
    )

)
endlocal

2 Comments

I copied raw.githubusercontent.com/npocmaka/batch.scripts/master/hybrids/… into the folder, along with another file with the code above and it did not copy, although it started successfully iterating through the files... some listed here: i.imgur.com/uEDzZ1A.png
@Adrian33 it is in the second comment. Delete the echo in this line echo copy "%%~fb" "%%~dp#" and leave only copy "%%~fb" "%%~dp#" to activate the copying.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.