设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 1845|回复: 7
打印 上一主题 下一主题

[已经解决] 很诡异的语法错误,无法解决。

[复制链接]

Lv2.观梦者

铃铃塔的守护者

梦石
0
星屑
626
在线时间
961 小时
注册时间
2010-10-24
帖子
2768

贵宾

跳转到指定楼层
1
发表于 2010-12-21 23:38:21 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
本帖最后由 px.凤翔九天 于 2010-12-22 23:08 编辑

表示这个问题可能有一定难度,成功解答者表示可能会给v。
问题:诡异的语法错误:在我自己写了一点代码后发现出现了诡异的语法错误...而且因为中途没有测试,所以出错后再想找问题所在就找不到了.....估计不是鼠标脚本的问题,也不太可能是转码工具的问题....我自己写的脚本中提到的文件夹均以创建(验证完毕)表示只要不用我写的。其他的都能和谐共存,用我的结果连写个条件分歧都报错......

错误就是我的脚本的31行...完全不知道怎么改...
试着注释掉,结果依然显示31行报错(注释都有错....)
索性删掉,结果其他地方又报错...
于是我带着报错就删的心态处理.....结果...都删掉了...
极其郁闷.....

先发一下使用到的各种诡异代码(喜欢的自己拿去用):
easyconv:
  1. #==============================================================================

  2. # 仭 EasyConv module - Ver 0.90

  3. #--

  4. # Moonlight INN

  5. # http://cgi.members.interq.or.jp/aquarius/rasetsu/

  6. # RaTTiE

  7. # [email protected]

  8. #----------------------

  9. # EasyConv::s2u(text) : S-JIS -> UTF-8

  10. # EasyConv::u2s(text) : UTF-8 -> S-JIS

  11. #==============================================================================

  12. module EasyConv

  13. # API梡掕悢掕媊

  14.   CP_ACP = 0

  15.   CP_UTF8 = 65001

  16. #------------------------------------

  17. # 仠 S-JIS -> UTF-8

  18. #------------------------------------

  19. def s2u(text)

  20. # API掕媊

  21.   m2w = Win32API.new('kernel32', 'MultiByteToWideChar', 'ilpipi', 'i')

  22.   w2m = Win32API.new('kernel32', 'WideCharToMultiByte', 'ilpipipp', 'i')

  23. # S-JIS -> Unicode

  24.   len = m2w.call(CP_ACP, 0, text, -1, nil, 0);

  25.   buf = "\0" * (len*2)

  26.   m2w.call(CP_ACP, 0, text, -1, buf, buf.size/2);

  27. # Unicode -> UTF-8

  28.   len = w2m.call(CP_UTF8, 0, buf, -1, nil, 0, nil, nil);

  29.   ret = "\0" * len

  30.   w2m.call(CP_UTF8, 0, buf, -1, ret, ret.size, nil, nil);

  31.   

  32.   return ret

  33. end

  34. # module_function偲偟偰岞奂

  35. module_function :s2u

  36. #------------------------------------

  37. # 仠 UTF-8 -> S-JIS

  38. #------------------------------------

  39. def u2s(text)

  40. # API掕媊

  41.   m2w = Win32API.new('kernel32', 'MultiByteToWideChar', 'ilpipi', 'i')

  42.   w2m = Win32API.new('kernel32', 'WideCharToMultiByte', 'ilpipipp', 'i')

  43. # UTF-8 -> Unicode

  44.   len = m2w.call(CP_UTF8, 0, text, -1, nil, 0);

  45.   buf = "\0" * (len*2)

  46.   m2w.call(CP_UTF8, 0, text, -1, buf, buf.size/2);

  47. # Unicode -> S-JIS

  48.   len = w2m.call(CP_ACP, 0, buf, -1, nil, 0, nil, nil);

  49.   ret = "\0" * len

  50.   w2m.call(CP_ACP, 0, buf, -1, ret, ret.size, nil, nil);

  51.   

  52.   return ret

  53. end

  54. # module_function偲偟偰岞奂

  55. module_function :u2s

  56. end
