Function to create multiple sub directories

Machine-specific discussion
Unix, Linux, OS X, OS/2, Windows, ..?
Locked
SHX
Posts: 37
Joined: Fri Feb 16, 2007 11:06 pm

Function to create multiple sub directories

Post by SHX »

Can someone give me an example of how to code a function that creates multiple sub directories

For instance if I pass "c:\firstdir\seconddir\thirddir" to the function and only "c:\" exists, that the code will create "c:\firstdir" and then "c:\firstdir\seconddir" and finally "c:\firstdir\seconddir\thirddir"


Steven

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Post by cormullion »

I know this was mainly Unix-related, but there might be some generic code in there too:

http://www.alh.net/newlisp/phpbb/viewto ... ight=mkdir

didi
Posts: 166
Joined: Fri May 04, 2007 8:24 pm
Location: Germany

Post by didi »

Playing with dirs :

Code: Select all

 ; dirtest  dmemos 29-jul-07

 ; --- simple function

 ( change-dir  "D:\\temp" )   ; my play-dir

 ( define ( mkdirs  mlist )
  ( dolist  ( dirname mlist )
       (  make-dir  dirname )
       (  change-dir dirname )))

 ( mkdirs  '( "a"  "b"  "c"  ))

 ; --- same with a macro 

 ( change-dir  "D:\\temp" )   ; my play-dir

 ( define-macro  ( mkdirs2 )
    ( doargs  ( dirname )
         ( make-dir (string dirname ))
         ( change-dir (string dirname))
 ))
 
 ( mkdirs2  "g" "h" "i" )   ; now you don't need a list

 ( change-dir  "D:\\temp" )   ; my play-dir

 ( mkdirs2 d e f )           ; .. and you even don't need strings

 ; --- small addition : when finished go back to start-dir  

 ( change-dir  "D:\\temp" )   ; my play-dir

 ( define ( mkdirs3  mlist )
   ( set 'start-dir (real-path))
   ( dolist  ( dirname mlist )
       (  make-dir  dirname )
       (  change-dir dirname ))
    ( change-dir start-dir ))

 ( mkdirs3  '( "j"  "k"  "l"  ))

 ; --- with macro the same

 ( define-macro  ( mkdirs4 )
    ( set 'start-dir (real-path))
    ( doargs  ( dirname )
         ( make-dir (string dirname ))
         ( change-dir (string dirname))
    )
   ( change-dir start-dir ))
 
 ( mkdirs4  "m" "n" "o" ) 

 ( mkdirs4   p q  r )  
Maybe you have to parse your string into single dir-names .

PS: it doesn't matter if you apply make-dir on an existing directory

PPS : i wrote this before reading cormullions link - but it's interesting to see it , i've tested my examples under Win2k

Locked