dbTalk Databases Forums  

Make Multiple Directories From A Table and Delete If Empty

comp.databases.ms-access comp.databases.ms-access


Discuss Make Multiple Directories From A Table and Delete If Empty in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
bezz
 
Posts: n/a

Default Make Multiple Directories From A Table and Delete If Empty - 05-14-2011 , 06:23 AM






There was a question a while ago about making directories from a table, specifically creating an artistes folder so music albums
can be stored by artist.

Anyone have a little routine stored away on their compendium of access goodies?

I suppose another useful function would be to check if a directory is empty and delete it as well so it cleanses any redundant
folders. I could probably adapt a routine I have already for reading a table and use MKDIR to create them, but someone may already
have an effective and tight method of doing it ?

J


--
--------------------------------- --- -- -
Posted with NewsLeecher v4.0 Final
Web @ http://www.newsleecher.com/?usenet
------------------- ----- ---- -- -

Reply With Quote
  #2  
Old   
Stuart McCall
 
Posts: n/a

Default Re: Make Multiple Directories From A Table and Delete If Empty - 05-14-2011 , 09:22 AM






"bezz" <bezz (AT) hotmail (DOT) com> wrote

Quote:
There was a question a while ago about making directories from a table,
specifically creating an artistes folder so music albums
can be stored by artist.

Anyone have a little routine stored away on their compendium of access
goodies?

I suppose another useful function would be to check if a directory is
empty and delete it as well so it cleanses any redundant
folders. I could probably adapt a routine I have already for reading a
table and use MKDIR to create them, but someone may already
have an effective and tight method of doing it ?

J
Is this the kind of thing you're looking for?

http://www.smccall.demon.co.uk/Strings.htm#CreatePath

Reply With Quote
  #3  
Old   
bezz
 
Posts: n/a

Default Re: Make Multiple Directories From A Table and Delete If Empty - 05-14-2011 , 11:07 AM



There was some useful data in the Stuart McFall pages, didn't realise the ex Rangers man was multi-skilled.

Used the routine below to make a start, this works OK, will probably develop a bit further to remove empty directories etc.



Private Sub dirprintcombut_Click()
On Error GoTo Err_dirprintcombut_Click

Dim db As Database
Set db = CurrentDb()
Dim RS As DAO.Recordset
Dim artistname As String
Dim Rootfolder As String
Dim dirtobecreated As String

' Name of folder where directories are to be created - error if it doesn't exist

Rootfolder = "E:\Test\"

' Open each entry in table one at a time - I used folder print to export a table

Set RS = db.OpenRecordset("SELECT * FROM ArtisteQuery")
Do While Not RS.EOF
artistname = RS![Artist]

' Create each prospective foldername

dirtobecreated = Rootfolder & artistname

' If the foldername doesn't exist then create it - this will allow mods to list later on

If Len(Dir(dirtobecreated, vbDirectory)) = 0 Then
MkDir dirtobecreated
End If

RS.MoveNext
Loop
RS.Close

' Close recordset on completion

Exit_MySub:
Set RS = Nothing
Set db = Nothing

Exit Sub


Exit_dirprintcombut_Click:
Exit Sub

Err_dirprintcombut_Click:
MsgBox Err.Description
Resume Exit_dirprintcombut_Click

End Sub


--
--------------------------------- --- -- -
Posted with NewsLeecher v4.0 Final
Web @ http://www.newsleecher.com/?usenet
------------------- ----- ---- -- -

Reply With Quote
  #4  
Old   
Stuart McCall
 
Posts: n/a

Default Re: Make Multiple Directories From A Table and Delete If Empty - 05-14-2011 , 09:10 PM



"bezz" <bezz (AT) hotmail (DOT) com> wrote

Quote:
There was some useful data in the Stuart McFall pages, didn't realise the
ex Rangers man was multi-skilled.

Used the routine below to make a start, this works OK, will probably
develop a bit further to remove empty directories etc.



Private Sub dirprintcombut_Click()
On Error GoTo Err_dirprintcombut_Click

Dim db As Database
Set db = CurrentDb()
Dim RS As DAO.Recordset
Dim artistname As String
Dim Rootfolder As String
Dim dirtobecreated As String

' Name of folder where directories are to be created - error if it doesn't
exist

Rootfolder = "E:\Test\"

' Open each entry in table one at a time - I used folder print to export a
table

Set RS = db.OpenRecordset("SELECT * FROM ArtisteQuery")
Do While Not RS.EOF
artistname = RS![Artist]

' Create each prospective foldername

dirtobecreated = Rootfolder & artistname

' If the foldername doesn't exist then create it - this will allow mods to
list later on

If Len(Dir(dirtobecreated, vbDirectory)) = 0 Then
MkDir dirtobecreated
End If

RS.MoveNext
Loop
RS.Close

' Close recordset on completion

Exit_MySub:
Set RS = Nothing
Set db = Nothing

Exit Sub


Exit_dirprintcombut_Click:
Exit Sub

Err_dirprintcombut_Click:
MsgBox Err.Description
Resume Exit_dirprintcombut_Click

End Sub

That looks like a plan, so long as you don't need to create folders more
than one level deep. Otherwise you'd need to use my CreateFolder routine (or
something like it).

What is FolderPrint?

Re the footballer Stuart M: actually he is multi-skilled of a sort. He
googled his own name and discovered my site. He then clicked my 'contact me'
link and sent me a message complimenting my homepage statement. Not bad for
a footballer <g>.

Reply With Quote
  #5  
Old   
bezz
 
Posts: n/a

Default Re: Make Multiple Directories From A Table and Delete If Empty - 05-15-2011 , 06:48 AM



Just about to go and watch his old team play...

I met him briefly at the driving range up in Clydebank, I lived in a place about 25 miles west of Glasgae for 10 years, where a lot
of footballers used to live. I was in the chippie next to my local once (and I'd been in the local for a while !) I said to my
mate, "I'm sure I know those two lads there, have we shipped out with them before". He replied "It's Michael Mols and Jorge
Albertz ya idjit. !"

Thanks for assistance all posters..

J


--
--------------------------------- --- -- -
Posted with NewsLeecher v4.0 Final
Web @ http://www.newsleecher.com/?usenet
------------------- ----- ---- -- -

Reply With Quote
Reply




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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.