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
Function to create multiple sub directories
-
- Posts: 2038
- Joined: Tue Nov 29, 2005 8:28 pm
- Location: latiitude 50N longitude 3W
- Contact:
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
http://www.alh.net/newlisp/phpbb/viewto ... ight=mkdir
Playing with dirs :
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
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 )
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