Notifications
Clear all

[Closed] CopyDirTree Recursive

Hi

I made a function for copy Dirs with all subdirs and files to destination path.
Its working fine , but Im sure what somebody of you can make it simpliest


  --Recursive fn
  fn copyAllDirsWithFiles inpath outpath =
  (
  	if not doesFileExist outpath do try (makeDir outpath) catch (return false)
  	local the_dirs = getDirectories (inpath+"*.*")
  	for in_d in the_dirs do
  	(
  		local out_d = 
  		(
  			local dir_elements = (filterString in_d "\\")
  			local last_dir = dir_elements[dir_elements.count]
  			outpath+last_dir+"\\"
  		)
  		
  		makeDir out_d
  
  		local the_files = getFiles (in_d+"*.*")
  		for in_f in the_files do 
  		(
  			local out_f = out_d + filenameFromPath in_f
  			copyFile in_f out_f
  		)
  	    --recursive call
  		copyAllDirsWithFiles in_d out_d
  	)
  )
  
  fn copyDirTree inpath outpath owerwrite:false =
  (
      --check path end slash
  	if inpath [inpath.count ] != "\\" do inpath  += "\\"
  	if outpath[outpath.count] != "\\" do outpath += "\\"
  	
      --check paths
  	if not doesFileExist inpath do return false
  	if not doesFileExist outpath do try (makeDir outpath) catch (return false)
  	
  	--copy main dir files
  	local the_files = getFiles (inpath+"*.*")
  	for in_f in the_files do 
  	(
  		local out_f = outpath + filenameFromPath in_f
  		copyFile in_f out_f
  	)
  	
  	--copy subdirs and files
  	copyAllDirsWithFiles inpath outpath
  	return OK
  )
  

chers

2 Replies

Hi Merlin, if you like, I got a whole set of functions for dealing with files, packed into a struct.

They’re available on IllusionCatalyst MaxScript page under “System Structures”

  • Enrico
1 Reply
(@merlinel)
Joined: 11 months ago

Posts: 0

Hi Enrico , I Must say , Nice Job!!! I like you site
A Lot of Stuff for study, Thanks!