复制代码
另外一个不详的转码工具:
  1. #==============================================================================

  2. # ■ String

  3. #------------------------------------------------------------------------------

  4. #  字符串类。可处理任意长度的字节串。(追加编码转换的定义)

  5. #==============================================================================



  6. class String

  7.   #--------------------------------------------------------------------------

  8.   # ● 用来编码 Ruby 字符串、解码 unicode 的 两个 Windows API 函数

  9.   #--------------------------------------------------------------------------

  10.   @@MultiByteToWideChar = Win32API.new("kernel32", "MultiByteToWideChar", ['I', 'L', 'P', 'I', 'P', 'I'], 'I')

  11.   @@WideCharToMultiByte = Win32API.new("kernel32", "WideCharToMultiByte", ['I', 'L', 'P', 'I', 'P', 'I', 'P', 'P'], 'I')

  12.   #--------------------------------------------------------------------------

  13.   # ● 返回将 Ruby UTF-8 字符串对象(本身)编码为 unicode 后的字符串

  14.   #--------------------------------------------------------------------------

  15.   def to_unicode

  16.     len = @@MultiByteToWideChar.call(65001, 0, self, -1, 0, 0) << 1

  17.     buf =" " * len

  18.     # 65001: UTF-8 字符集编码(代码页)

  19.     @@MultiByteToWideChar.call(65001, 0, self, -1, buf, len)

  20.     return buf

  21.   end

  22.   #--------------------------------------------------------------------------

  23.   # ● 返回将编码为 unicode 的字符串对象(本身)解码为 UTF-8 后的字符串

  24.   #--------------------------------------------------------------------------

  25.   def to_UTF8

  26.     len = @@WideCharToMultiByte.call(65001, 0, self, -1, 0, 0, 0, 0)

  27.     buf =" " * len

  28.     @@WideCharToMultiByte.call(65001, 0, self, -1, buf, len, 0, 0)

  29.     # 去掉 '\0' 字符串结束符(因为转换之后仅仅用于 Ruby 字符串)

  30.     buf.slice!(-1, 1)

  31.     return buf

  32.   end

  33. end



  34. FindFirstFile = Win32API.new("kernel32", "FindFirstFileW", "PP", "L")

  35. FindNextFile = Win32API.new("kernel32", "FindNextFileW", "LP", "I")



  36. filenames = []

  37. findFileData = " " * 592



  38. hFindFile = FindFirstFile.call(

  39. "*".to_unicode, findFileData)



  40. while FindNextFile.call(hFindFile, findFileData) != 0

  41.   filenames.push(findFileData[44, 45 + 260 * 2].to_UTF8)

  42. end



复制代码
为判断文件名为中文的定义方法:filetest.exists?
  1. PathFileExists = Win32API.new("shlwapi", "PathFileExistsW", "P", "I")

  2. MultiByteToWideChar = Win32API.new("kernel32", "MultiByteToWideChar", "ILPIPI", "I")

  3. def FileTest.exists?(filename)

  4.   len = MultiByteToWideChar.call(65001, 0, filename, -1, 0, 0) << 1

  5.   buf = " " * len

  6.   MultiByteToWideChar.call(65001, 0, filename, -1, buf, len)

  7.   return PathFileExists.call(buf) == 0 ? false : true

  8. end

  9. 删除文件夹的脚本:
  10. [code]module Kernel
  11.         def deleteDir(dirname)
  12.                 Dir.foreach(dirname) { |filename|
  13.                         next if(filename == ".." || filename == ".")
  14.                         path = dirname + File::SEPARATOR + filename
  15.                         if(File.ftype(path) == "directory")
  16.                                 deleteDir(path)
  17.                         else
  18.                                 File.delete(path)
  19.                         end
  20.                 }
  21.                 Dir.delete(dirname)
  22.         end
  23. end
复制代码
复制文件夹的写法(里面是例子:复制data文件夹到桌面)
  1. class String
  2.     @@MultiByteToWideChar = Win32API.new("kernel32", "MultiByteToWideChar", ['I', 'L', 'P', 'I', 'P', 'I'], 'I')
  3.     def to_unicode
  4.         len = @@MultiByteToWideChar.call(65001, 0, self, -1, 0, 0) << 1
  5.         buf =" " * len
  6.         @@MultiByteToWideChar.call(65001, 0, self, -1, buf, len)
  7.         return buf
  8.     end
  9. end

  10. sh_file_operation = Win32API.new('shell32', 'SHFileOperationW', 'P', 'i')

  11. src = "./Data"
  12. xx="桌面"
  13. dest = "C:/Documents and Settings/Administrator/#{xx}"

  14. op_struct = [0, 2, src.to_unicode, dest.to_unicode, 4 | 0x10 | 0x0200, 0, 0, 0].pack('iIppSiii')
  15. sh_file_operation.call(op_struct)
复制代码
鼠标脚本:
  1. #===========================================================
  2. #===================
  3. # 本脚本来自http://rpg.blue/web/,使用和转载请保留此信息
  4. #==============================================================================

  5. #=================以下两个用来调整战斗时的手感问题,可以自己试试。
  6. $敌人选框扩大 = 20
  7. $角色选框扩大 = 30


  8. #==============================================================================
  9. # API调用
  10. #==============================================================================
  11. $ShowCursor = Win32API.new("user32", "ShowCursor", 'i', 'l')
  12. $GetCursorPos = Win32API.new("user32", "GetCursorPos", 'p', 'i')
  13. $ScreenToClient = Win32API.new("user32", "ScreenToClient", 'ip', 'i')
  14. $GetActiveWindow = Win32API.new("user32", "GetActiveWindow", nil, 'l')
  15. $Window_HWND = $GetActiveWindow.call
  16. $GetKeyState = Win32API.new("user32", "GetKeyState", 'i', 'i')
  17. #$FindWindow = Win32API.new("user32", "FindWindow", 'pp', 'i')
  18. #$HookStart  = Win32API.new("mouse_hook.dll", "HookStart", 'i', nil)
  19. #$HookEnd  = Win32API.new("mouse_hook.dll", "HookEnd", nil, nil)
  20. #$GetMouseStatus  = Win32API.new("mouse_hook.dll", "GetMouseStatus", 'i', 'i')
  21. #$Window_HWND = $FindWindow.call(nil, 'mousetry')

  22. module Mouse  
  23.   LEFT = 0x01
  24.   RIGHT = 0x02

  25.   def self.init(sprite = nil)
  26. #   $HookStart.call($Window_HWND)
  27.     $ShowCursor.call(0)
  28.    
  29.     @show_cursor = false
  30.    
  31.     @mouse_sprite = Sprite.new
  32.     @mouse_sprite.z = 99999
  33.     @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/cursor1.png')
  34.     #@mouse_sprite.bitmap.fill_rect(Rect.new(0, 0, 32, 32), Color.new(0, 0, 0))

  35.     @left_press = false
  36.     @right_press = false
  37.     @left_trigger = false
  38.     @right_trigger = false
  39.     @left_repeat = false
  40.     @right_repeat = false
  41.     @click_lock = false
  42.    
  43.     update
  44.   end
  45.   def self.exit
  46.     @mouse_sprite.bitmap.dispose
  47.     @mouse_sprite.dispose
  48.     @show_cursor = true
  49. #    $HookEnd.call
  50.     $ShowCursor.call(1)
  51.   end
  52.   def self.mouse_debug
  53.     return @mouse_debug.bitmap
  54.   end
  55.   def self.update
  56.     left_down = $GetKeyState.call(0x01)
  57.     right_down = $GetKeyState.call(0x02)
  58.    
  59.     @click_lock = false
  60.     mouse_x, mouse_y = self.get_mouse_pos
  61.     if @mouse_sprite != nil
  62.       @mouse_sprite.x = mouse_x
  63.       @mouse_sprite.y = mouse_y
  64.     end
  65.     if left_down[7] == 1
  66.       @left_repeat = (not @left_repeat)
  67.       @left_trigger = (not @left_press)
  68.       @left_press = true
  69.     else
  70.       @left_press = false
  71.       @left_trigger = false
  72.       @left_repeat = false
  73.     end
  74.     if right_down[7] == 1
  75.       @right_repeat = (not @right_repeat)
  76.       @right_trigger = (not @right_press)
  77.       @right_press = true
  78.     else
  79.       @right_press = false
  80.       @right_trigger = false
  81.       @right_repeat = false
  82.     end
  83.   end
  84.   def self.get_mouse_pos
  85.     point_var = [0, 0].pack('ll')
  86.     if $GetCursorPos.call(point_var) != 0
  87.       if $ScreenToClient.call($Window_HWND, point_var) != 0
  88.         x, y = point_var.unpack('ll')
  89.         if (x < 0) or (x > 10000) then x = 0 end
  90.         if (y < 0) or (y > 10000) then y = 0 end
  91.         if x > 640 then x = 640 end
  92.         if y > 480 then y = 480 end
  93.         return x, y
  94.       else
  95.         return 0, 0
  96.       end
  97.     else
  98.       return 0, 0
  99.     end
  100.   end
  101.   def self.press?(mouse_code)
  102.     if mouse_code == LEFT
  103.       if @click_lock
  104.         return false
  105.       else
  106.         return @left_press
  107.       end
  108.     elsif mouse_code == RIGHT
  109.       return @right_press
  110.     else
  111.       return false
  112.     end
  113.   end
  114.   def self.trigger?(mouse_code)
  115.     if mouse_code == LEFT
  116.       if @click_lock
  117.         return false
  118.       else
  119.         return @left_trigger
  120.       end
  121.     elsif mouse_code == RIGHT
  122.       return @right_trigger
  123.     else
  124.       return false
  125.     end
  126.   end
  127.   def self.repeat?(mouse_code)
  128.     if mouse_code == LEFT
  129.       if @click_lock
  130.         return false
  131.       else
  132.         return @left_repeat
  133.       end
  134.     elsif mouse_code == RIGHT
  135.       return @right_repeat
  136.     else
  137.       return false
  138.     end
  139.   end
  140.   def self.click_lock?
  141.     return @click_lock
  142.   end
  143.   def self.click_lock
  144.     @click_lock = true
  145.   end
  146.   def self.click_unlock
  147.     @click_lock = false
  148.   end
  149. end
  150. module Input
  151.   if @self_update == nil
  152.     @self_update = method('update')
  153.     @self_press = method('press?')
  154.     @self_trigger = method('trigger?')
  155.     @self_repeat = method('repeat?')
  156.   end
  157.   def self.update
  158.     @self_update.call
  159.     Mouse.update
  160.   end
  161.   def self.press?(key_code)
  162.     if @self_press.call(key_code)
  163.       return true
  164.     end
  165.     if key_code == C
  166.       return Mouse.press?(Mouse::LEFT)
  167.     elsif key_code == B
  168.       return Mouse.press?(Mouse::RIGHT)
  169.     else
  170.       return @self_press.call(key_code)
  171.     end
  172.   end
  173.   def self.trigger?(key_code)
  174.     if @self_trigger.call(key_code)
  175.       return true
  176.     end
  177.     if key_code == C
  178.       return Mouse.trigger?(Mouse::LEFT)
  179.     elsif key_code == B
  180.       return Mouse.trigger?(Mouse::RIGHT)
  181.     else
  182.       return @self_trigger.call(key_code)
  183.     end
  184.   end
  185.   def self.repeat?(key_code)
  186.     if @self_repeat.call(key_code)
  187.       return true
  188.     end
  189.     if key_code == C
  190.       return Mouse.repeat?(Mouse::LEFT)
  191.     elsif key_code == B
  192.       return Mouse.repeat?(Mouse::RIGHT)
  193.     else
  194.       return @self_repeat.call(key_code)
  195.     end
  196.   end
  197. end
  198. class Window_Selectable
  199.   if @self_alias == nil
  200.     alias self_update update
  201.     @self_alias = true
  202.   end
  203.   def update
  204.     #self.cursor_rect.empty
  205.     self_update
  206.     if self.active and @item_max > 0
  207.       index_var = @index
  208.       tp_index = @index
  209.       mouse_x, mouse_y = Mouse.get_mouse_pos
  210.       mouse_not_in_rect = true
  211.       for i in 0...@item_max
  212.         @index = i
  213.         update_cursor_rect
  214.         top_x = self.cursor_rect.x + self.x + 16
  215.         top_y = self.cursor_rect.y + self.y + 16
  216.         bottom_x = top_x + self.cursor_rect.width
  217.         bottom_y = top_y + self.cursor_rect.height
  218.         if (mouse_x > top_x) and (mouse_y > top_y) and
  219.            (mouse_x < bottom_x) and (mouse_y < bottom_y)
  220.           mouse_not_in_rect = false
  221.           if tp_index != @index
  222.             tp_index = @index
  223.             $game_system.se_play($data_system.cursor_se)
  224.           end
  225.           break
  226.         end
  227.       end
  228.       if mouse_not_in_rect
  229.         @index = index_var
  230.         update_cursor_rect
  231.         Mouse.click_lock
  232.       else
  233.         Mouse.click_unlock               
  234.       end
  235.     end
  236.   end
  237. end
  238. class Window_NameInput
  239.   if @self_alias == nil
  240.     alias self_update update
  241.     @self_alias = true
  242.   end
  243.   def update
  244.     #self.cursor_rect.empty
  245.     self_update
  246.     if self.active
  247.       index_var = @index
  248.       mouse_x, mouse_y = Mouse.get_mouse_pos
  249.       mouse_not_in_rect = true
  250.       for i in (0...CHARACTER_TABLE.size).to_a.push(180)
  251.         @index = i
  252.         update_cursor_rect
  253.         top_x = self.cursor_rect.x + self.x + 16
  254.         top_y = self.cursor_rect.y + self.y + 16
  255.         bottom_x = top_x + self.cursor_rect.width
  256.         bottom_y = top_y + self.cursor_rect.height
  257.         #
  258.         if (mouse_x > top_x) and (mouse_y > top_y) and
  259.            (mouse_x < bottom_x) and (mouse_y < bottom_y)
  260.           mouse_not_in_rect = false
  261.           break
  262.         end
  263.       end
  264.       if mouse_not_in_rect
  265.         @index = index_var
  266.         update_cursor_rect
  267.         Mouse.click_lock
  268.       else
  269.         Mouse.click_unlock
  270.       end
  271.     end
  272.   end
  273. end
  274. class Window_InputNumber
  275.   if @self_alias == nil
  276.     alias self_update update
  277.     @self_alias = true
  278.   end
  279.   def update
  280.     #self.cursor_rect.empty
  281.     self_update
  282.     mouse_x, mouse_y = Mouse.get_mouse_pos
  283.     if self.active and @digits_max > 0
  284.       index_var = @index
  285.       mouse_not_in_rect = true
  286.       for i in 0...@digits_max
  287.         @index = i
  288.         update_cursor_rect
  289.         top_x = self.cursor_rect.x + self.x + 16
  290.         bottom_x = top_x + self.cursor_rect.width
  291.         #
  292.         if (mouse_x > top_x) and (mouse_x < bottom_x)
  293.           mouse_not_in_rect = false
  294.           break
  295.         end
  296.       end
  297.       if mouse_not_in_rect
  298.         @index = index_var
  299.         update_cursor_rect
  300.         Mouse.click_lock
  301.       else
  302.         Mouse.click_unlock
  303.       end
  304.     end
  305.     if @last_mouse_y == nil
  306.       @last_mouse_y = mouse_y
  307.     end
  308.     check_pos = (@last_mouse_y - mouse_y).abs
  309.     if check_pos > 10
  310.       $game_system.se_play($data_system.cursor_se)
  311.       place = 10 ** (@digits_max - 1 - @index)
  312.       n = @number / place % 10
  313.       @number -= n * place
  314.       n = (n + 1) % 10 if mouse_y < @last_mouse_y
  315.       n = (n + 9) % 10 if mouse_y > @last_mouse_y
  316.       @number += n * place
  317.       refresh
  318.       @last_mouse_y = mouse_y
  319.     end
  320.   end
  321. end
  322. class Scene_File
  323.   if @self_alias == nil
  324.     alias self_update update
  325.     @self_alias = true
  326.   end
  327.   def update
  328.     mouse_x, mouse_y = Mouse.get_mouse_pos
  329.     Mouse.click_lock
  330.     idx = 0
  331.     for i in @savefile_windows
  332.       top_x = i.x + 16
  333.       top_y = i.y + 16
  334.       bottom_x = top_x + i.width
  335.       bottom_y = top_y + i.height
  336.       if (mouse_x > top_x) and (mouse_y > top_y) and
  337.          (mouse_x < bottom_x) and (mouse_y < bottom_y)
  338.         i.selected = true
  339.         if @file_index != idx
  340.           @file_index = idx
  341.           $game_system.se_play($data_system.cursor_se)
  342.         end            
  343.         Mouse.click_unlock
  344.       else
  345.         i.selected = false
  346.       end
  347.       idx += 1
  348.     end
  349.     self_update
  350.   end
  351. end
  352. class Arrow_Enemy
  353.   if @self_alias == nil
  354.     alias self_update update
  355.     @self_alias = true
  356.   end
  357.   def update
  358.     mouse_x, mouse_y = Mouse.get_mouse_pos
  359.     idx = 0
  360.     for i in $game_troop.enemies do
  361.       if i.exist?
  362.         top_x = i.screen_x - self.ox
  363.         top_y = i.screen_y - self.oy
  364.         bottom_x = top_x + self.src_rect.width
  365.         bottom_y = top_y + self.src_rect.height
  366.         if (mouse_x > top_x - $敌人选框扩大) and (mouse_y > top_y - $敌人选框扩大) and
  367.            (mouse_x < bottom_x + $敌人选框扩大) and (mouse_y < bottom_y + $敌人选框扩大)
  368.           if @index != idx
  369.             $game_system.se_play($data_system.cursor_se)
  370.             @index = idx
  371.           end
  372.         end
  373.       end
  374.       idx += 1
  375.     end
  376.     self_update
  377.   end
  378. end
  379. class Arrow_Actor
  380.   if @self_alias == nil
  381.     alias self_update update
  382.     @self_alias = true
  383.   end
  384.   def update
  385.     mouse_x, mouse_y = Mouse.get_mouse_pos
  386.     idx = 0
  387.     for i in $game_party.actors do
  388.       if i.exist?
  389.         top_x = i.screen_x - self.ox
  390.         top_y = i.screen_y - self.oy
  391.         bottom_x = top_x + self.src_rect.width
  392.         bottom_y = top_y + self.src_rect.height
  393.         if (mouse_x > top_x - $角色选框扩大) and (mouse_y > top_y - $角色选框扩大) and
  394.            (mouse_x < bottom_x + $角色选框扩大) and (mouse_y < bottom_y + $角色选框扩大)
  395.           if @index != idx
  396.             $game_system.se_play($data_system.cursor_se)
  397.             @index = idx
  398.           end
  399.         end
  400.       end
  401.       idx += 1
  402.     end
  403.     self_update
  404.   end
  405. end
  406. class Game_Player
  407.   if @self_alias == nil
  408.     alias self_update update
  409.     @self_alias = true
  410.   end
  411.   def update
  412.     mouse_x, mouse_y = Mouse.get_mouse_pos

  413.     if @last_move_x == nil
  414.       @last_move_x = false
  415.     end
  416.     if Mouse.press?(Mouse::LEFT)
  417.       last_moving = moving?
  418.       last_direction = @direction
  419.       unless moving? or $game_system.map_interpreter.running? or
  420.              @move_route_forcing or $game_temp.message_window_showing
  421.         last_x = @x
  422.         if @last_move_x
  423.           @last_move_x = false
  424.         elsif mouse_x > screen_x + 16
  425.           move_right
  426.         elsif mouse_x < screen_x - 16
  427.           move_left
  428.         end
  429.         last_y = @y
  430.         if last_x != @x
  431.           @last_move_x = true
  432.         elsif mouse_y > screen_y
  433.           move_down
  434.         elsif mouse_y < screen_y - 32
  435.           move_up
  436.         end
  437.         if last_y != @y
  438.           @last_move_x = false
  439.         elsif not @last_move_x
  440.           case last_direction
  441.           when 2
  442.             turn_down
  443.           when 4
  444.             turn_left
  445.           when 6
  446.             turn_right
  447.           when 8
  448.             turn_up
  449.           end
  450.         end
  451.       end
  452.     end
  453.     self_update
  454.   end
  455. end
  456. Mouse.init
  457. END { Mouse.exit }




  458. #==============================================================================
  459. # 本脚本来自http://rpg.blue/web/,使用和转载请保留此信息
  460. #==============================================================================
