neeview一键保存当前图片命名为文件名加图片名


更新日期

2025.04.14
neeview43.2版测试通过

neeview下载

电脑上已经安装了.NET运行库可以下载fd版本,地址:https://github.com/neelabo/NeeView/releases/

neeview开启脚本功能

选项,设置,指令,脚本,使用脚本(开),打开脚本文件夹

neeview一键保存当前图片命名为文件名加图片名

在脚本文件夹新建文件:neeview一键保存当前图片命名为文件名加图片名.nvjs
第15行修改成要保存图片的目录,斜杠要写两遍

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// @name neeview一键保存当前图片命名为文件名加图片名
// @description neeview一键保存当前图片命名为文件名加图片名
// @shortCutKey Ctrl+S
// https://github.com/wangandi520/andyspythonscript
// 版本1.2
// log()函数可以在neeview console中输出信息。在选项,打开脚本控制台
// 脚本用于保存漫画压缩包内的图片到某个位置,保存成功后neeview右下角会弹出提示
// 快捷键默认是Ctrl+S,可以自己修改,在选项,设置,指令,指令设置,拉到最下面,neeview一键保存当前图片命名为文件名加页数,双击,快捷键,如果有叹号是冲突了,点消除冲突,选择脚本名
// 保存图片是原压缩包内的文件,未经过其他处理
// 弹出的命令提示符窗口是修改文件名用的
// 保存图片名不是原图片名,文件名格式:zip文件名_图片相对于zip的相对路径_图片名.扩展名
// 例如压缩包1.zip内包含文件夹2,文件夹2内包含图片3.jpg,保存的文件名就是1_2_3.jpg
// 保存图片的文件夹路径:saveImagePath,注意要双斜杠,文件夹最后不加斜杠
// 例如var saveImagePath = "D:\\漫画截图"
var saveImagePath = "H:\\ecomic截图"

// 从文件名和扩展名,获取文件名,不包括扩展名
function getFileNameWithoutExt(fileName) {
var lastDotIndex = fileName.lastIndexOf('.');
return lastDotIndex === -1 ? fileName : fileName.substring(0, lastDotIndex);
}

// 从文件名和扩展名,获取扩展名,包括点号
function getFileExtension(fileName) {
var lastDotIndex = fileName.lastIndexOf('.');
return lastDotIndex === -1 ? '' : fileName.substring(lastDotIndex);
}

// 从完整路径,获取文件名和扩展名
function getFileNameFromPath(filePath) {
var pathParts = filePath.split('\\');
return pathParts[pathParts.length - 1];
}

// 获取图片在压缩包内的相对路径,文件名,扩展名,并使用下划线代替斜杠
function getRelativeFilePath(zipFilePath, imageFilePath) {
if (imageFilePath.startsWith(zipFilePath)) {
return imageFilePath.substring(zipFilePath.length).replace(/\\/g, '_');
//return filePath.substring(folderPath.length);
}
}

var param01 = {
"Mode": "Original",
"IsOriginalSize": "True",
"IsShowToast": "False",
"OverwriteMode": "AddNumber",
"FileNameMode": "BookPageNumber",
"ExportFolder": saveImagePath
}
// 执行导出图片
nv.Command.ExportImage.Patch(param01).Execute()
// 当前书籍路径,文件名,扩展名
var getBookPath = nv.Book.Path
// 当前书籍文件名,扩展名
var getBookFileName = getFileNameFromPath(nv.Book.Path)
// 当前书籍文件名
var getBookFileNameWithoutSuffix = getFileNameWithoutExt(getBookFileName)
// 当前图片序号,从0开始
var getCurrentPageIndex = nv.Book.ViewPages[0].Index
// 当前图片路径,文件名,扩展名
var getCurrentPagePath = nv.Book.ViewPages[0].Path
// 当前图片文件名,扩展名
var getCurrentPageFileName = getFileNameFromPath(nv.Book.ViewPages[0].Path)
// 当前图片扩展名
var getCurrentPageFileSuffix = getFileExtension(nv.Book.ViewPages[0].Path)
// 当前图片在压缩包内的相对路径
var getCurrentPageRelativePath = getRelativeFilePath(getBookPath, getCurrentPagePath)
// 程序导出的图片的路径
oldFileName = saveImagePath + '\\' + getBookFileNameWithoutSuffix + '_' + getCurrentPageIndex + getCurrentPageFileSuffix
// 要修改成新的文件名,ren命令不加路径,move命令加路径
//newFileName = getBookFileNameWithoutSuffix + getCurrentPageRelativePath
newFileName = saveImagePath + '\\' + getBookFileNameWithoutSuffix + getCurrentPageRelativePath
// 改名,如果有重名的,就覆盖
var cmdPara = ' /c SET "COPYCMD=/Y" && move "' + oldFileName + '" "' + newFileName + '" && echo '
//var cmdPara = ' /c ren "' + oldFileName + '" "' + newFileName + '"'
//var cmdPara = nv.Config.Script.ScriptFolder + '\\neeview一键保存当前图片命名为文件名加图片名.py ' + oldFileName + ' ' + newFileName
var param02 = {
"Command": "cmd.exe",
//"Command": "python.exe",
"Parameter": cmdPara
}
// 两个命令效果相同
nv.Command.OpenExternalApp.Patch(param02).Execute()
//system("cmd.exe", cmdPara)
nv.ShowToast(newFileName + '文件已保存。')

设置快捷键

默认快捷键是Ctrl+S,修改在
选项,设置,指令,指令设置,拉到最下面,neeview一键保存当前图片命名为文件名加页数,双击,快捷键,如果有叹号是冲突了,点消除冲突,选择脚本名
之后Ctrl+S,neeview右下角会显示XX已存储

参考文章

neeview,帮助,脚本说明