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

Project1

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

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

[复制链接]

Lv4.逐梦者

梦石
0
星屑
7048
在线时间
880 小时
注册时间
2015-2-10
帖子
248
跳转到指定楼层
1
发表于 2018-4-6 10:57:47 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

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

如题,就是在游戏进行中给游戏文件夹目录下的某个文件改名……本人脚本盲,不知道该怎么办……

Lv3.寻梦者

梦石
0
星屑
4344
在线时间
552 小时
注册时间
2017-12-2
帖子
41
2
发表于 2018-4-6 13:06:41 | 只看该作者
本帖最后由 Mehmet 于 2018-4-6 13:08 编辑

如果只是NW.js游戏平台可以参考下我这个.
JAVASCRIPT 代码复制
  1. //=============================================================================
  2. // Mehmet Plugins - file Rename
  3. // Mehmet_fileRename.js
  4. //=============================================================================
  5.  
  6. /*:
  7.  * @plugindesc 基于NW.js游戏平台游戏目录下的文件重命名.
  8.  * @author Mehmet
  9.  * @version 1.0
  10.  *
  11.  * @help
  12.  * Plugins Command:
  13.  * 1.文件移动
  14.  *   mehmetFileRename /img/faces/Actor3.png /img/Actor3.png
  15.  * 2.文件重命名
  16.  *   mehmetFileRename /img/faces/Actor3.png /img/faces/Actor4.png
  17.  * 3.文件夹(即有第三个实参)
  18.  *   mehmetFileRename /img/Test /img/Test1 true
  19.  */
  20.  
  21.  
  22. (function() {
  23.  
  24. var Mehmet = Mehmet || {};
  25. Mehmet.Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
  26. Game_Interpreter.prototype.pluginCommand = function(command, args) {
  27.     Mehmet.Game_Interpreter_pluginCommand.call(this, command, args);
  28.     if (command.toUpperCase() === 'MEHMETFILERENAME') {
  29.         if (Utils.isNwjs() && args[0] && args[1]) {
  30.             if (args[2]) {
  31.                 Mehmet.fileRenamefunction(args[0], args[1], true);
  32.             } else {
  33.                 Mehmet.fileRenamefunction(args[0], args[1]);
  34.             }
  35.         }
  36.     }
  37. };
  38.  
  39. Mehmet.fileRenamefunction = function(oldPath, newPath) {
  40.     var data = null;
  41.     if (arguments[2]) {
  42.         var fs = require('fs');
  43.         var oldfilePath = this.localFileDirectoryPath(oldPath);
  44.         var newfilePath = this.localFileDirectoryPath(newPath);
  45.     } else {
  46.         var oldfilePath = this.localFileDirectoryPath(oldPath);
  47.         var newfilePath = this.localFileDirectoryPath(newPath);
  48.         var fs = require('fs');
  49.     }
  50.     if (!fs.existsSync(oldfilePath)) {
  51.         return console.log("%c File not found:" + oldfilePath,"color:red;background-color:rgba(58,58,58,1)");
  52.     }
  53.     fs.rename(oldfilePath, newfilePath, function(err) {
  54.         if (err) {
  55.             console.log("%c" + err,"color:yellow;background-color:rgba(58,58,58,1)");
  56.         }
  57.     });
  58. };
  59.  
  60. Mehmet.localFileDirectoryPath = function(filePath) {
  61.     var path = require('path');
  62.     var filePath = filePath || '';
  63.     var base = path.dirname(process.mainModule.filename);
  64.     return path.join(base, filePath);
  65. };
  66.  
  67. })();
回复 支持 反对

使用道具 举报

Lv4.逐梦者

梦石
0
星屑
7048
在线时间
880 小时
注册时间
2015-2-10
帖子
248
3
 楼主| 发表于 2018-4-6 14:02:23 | 只看该作者
Mehmet 发表于 2018-4-6 13:06
如果只是NW.js游戏平台可以参考下我这个.
//=========================================================== ...

谢谢,问题已解决。
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-5-3 08:46

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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