复制代码
完美输入法(多次测试不是这个的问题,外加脚本太长,就不复制过来了。)

最后:
我的问题写法:
  1. def traverse(path)
  2.   if FileTest.directory?(path)
  3.     dir=Dir.open(path)
  4.     while name = dir.read
  5.       next if name=="."
  6.       next if name==".."
  7.       traverse(path + "/" + name)
  8.     end
  9.     dir.close
  10.   else
  11.     process_file(path)
  12.   end
  13. end

  14. def process_file(path)
  15.   if File.extname(path)==".txt"
  16.     f = File.open(path, "rb")
  17.     vs = f.readlines
  18.     f.close
  19.     yearcycle=2000
  20.     monthcycle=1
  21.     loop do
  22.       if vs.include?("#{yearcycle}年#{monthcycle}月")==true
  23.         path_to_add=nil
  24.         path_from=File.dirname(path)
  25.         path_from_final=File.basename(path_from)
  26.         if FileTest.exists?("C:/Documents and Settings/Administrator/#{EasyConv::u2s(bingzhiname)}/#{yearcycle}-#{monthcycle}") == false
  27.           fullpath="C:/Documents and Settings/Administrator/#{EasyConv::u2s(bingzhiname)}/#{yearcycle}.#{monthcycle}"
  28.           system("md #{fullpath})
  29.         end
  30. if FileTest.exists?("C:/Documents and Settings/Administrator/桌面/文件夹/#{yearcycle}.#{monthcycle}/#{path_from_final}") == true
  31.             path_to_add="重名文件夹"
  32.             end
  33. src = "#{path_from}"
  34. dest = "C:/Documents and Settings/Administrator/桌面/文件夹/#{yearcycle}-#{monthcycle}/#{path_to_add}"
  35. op_struct = [0, 2, src.to_unicode, dest.to_unicode, 4 | 0x10 | 0x0200, 0, 0, 0].pack('iIppSiii')
  36. sh_file_operation.call(op_struct)


  37.           break
  38.         else
  39.           if monthcycle!=12
  40.             monthcycle+=1
  41.           else
  42.             yearcycle+=1
  43.             monthcycle=1
  44.           end
  45.         end
  46.       end
  47.     else
  48.     end
  49.   end
  50.   
复制代码

Lv2.观梦者

梦石
0
星屑
491
在线时间
339 小时
注册时间
2010-12-15
帖子
926

开拓者

2
发表于 2010-12-22 00:31:30 | 只看该作者
基本都是和字符有关系的,估计是乱码造成的

点评

所以...搞不定了...不加那个什么都好,貌似我给出的脚本无冲突...只有我写的有问题...  发表于 2010-12-22 21:45
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
110
在线时间
953 小时
注册时间
2007-4-25
帖子
805
3
发表于 2010-12-22 02:26:42 | 只看该作者
29行:
  1. system("md #{fullpath})
复制代码
看见错误冇?

点评

这错误很容易让人纠结……  发表于 2010-12-22 14:41
[email protected]:~> repeat 1 fortune
Matz is nice, so we are nice.
回复 支持 反对

使用道具 举报

Lv2.观梦者

铃铃塔的守护者

梦石
0
星屑
626
在线时间
961 小时
注册时间
2010-10-24
帖子
2768

贵宾

4
 楼主| 发表于 2010-12-22 22:50:55 | 只看该作者
回复 苏小脉 的帖子

话说不是这个问题...出错的行不是这个....话说这个用法貌似诡异,实际是deathking给我的方法
原地址:http://rpg.blue/thread-161374-1-1.html   
里面还有deathking给出的解说。貌似没问题。
应该是其他问题....希望你继续看....貌似不是冲突问题。因为只要把我那个脚本去掉,一切功能相当完善。祈求继续研究....貌似逻辑没错啊...报错说的是syntax error(语法错误。。)但是完全没找到语法错误。(觉得错的话请先看一下上面我给出的复制 删除目录的脚本)
我写的这个功能是这样的。找到photo文件夹中的所有文件(包括子目录中的文件),如果文件为txt(后缀判定),那么打开txt,判断里面的信息(格式应为“2009-5”这类,前面为年,后面为月)然后在桌面创建文件夹,在其中按txt中的月份创建对应名的文件夹,并把含有那个对应txt的文件夹复制到创建的文件夹中....貌似我说的不是很明白...你看看能不能改良到不报错版或换一种写法来搞定相同的问题。谢谢。

魔法麻将独立游戏制作中,欢迎热情的测试员与UI设计师合作开发~
回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
1070
在线时间
1564 小时
注册时间
2008-7-30
帖子
4418

贵宾

5
发表于 2010-12-22 23:00:38 | 只看该作者
本帖最后由 DeathKing 于 2010-12-22 23:00 编辑

试试先修正29行的错误再运行一下。

See FScript Here:https://github.com/DeathKing/fscript
潜心编写URG3中。
所有对URG3的疑问和勘误或者建议,请移步至发布页面。
欢迎萌妹纸催更
回复 支持 反对

使用道具 举报

Lv2.观梦者

铃铃塔的守护者

梦石
0
星屑
626
在线时间
961 小时
注册时间
2010-10-24
帖子
2768

贵宾

6
 楼主| 发表于 2010-12-22 23:06:54 | 只看该作者
本帖最后由 px.凤翔九天 于 2010-12-22 23:07 编辑

回复 DeathKing 的帖子

呃呃呃,居然神奇的好使了!!!难道这么纠结的代码居然死在了我的一个小小的疏忽....郁闷....细节决定成败啊...谢谢了。果然好使了。(但是明明报错是不是这行啊....)
(话说你们眼睛都好尖....我怎么就是挑不到啊...好不容易记住数end了...这次搞的忘了数",一定改....)

魔法麻将独立游戏制作中,欢迎热情的测试员与UI设计师合作开发~
回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
1070
在线时间
1564 小时
注册时间
2008-7-30
帖子
4418

贵宾

7
发表于 2010-12-22 23:08:35 | 只看该作者
回复 px.凤翔九天 的帖子

控件的语法高亮很好用……
仔细看看,缺那么一个单引号,解释器的分析和编辑器的着色方案就不一样了。

点评

恩恩,很对,但是我的显示屏亮度设置貌似太低(保护眼睛...)高亮我也看不到...着色...因为那个代码中对字符串的处理很多,结果诡异的上了色.....  发表于 2010-12-22 23:11

See FScript Here:https://github.com/DeathKing/fscript
潜心编写URG3中。
所有对URG3的疑问和勘误或者建议,请移步至发布页面。
欢迎萌妹纸催更
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
110
在线时间
953 小时
注册时间
2007-4-25
帖子
805
8
发表于 2010-12-22 23:16:32 | 只看该作者
回复 px.凤翔九天 的帖子

不用看你具体的代码,看到 29 行就足够了。29 行有一个双引号,这对于 Ruby 解析器来说是一个字符串字元的开始,直到下一个双引号出现而结束。由于 29 行的双引号只有一个(实际上是你少打了一个),所以 31 行的第一个双引号就成了字符串字元的结尾,而后面的 C:/Documents and Settings/ 自然就被当做字符串以外的字元来处理了。Ruby 解析器在接收一个字符串字元后,下一个可接收的字元有不少,如空格,换行,调用 String 的方法等,但绝对没有直接跟着一个常量 C 的语法,所以这里就有了语法错误。

点评

也对啊,怪不得我把报错的那行注释掉还是那行报错...  发表于 2010-12-22 23:19
原来如此,上面少了一个引号导致电脑自己去找下一个,就把我的路径的引号给带走了,所以就错误了啊....看来下次发现语法错误不能只看那一行啊。  发表于 2010-12-22 23:19
[email protected]:~> repeat 1 fortune
Matz is nice, so we are nice.
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-6-3 09:54

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表