windows 7 - Given a list of filenames, how can you iterate through subdirectories and return a list of where those files exist?

07
2014-07
  • Iain Fraser

    I have discovered an old playlist that I'd really like to listen to. Unfortunately, it's one that was created for a USB stick that had music copied out of my collection into a flat folder.

    What I want to do now is recreate that playlist by matching those filenames to the paths in my main music collection.

    As an example, suppose my existing playlist looks like this:

    F:\music\Artist 1 - Song 1.mp3
    F:\music\Artist 2 - Song 2.mp3
    F:\music\Artist 3 - Song 3.mp3
    

    And after processing, I might end up with something like this:

    W:\Music Collection\Compilations\Compilations Forever 6\Artist 1 - Song 1.mp3
    W:\Music Collection\Artist 2\This is the Album\Artist 2 - Song 2.mp3
    W:\Music Collection\Unsorted New Stuff\Artist 3 - Song 3.mp3
    

    The filenames are guaranteed to be the same, the paths will always be different.

    There are about 300 tracks on this playlist, so it would be laborious to manually search for each one individually. I've had a look at XCOPY, having read about EXCLUDE, I was hoping there'd be an INCLUDE, but alas that wasn't going to be an option. I'd also read about using a FOR loop inside a batch file, but it's been a long time since I wrote batch files and I'm not quite sure where to begin.

    Thanks very much for your help

  • Answers
  • dbenham

    I assume you can get your old playlist in a text file - call it "oldList.txt".

    First you need to get a modified list in a text file that contains just the file names, without any path information. Then you can pipe the result of a recursive DIR command into FINDSTR, and use the modified list as literal, case insensitive search strings that must match the end of a full path from the DIR command.

    Here is a simple batch script that should do the trick:

    @echo off
    (for /f "eol=: delims=" %%F in (oldList.txt) do echo \%%~nxF)>searchList.txt
    dir /b /s /a-d "W:\Music Collection\*"|findstr /lieg:searchList.txt >newList.txt
    del searchList.txt
    
  • Iain Fraser

    Okay, so here's what I did. It was all done with regular expressions. I'm 100% sure there's an easier way to do it than this, but it worked and I only had to do it once so good result.

    I used an application called Regex Buddy, but you could conceivably use any half-decent text editor with regex support.

    Please note, all of the following Regexs are set so ^ and $ match at line breaks and the regex is processed line-by-line.

    I took the original file list:

    F:\music\(Artist 1) - Song 1.mp3
    F:\music\[Artist 2] - Song 2.mp3
    F:\music\Artist 3 - Song 3 {remix}.mp3
    

    and applied the following regex to it:

    ^.*\\
    replace with empty string
    

    Which results in:

    (Artist 1) - Song 1.mp3
    [Artist 2] - Song 2.mp3
    Artist 3 - Song 3 {remix}.mp3
    

    I then applied

    [\.\[\]\(\)\{\}]
    replace with
    \$0
    

    Which results in

    \(Artist 1\) - Song 1\.mp3
    \[Artist 2\] - Song 2\.mp3
    Artist 3 - Song 3 \{remix\}\.mp3
    

    I then applied

    $\s
    replace with
    |
    

    Which results in

    \(Artist 1\) - Song 1\.mp3|\[Artist 2\] - Song 2\.mp3|Artist 3 - Song 3 \{remix\}\.mp3
    

    I then applied

    .*
    replace with
    ^.*\\($0)$
    

    Which results in

    ^.*\\(\(Artist 1\) - Song 1\.mp3|\[Artist 2\] - Song 2\.mp3|Artist 3 - Song 3 \{remix\}\.mp3)$
    

    We now have a super long regex which incorporates all the files I'm looking for.

    Now open the command prompt, browse to the music director any type the following:

    dir /s/b > filelist.txt
    

    When the command has finished, open up filelist.txt and apply the regex we built to it as a search.

    Hey presto! All the files in the playlist found. There were of course a few false positives where I had duplicate file names, but it's good enough to get me rocking and didn't take all that much time to achieve (despite how it looks)


  • Related Question

    windows - How can I play my MP3 files through my stereo system?
  • Joel Coehoorn

    Here's the situation. Like many others I have my entire CD collection ripped to my PC, along side other music I've acquired through iTunes or Amazon MP3. Also like many others the speakers at my PC are underpowered, and likely included in my monitor as an afterthought.

    This is fine for most use: system sounds, YouTube, etc. Even games sounds and music. But I'd like something a little better for when I really want to listen to music. And I have it; in the next room — barely 25 feet away as the crow flies — sits a nice 400 watts stereo system. The stereo supports MP3 CDs, so up to this point I've just kept a few CD-RW disks around to keep most of my collection available. But it's time to move on to something a little more sophisticated.

    What are my options for using the MP3 files available on my computer as an input for this stereo?

    Some notes:

    • I want to be able to control what song the stereo is playing without having to go to the PC, including setting up and retrieving playlists. Ideally this should even be able to wake the PC from sleep mode to start playing.
    • I primarily use Windows Media Player on the PC (which runs Windows Vista). However, the files themselves live on a server running Windows Server 2008, and so I could also install something on the server and run everything from there.
    • The axillary input on the stereo is unfortunately limited to a 1/8 inch stereo mini-plug.
    • I'm loath to run wires across two rooms, and I'm considering moving the stereo to the garage at some point. Therefore a wireless solution that can easily cover about 100 ft or so is preferred.
    • I already have a Wi-Fi network ready, but it's secured so anything using Wi-Fi should make it easy to set up security.
    • Bonus points for doing it in under $85 shipped at Amazon (I'm hoping to pay for this via $85 worth of Amazon gift cards). I know this a pretty tight budget, so just getting close is okay.
    • Bonus points for something that remembers multiple profiles (keep my favorite songs separate from the wife's).
    • Bonus points for a remote that can also replace my stereo remote, so I only need one device to control everything. I'm not holding my breath on this one given my price range, though.
    • Bonus points if I can also use for Internet radio.

    Doing some research on my own as well. This looks like it'll do exactly what I want, but it lists at an outrageous $299:
    http://www.linksysbycisco.com/US/en/products/DMP100


  • Related Answers
  • BenA

    It may not hit every point on your list, but I use an Apple Airport Express to achieve the same goal.

    • Its wireless (and supports security)
    • The output is a 1/8 inch stereo jack
    • Amazon lists it at $95 dollars currently, so near your price point
    • If you have an iPhone or an iPod touch there is a Remote app you can use to control playback (including playlist support)

    This solutions obviously needs iTunes as the serving software, but if your server machine is always on then I'd suggest you leave it running on that. This would also get around the Wake from sleep issue.

    Update You may be able to use Salling Clicker as the remote on your phone (though I haven't tried it myself). There's a free trial which may be worth a look.

  • Noldorin

    If you have a modern smartphone (either Windows Mobile or Unix-based), a decent solution might be to use Windows Media Sharing over the wireless network. This would have the following advantages in my view:

    • The communication problem would be solved by using your existing WiFi network.
    • Windows Media Sharing gives you pretty good control over playback. You can easily make use of albums, playlists, and such.
    • Connecting the phone to 1/8in audio input of your system should be a straightforward matter, since all phones have earphone jacks.
    • You may be able to use the phone's IR capabilities for receiving signal from a remote control, or even better, if you can get hold of a Bluetooth remote, use that. May require some hackery though.
    • Waking the serving computer up from sleep should be possible by sending a LAN packet from your phone.

    Understandably, this could require a fair bit of effort to get this running, but I believe it is an elegant solution in the end, and (providing you have a smartphone running a decent OS), a relatively cost-effective one too. Even if you don't, I suspect you could buy a good enough smartphone to do the job for under £150 ($250?), which could well be a worthy investment in general.

  • GAThrawn

    The Logitech Squeezebox range has some options that fulfill pretty much all of your requests, they do require a PC to be switched on whilst playing, but this could easily be your server.

    The Squeezebox Touch and Duet are both meant to be plugged into a home stereo and can be controlled by their remote control (or built-in touch screen) you can also control them via the server's web control page using any WiFi enabled phone, and many smart phone platforms have dedicated apps in their stores (I use SqueezeControl on my Android phone).