global counter as integer
if File Exist("AGKCompatible.x")=1
   delete file "AGKCompatible.x"
endif
print "Old File Found.. [Deleted]"
wait 100
print "Creating new file AGKCompatible.x"
open to write 1,"AGKCompatible.x"
open to read 2,"test.x"

while file end(2)=0
   read string 2,data$

      if left$(data$,17)="          Texture"
         Print "Converting Texture Data ["+str$(counter)+"]"
         data2$=trunkstring(data$,".")
         data3$=right$(data2$,len(data2$)-28)
         inc counter,1
         oldfront$=left$(data$,28)+data3$+"."+str$(counter)+right$(data$,6)
         write string 1,oldfront$
         print right$(oldfront$,len(oldfront$)-17)
      else
      write string 1,data$
   endif


endwhile


close file 1
close file 2
print "["+str$(counter)+"] Materials Converted"
print "Pres any key to exit"
Wait key






function trunkstring(string$,val$)

for i = 1 to len(string$)
   if right$(left$(string$,i),1)=val$
      result$=left$(string$,i-1)
   endif
next
endfunction result$