Closed Thread
Results 1 to 2 of 2

Thread: importing file names based on extension

  1. #1
    Barn Enthusiast sbenj69 is a jewel in the rough sbenj69 is a jewel in the rough sbenj69 is a jewel in the rough sbenj69 is a jewel in the rough sbenj69's Avatar
    Join Date
    Mar 2008
    Location
    The frigid northern plains
    Posts
    432
    Rep Power
    7

    importing file names based on extension

    How would one go about scanning a hard drive for all mp3 files (i.e. *.mp3) and importing all of the titles into a database? I'm sure the dir function comes into play, but it seems to only handle "current" directory and not sub directories.

    I was just curious is all..... haven't really dabbled that much in the file/directory functions.

  2. #2
    Barn Enthusiast sbenj69 is a jewel in the rough sbenj69 is a jewel in the rough sbenj69 is a jewel in the rough sbenj69 is a jewel in the rough sbenj69's Avatar
    Join Date
    Mar 2008
    Location
    The frigid northern plains
    Posts
    432
    Rep Power
    7

    Ok, I was able to do this by calling a DOS command from a form. I automated everything by macro. In my case, a dash "-" separates artist from song title, so I did an instr function to find the dash and parsed out the artist and song based on the dash.

    The correct way to call the DOS command was:
    Code:
    Dim ans As String
    
    ans = "dir c:\*.mp3 /s > c:\mylist.txt"
    
    Shell "cmd /c " & ans, vbHide
    
    DoCmd.Close
    
    Basically, DIR C:*.mp3 /s >mylist.txt makes a text file based on my directory search, which in this case is a full system search. It saved the directory search as mylist.txt. I had to set an import template for the macro to work correctly. I opted for undelimited (fixed width). Not sure if the import format will be included with the zip.

    If it isn't included, then you will need to go to the import function for Access, choose file type as text, point it to the text file, choose fixed width, click on the advanced button, then click on "save as", then type "nospaces", save it, and then cancel out, then re-run the macro.

    Note: A macro cannot import a text file without having an import type set up.

    In the macro, I put a msgbox to tell the user to wait 10 seconds, giving the form time to search the hard drive and export to the text file. Then the macro imports from the text file, parses out the important info, and displays a form in datasheet view to show the imported files. If you click OK too early, it will give a JET database error....... I will prolly automate this a little bit more in the future, but I have another project (a paying project) and I didn't have much time to spend on this. Stay tuned, as I will update this in the future to make it truly fully automated.

    Basically, what I've created was a database that searches your hard drive for mp3's and inserts it into a database. I have a more advanced database that lets users request songs, search songs, and do quick picks based on genre. This is just a basic example, and you can do with it as you wish.

    So, hope you like it....this can be modified to look up any type file. Also, I could make this to make hyperlinks if I so desired, so, you search for a file, and run it instantly. Definitely could be a high powered search tool. I could even make it where you specify the extension type and it pulls it up for you to run.

    Without further delay, here is the database
    Last edited by sbenj69; March 13th, 2009 at 03:22 AM.

Closed Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO