Advertisement
ZNZNCOOP

findFile

Oct 5th, 2014
767
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.73 KB | None | 0 0
  1. function cut(line)
  2.    temp= ""
  3.    for i=0,#line do
  4.    
  5.       temp= string.sub(line,#line-i,#line-i)
  6.       if temp == "/"
  7.       then
  8.          return string.sub(line,#line-i+1,#line)
  9.       end
  10.  
  11.    end
  12. end
  13. -- namefile 1 = name file find
  14. -- namefile 2 = now file
  15. function heavy_version_find(namefile1,namefile2,min_numbersimbol)
  16. if namefile1 == nil or namefile2 == nil
  17. then
  18.    return
  19. end
  20.  
  21. if min_numbersimbol > #namefile1
  22. then
  23.    min_numbersimbol= #namefile1
  24. end
  25.  
  26. if min_numbersimbol == nil
  27. then
  28.    min_numbersimbol= math.floor(#namefile1/3)
  29. end
  30.    l= #namefile1
  31.    v1= ""
  32.    v2= ""
  33.    v3= cut(namefile2)
  34.    c= 0
  35.    for q=1,#namefile1 do
  36.    for i=1,#namefile2 do
  37.           v1= string.sub(namefile1,1,l)
  38.       v2= string.sub(v3,i,i+l-1)
  39.            c=c+1
  40.       if c == 50
  41.       then
  42.          sleep(0)
  43.          c= 0
  44.      end
  45.       if v1 == v2 and l>=min_numbersimbol
  46.       then
  47.          return true
  48.       else
  49.          return false
  50.       end
  51.    end
  52.    l=l-1
  53.  end
  54. end
  55.  
  56.  
  57. function easy_version_find(namefile1,namefile2,min_numbersimbol)
  58. if namefile1 == nil or namefile2 == nil
  59. then
  60.    return
  61. end
  62.  
  63. if min_numbersimbol > #namefile1
  64. then
  65.    min_numbersimbol= #namefile1
  66. end
  67.  
  68. if min_numbersimbol == nil
  69. then
  70.    min_numbersimbol= math.floor(#namefile1/3)
  71. end
  72.    l= #namefile1
  73.    v1= ""
  74.    v2= ""
  75.    v3= cut(namefile2)
  76.    c= 0
  77.    for i=1,#namefile2 do
  78.           v1= string.sub(namefile1,1,l)
  79.       v2= string.sub(v3,i,i+l-1)
  80.            c=c+1
  81.       if c == 50
  82.       then
  83.          sleep(0)
  84.          c= 0
  85.      end
  86.       if v1 == v2 and l>=min_numbersimbol
  87.       then
  88.          return true
  89.       else
  90.          return false
  91.       end
  92.    end
  93. end
  94.  
  95. otvet= {}
  96. function findFile(name,dir_list)
  97.  
  98.    if dir_list == nil
  99.    then
  100.       dir_list= {''}
  101.    end
  102.    if name == nil or name == ' '
  103.    then
  104.       return
  105.    end
  106.    if otvet == nil
  107.    then
  108.       otvet= {}
  109.    end
  110.  
  111.    now_list= {}
  112.    v_list = {}
  113.    count = 0
  114.    for i=1,#dir_list do
  115.           now_list= fs.list(dir_list[i])
  116.           for d=1,#now_list do
  117.                 -- print(dir_list[i]..'/'..now_list[d])
  118.                  now_list[d]= dir_list[i]..'/'..now_list[d]
  119.                
  120.                  if fs.isDir(now_list[d])
  121.                  then
  122.             v_list[#v_list+1]= now_list[d]
  123.             count=count+1
  124.                  end
  125.                  if easy_version_find(name,now_list[d],#name)
  126.                  then
  127.                     otvet[#otvet+1]= now_list[d]
  128.                  end
  129.           end
  130.    end
  131.       if count == 0
  132.       then
  133.          return
  134.       end
  135.       findFile(name,v_list,otvet)
  136.  
  137. end
  138.  
  139. name= "vector"
  140. name= read()
  141. findFile(name,nil,nil)
  142.  
  143.  
  144. for i=1,#otvet do
  145.         print(otvet[i])
  146. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement