* dl shell 批量小写文件名

This commit is contained in:
2025-08-15 00:14:42 +08:00
parent 769d6d4bb8
commit f079fa635f
11 changed files with 69 additions and 10 deletions
+2 -1
View File
@@ -625,7 +625,7 @@ std::string GetExtension(std::string_view path_name, bool has_dot /*= false*/)
return {};
}
std::string GetFilename(std::string_view path_name)
std::string GetFileName(std::string_view path_name)
{
try
{
@@ -1002,4 +1002,5 @@ bool Rename(std::string_view src, std::string_view tar)
return false;
}
}
+26 -1
View File
@@ -51,6 +51,7 @@ namespace dl::File
void GetPathFileAll(std::string_view path, std::vector<std::string>& ret,
std::string_view regex = "", bool recursion = true);
/**
* @brief 获取文件夹当前内容
* @param[in] path 路径
@@ -233,7 +234,7 @@ std::string GetExtension(std::string_view path_name, bool has_dot = false);
* @param[in] path_name
* @note a/b返回b,a/b/返回空
*/
std::string GetFilename(std::string_view path_name);
std::string GetFileName(std::string_view path_name);
/**
* @brief 返回文件名不含后缀
* @param[in] path_name
@@ -346,4 +347,28 @@ std::string PathPublic();
void InitFileSystem();
namespace Lua
{
inline std::vector<std::string> lua_GetPathFileAll_3(std::string_view path, std::string_view regex /*= ""*/, bool recursion /*= true*/)
{
std::vector<std::string> ret;
GetPathFileAll(path, ret, regex, recursion);
return ret;
}
inline std::vector<std::string> lua_GetPathFileAll_2(std::string_view path,
std::string_view regex)
{
std::vector<std::string> ret;
GetPathFileAll(path, ret, regex, true);
return ret;
}
inline std::vector<std::string> lua_GetPathFileAll_1(std::string_view path)
{
std::vector<std::string> ret;
GetPathFileAll(path, ret, "", true);
return ret;
}
}
}
+1 -1
View File
@@ -218,7 +218,7 @@ namespace dl
{
_exe = svn_path;
if (!dl::File::IsExist(_exe)
|| dl::File::GetFilename(svn_path) != "svn.exe")
|| dl::File::GetFileName(svn_path) != "svn.exe")
return false;
return true;
}
+18 -4
View File
@@ -7,6 +7,7 @@
#include "ui/dl_ui_manager.h"
#include <LuaBridge/Array.h>
#include <LuaBridge/Vector.h>
namespace dl
{
@@ -37,7 +38,19 @@ namespace dl
.endClass();
auto result = luabridge::push(L, g_system);
lua_setglobal(L, "system");
lua_setglobal(L, "g_system");
}
void lua_register_file(lua_State* L)
{
using namespace File::Lua;
luabridge::getGlobalNamespace(L)
.beginNamespace("g_file")
.addFunction("GetPathFileAll", &lua_GetPathFileAll_3, &lua_GetPathFileAll_2, &lua_GetPathFileAll_1)
.addFunction("Rename", &File::Rename)
.addFunction("GetFilePath", &File::GetFilePath)
.addFunction("GetFileName", &File::GetFileName)
.endNamespace();
}
void lua_register_gfx(lua_State* L)
@@ -48,7 +61,7 @@ namespace dl
.endClass();
auto result = luabridge::push(L, g_gfx);
lua_setglobal(L, "gfx");
lua_setglobal(L, "g_gfx");
}
void lua_register_ui(lua_State* L)
@@ -73,7 +86,7 @@ namespace dl
.endClass();
auto result = luabridge::push(L, g_ui);
lua_setglobal(L, "ui");
lua_setglobal(L, "g_ui");
}
void lua_register_factory(lua_State* L)
@@ -84,7 +97,7 @@ namespace dl
.endClass();
auto result = luabridge::push(L, g_factory);
lua_setglobal(L, "factory");*/
lua_setglobal(L, "g_factory");*/
}
#if DL_PLATFORM == DL_PLATFORM_WIN32
@@ -102,6 +115,7 @@ namespace dl
{
lua_register_base(L);
lua_register_system(L);
lua_register_file(L);
lua_register_gfx(L);
lua_register_ui(L);
lua_register_factory(L);
+6
View File
@@ -0,0 +1,6 @@
{
"Lua.diagnostics.globals": [
"g_file",
"system"
]
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 359 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 343 B

@@ -1,3 +1,16 @@
local ret_files = g_file.GetPathFileAll("./")
for key, value in pairs(ret_files) do
local path = g_file.GetFilePath(value)
local filename = g_file.GetFileName(value)
local new_name = path .. string.lower(filename)
g_file.Rename(value, new_name)
print(value.."->"..new_name)
end
print "此工具会批量修改当前文件夹的所有文件名为小写"
system "pause"