static Quote = esc(?+\"+, ?+\+)
static Delim = Quote ++ " " ++ Quote
local Pos = find(x9, Delim)
local One = slice(x9, 2, Pos - 1)
local Two = slice(x9, Pos + 3, length(x9) - 2)
static SNSE = "SwapNames Script Error #"
if(!validpath(One) || !validpath(Two)) do
	messagebox("ok error", "Two files/directories must be selected", SNSE ++ 4)
	quit
endif
if(file.isfolder(One) + file.isfolder(Two) == 1) do
	messagebox("ok error", "Either two files or two directories must be selected", SNSE ++ 5)
	quit
endif
local Ran, Temp
local Path = file.folder(One) ++ esc(?+\\+, ?+\+)
for(1)
	Ran = Ran ++ random(10)
	Temp = Path ++ Ran
	if(!validpath(Temp)) do
		if(!file.move(One, Temp)) do
			messagebox("ok error", "Error moving " ++ One ++ " to " ++ Temp, SNSE ++ 1)
			quit
		endif
		
		if(!file.move(Two, One)) do
			messagebox("ok error", "Error moving " ++ Two ++ " to " ++ One, SNSE ++ 2)
			quit
		endif
		if(!file.move(Temp, Two)) do
			messagebox("ok error", "Error moving " ++ Temp ++ " to " ++ Two, SNSE ++ 3)
			quit
		endif
		win.sendmessage(win.handle("c=TTOTAL_CMD"), 0x400+51, 540, 0)
		quit
	endif
endfor