Create folder and file from string on MacOS

tell application "Finder"
	display dialog "File Name:" default answer ""
	set fileNameWithPath to the text returned of result
	if length of fileNameWithPath = 0 then
		return 0
	end if
	set thisFolder to the target of the front window as alias
	set oldDelimiters to AppleScript's text item delimiters
	set AppleScript's text item delimiters to "/"
	set myFolderFileList to every text item of fileNameWithPath
	set AppleScript's text item delimiters to oldDelimiters
	set fileName to the last item of myFolderFileList -- get last item
	if length of myFolderFileList > 1 then
		set myFolderList to myFolderFileList's (items 1 thru -2) --remove last item
		repeat with folderName in myFolderList
			if length of folderName > 0 then
				if (exists folder folderName of thisFolder) is true then
					set newThisFolder to thisFolder & folderName as text
					set thisFolder to newThisFolder as alias
					set thisFolder to make new folder with properties {name:folderName} at thisFolder
				end if
			end if
		end repeat
	end if
	if length of fileName > 0 then
		make new file at thisFolder with properties {name:fileName}
	end if
end tell