Go Back   DeveloperBarn Forums > Databases > Microsoft Access

Sponsored Links

Discuss "importing file names based on extension" in the Microsoft Access forum.

Microsoft Access - Microsoft Access is a database for small to medium applications. Learn tips and tricks and best database practices here.


Closed Thread « Previous Thread | Next Thread »  
 
LinkBack (1) Thread Tools Display Modes
  1 links from elsewhere to this Post. Click to view. #1  
Old April 10th, 2008, 04:57 PM
sbenj69's Avatar
Moderator

 
Join Date: Mar 2008
Posts: 84
Thanks: 20
Thanked 24 Times in 19 Posts
Rep Power: 1
sbenj69 is on a distinguished road

Awards Showcase
Microsoft Windows Microsoft Access 
Total Awards: 2

Default 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.
Sponsored Links
  #2  
Old April 11th, 2008, 12:56 AM
sbenj69's Avatar
Moderator

 
Join Date: Mar 2008
Posts: 84
Thanks: 20
Thanked 24 Times in 19 Posts
Rep Power: 1
sbenj69 is on a distinguished road

Awards Showcase
Microsoft Windows Microsoft Access 
Total Awards: 2

Default

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
Attached Files
File Type: zip Find MP3s.zip (15.9 KB, 7 views)
Closed Thread

  DeveloperBarn Forums > Databases > Microsoft Access

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

LinkBacks (?)
LinkBack to this Thread: http://www.developerbarn.com/microsoft-access/121-importing-file-names-based-extension.html
Posted By For Type Date
DeveloperBarn Forums - ASP Help, ASP.Net Help, PHP Help, SQL Help, Tutorials, Windows Help This thread Refback April 26th, 2008 09:36 AM


All times are GMT -4. The time now is 12:58 PM.



Content Relevant URLs by vBSEO 3.2.0