Create Serial Dir

Started by Hardcoal, August 11, 2024, 19:50:53

Previous topic - Next topic

Hardcoal

Im not sure if it exists on Blitzmax or not, but when I tried to create a Chain of Dirs, It didnt work.
I mean Lets say you want to create in C: Drive This following Directories..    C:/Quake/Maps/User/
Now If Quake dir doest not exist.. it wont Create Maps And users.. Right? 

Well anyways.. I Hope im not making a fool of myself and theirs already a command like this, But this following Function Will Create the Chain of Desired Dirs..

Code: BASIC
	Method CreateSerialDir(SerialDir:String)   			'Example CreateSerialDir("C:\Users\User\Desktop\Test\Banana\Moshe\Apple\")
														'This Creates Dir And Sub Dirs if they dont exist
	 	Local SD:String[100], Char:String, WrdCntr		'Spaces are not Good between name and Slash.. Example:   "Banana \ Moshe\ Apple\" = [Not Good]
		SerialDir = Trim(SerialDir)
		If IsSlash(Right(SerialDir, 1)) = False Then SerialDir = SerialDir + "\"
		For Local I = 1 To Len (SerialDir)
			Char = Mid(SerialDir, I, 1)
			If IsSlash(Char) Then
				SD[WrdCntr] = SD[WrdCntr] + Char
				WrdCntr = WrdCntr + 1
			Else
				SD[WrdCntr] = SD[WrdCntr] + Char
			End If
		Next
		
		Local BuiltDir:String
		For Local DAR:String = EachIn SD
			If DAR.Length > 0 Then
				BuiltDir = BuiltDir + DAR
				If DirectoryExsists(BuiltDir) = False Then
					CreateDir(BuiltDir)
					Print BuiltDir
				End If
			Else
				Exit
			End If
		Next
		
	   '----------------------------------'
	   
			Function IsSlash(Sign:String)
				 If Sign = "\" Then Return True
				 If Sign = "/" Then Return True
			End Function
		
			Function DirectoryExsists(Dir:String)
				Local TempDirHandle
				TempDirHandle = ReadDir(Dir)
				If TempDirHandle > 0 Then
					CloseDir(TempDirHandle)
					Return True
				End If
			End Function
		
	End Method
Things I've done:   https://itch.io/profile/hardcoal  [I keep improving them btw]

dawlane


It should be:
CreateDir("basedir/subdir/subdir2", True)

You've got this and this modules.

Hardcoal

I Used to recall it long time ago.. somehow it skipped my mind.. TY
Things I've done:   https://itch.io/profile/hardcoal  [I keep improving them btw]