查看: 4024|回复: 2

[有事请教] [已经解决]如何用脚本给文件改名?

[复制链接]
梦石
0
星屑
10515
在线时间
1118 小时
注册时间
2015-2-10
回帖
164
发表于 2018-4-6 10:57:47 | 显示全部楼层 |阅读模式

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

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

×
本帖最后由 fbeds 于 2018-4-14 13:10 编辑

如题,就是在游戏进行中给游戏文件夹目录下的某个文件改名……本人脚本盲,不知道该怎么办……
梦石
0
星屑
4399
在线时间
552 小时
注册时间
2017-12-2
回帖
41
发表于 2018-4-6 13:06:41 | 显示全部楼层
本帖最后由 Mehmet 于 2018-4-6 13:08 编辑

如果只是NW.js游戏平台可以参考下我这个.
  1. //=============================================================================
  2. // Mehmet Plugins - file Rename
  3. // Mehmet_fileRename.js
  4. //=============================================================================

  5. /*:
  6. * @plugindesc 基于NW.js游戏平台游戏目录下的文件重命名.
  7. * @author Mehmet
  8. * @version 1.0
  9. *
  10. * @help
  11. * Plugins Command:
  12. * 1.文件移动
  13. *   mehmetFileRename /img/faces/Actor3.png /img/Actor3.png
  14. * 2.文件重命名
  15. *   mehmetFileRename /img/faces/Actor3.png /img/faces/Actor4.png
  16. * 3.文件夹(即有第三个实参)
  17. *   mehmetFileRename /img/Test /img/Test1 true
  18. */


  19. (function() {

  20. var Mehmet = Mehmet || {};
  21. Mehmet.Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
  22. Game_Interpreter.prototype.pluginCommand = function(command, args) {
  23.     Mehmet.Game_Interpreter_pluginCommand.call(this, command, args);
  24.     if (command.toUpperCase() === 'MEHMETFILERENAME') {
  25.         if (Utils.isNwjs() && args[0] && args[1]) {
  26.             if (args[2]) {
  27.                 Mehmet.fileRenamefunction(args[0], args[1], true);
  28.             } else {
  29.                 Mehmet.fileRenamefunction(args[0], args[1]);
  30.             }
  31.         }
  32.     }
  33. };

  34. Mehmet.fileRenamefunction = function(oldPath, newPath) {
  35.     var data = null;
  36.     if (arguments[2]) {
  37.         var fs = require('fs');
  38.         var oldfilePath = this.localFileDirectoryPath(oldPath);
  39.         var newfilePath = this.localFileDirectoryPath(newPath);
  40.     } else {
  41.         var oldfilePath = this.localFileDirectoryPath(oldPath);
  42.         var newfilePath = this.localFileDirectoryPath(newPath);
  43.         var fs = require('fs');
  44.     }
  45.     if (!fs.existsSync(oldfilePath)) {
  46.         return console.log("%c File not found:" + oldfilePath,"color:red;background-color:rgba(58,58,58,1)");
  47.     }
  48.     fs.rename(oldfilePath, newfilePath, function(err) {
  49.         if (err) {
  50.             console.log("%c" + err,"color:yellow;background-color:rgba(58,58,58,1)");
  51.         }
  52.     });
  53. };

  54. Mehmet.localFileDirectoryPath = function(filePath) {
  55.     var path = require('path');
  56.     var filePath = filePath || '';
  57.     var base = path.dirname(process.mainModule.filename);
  58.     return path.join(base, filePath);
  59. };

  60. })();
复制代码
回复

使用道具 举报

梦石
0
星屑
10515
在线时间
1118 小时
注册时间
2015-2-10
回帖
164
 楼主| 发表于 2018-4-6 14:02:23 | 显示全部楼层
Mehmet 发表于 2018-4-6 13:06
如果只是NW.js游戏平台可以参考下我这个.
//=========================================================== ...

谢谢,问题已解决。
回复

使用道具 举报

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

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部