Copy Directory if it doesn't already exist

BlitzMax Forums/BlitzMax Programming/Copy Directory if it doesn't already exist

Cobra Blade(Posted 2011) [#1]
I know this should be easy enough... but I just can't seem to grasp it at the moment... :(

So I've got everything within my (OS X) App but of course we don't want the user to save their saves, etc to here.

I've also got some pre-made user files in the App's resource folder. What I want to do is make it so the App checks to see if this folder already exists in the users Application Support folder, if it doesn't it copies this pre-made folder over to Application Support folder.

If anyone could provide me with some sample code to do this that would be super!


Oddball(Posted 2011) [#2]
I recommend you check out Brucey's bah.Volumes module. All the functions you need are in there.
http://code.google.com/p/maxmods/wiki/VolumesModule


Oddball(Posted 2011) [#3]
And because it's the season of giving here's some code.
Import bah.Volumes

Local appSupport:String=GetUserAppDir()+"/MyGame/SaveDir"
Local appResource:String=StripDir(AppFile)+".app/Contents/Resources/SaveDir"
If FileType(appSupport)=0
	CopyDir appResource,appSupport
EndIf


Last edited 2011


Cobra Blade(Posted 2011) [#4]
Thank you kindly for your Christistmas generosity Dave!


ImaginaryHuman(Posted 2011) [#5]
If FileType(Path)=FILETYPE_DIR

?

Would be 0, I believe, if it doesn't exist?


Oddball(Posted 2011) [#6]
Yes. ImaginaryHuman is correct. I made a booboo.
Import bah.Volumes

Local appSupport:String=GetUserAppDir()+"/MyGame/SaveDir"
Local appResource:String=StripDir(AppFile)+".app/Contents/Resources/SaveDir"
If FileType(appSupport)=2
	CopyDir appResource,appSupport
EndIf
Corrected.


Cobra Blade(Posted 2011) [#7]
Thanks ImaginaryHuman.
Thank you both and I hope you both have a very merry Christmas.