首页
社区
课程
招聘
[分享]能把文件或文件夹重命命为任意文件名工具All Name
发表于: 2009-12-13 23:03 2417

[分享]能把文件或文件夹重命命为任意文件名工具All Name

2009-12-13 23:03
2417
All Name的意思是所有名字都可以,是一个文件/文件夹改名工具,和其他改名工具的区别就是这个工具是All Name,而其他工具不是
只支持XP

为什么只支持XP?
因为VISTA及以上读写磁盘需要驱动,而这个程序的接口只是ring3的

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include <FileCtrl.hpp>
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
typedef int (* FS_RENAMEFILE)(const wchar_t * path,const wchar_t * NewName);//重命名文件
FS_RENAMEFILE allname;
typedef BYTE * (* FSREAD)(LARGE_INTEGER base,DWORD size) ;
typedef bool (* FSWRITE)(LARGE_INTEGER base,DWORD size,BYTE * mem) ;
typedef bool ( * FS_PRE_READ)(FSREAD FSIO_READ); //定义读
typedef bool ( * FS_PRE_WRITE)(FSWRITE FSIO_WRITE); //定义写
FS_PRE_READ read;
FS_PRE_WRITE write;

bool SaveResToFile(LPCSTR ResName, LPCSTR ResType, LPCSTR FileName); //资源释放 FS.DLL



HANDLE hDev=NULL,hFile=NULL; //读写句柄
BYTE * buffer=new BYTE[0x40000]; //BUFFER,大点没关系
HINSTANCE DLLInst = NULL; //DLL句柄
BYTE * Read(LARGE_INTEGER a,DWORD b) //读函数内容 ,具体内容没什么好讲的,就是根据偏移,读取指定大小
{
if (hDev!=INVALID_HANDLE_VALUE)
{
DWORD dwRet;
SetFilePointer(hDev,a.LowPart,&a.HighPart,FILE_BEGIN);
ReadFile(hDev,buffer,b,&dwRet,0);
}
return buffer;
}

bool Write(LARGE_INTEGER a,DWORD b,Byte * mem) //写函数,如果用驱动实现的话那么VISTA及以上也可以支持
{
if (hFile!=INVALID_HANDLE_VALUE)
{
DWORD dwRet;
SetFilePointer(hFile,a.LowPart,&a.HighPart,FILE_BEGIN);
dwRet=WriteFile(hFile,mem,b,&dwRet,0);
if(dwRet==0)
{
MessageBox(Form1->Handle,"写入失败。","出错了",0);
}
}
else
{

}
return 1;
}

void __fastcall TForm1::Edit1Exit(TObject *Sender)
{
if(Form1->Edit1->Text==""){Form1->Edit1->Text="请输入待重命名文件/夹";}
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Edit1Enter(TObject *Sender)
{
if(Form1->Edit1->Text=="请输入待重命名文件/夹"){Form1->Edit1->Text="";}
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
if (Form1->OpenDialog1->Execute())
{
if (Form1->OpenDialog1->FileName!="")
{
Form1->Edit1->Text=Form1->OpenDialog1->FileName;
}
}
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button4Click(TObject *Sender)
{
String Path="";
if (SelectDirectory("请选择目录",L"",Path))
{
Form1->Edit1->Text=Path;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
String y=InputBox("Hello","New Name?",""); //输入新的名字
if(y==""){return;}
String path=Form1->Edit1->Text;
if(path==""){MessageBox(Form1->Handle,"哪个文件需要改名字?","出错了",0);return;}
if(path.SubString(2,1)!=":"){MessageBox(Form1->Handle,"不认识路了。","出错了",0);return;}
String temp="\\\\.\\";
temp=temp+path.SubString(1,2);
hDev=CreateFile(temp.c_str(),GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ | FILE_SHARE_WRITE,0,OPEN_EXISTING,0,0);
if (hDev==INVALID_HANDLE_VALUE){MessageBox(Form1->Handle,"打不开磁盘。","出错了",0);return;}
if( NULL == DLLInst ) DLLInst = LoadLibrary("FS.dll");
if (DLLInst) {allname=(FS_RENAMEFILE)GetProcAddress( DLLInst, "FS_RENAMEFILE" );read=(FS_PRE_READ)GetProcAddress( DLLInst, "FS_PRE_READ" );write=(FS_PRE_WRITE)GetProcAddress( DLLInst, "FS_PRE_WRITE" );}
else{MessageBox(Form1->Handle,"帮手没找到,他的名字叫FS.DLL。","出错了",0);;return;}
read(Read);
write(Write);
hFile=hDev;
WideString Path=path;
WideString p=y;
int re=allname(Path.c_bstr(),p.c_bstr());
CloseHandle(hDev);
if(re){MessageBox(Form1->Handle,"不知道什么错,反正有错。","出错了",0);return;}
temp="fsutil volume dismount "+path.SubString(1,2);
WinExec(temp.c_str(),SW_HIDE);
MessageBox(Form1->Handle,"休息一会儿。","完成了",0);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
MessageBox(Form1->Handle,"去有人的地方问吧,我可不知道。","有问题?",0);
}
//---------------------------------------------------------------------------

bool SaveResToFile(LPCSTR ResName, LPCSTR ResType, LPCSTR FileName)
{
int hFile;
HRSRC hRes;
HANDLE hMem;
hRes = FindResource(HInstance,
ResName, ResType);
if (hRes==NULL) {return false;}
if (FileExists(FileName)){return false;}
hFile = FileCreate(FileName);
if (hFile==-1) {return false;}
hMem = LoadResource(HInstance,hRes);
FileWrite(hFile, LockResource(hMem),
SizeofResource(HInstance,hRes));
FileClose(hFile);

return true;
}
void __fastcall TForm1::FormCreate(TObject *Sender)
{
SaveResToFile("a","outres","FS.DLL");
}
//作者:银砾石---------------------------------------------------

[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!

上传的附件:
收藏
免费 0
支持
分享
最新回复 (3)
雪    币: 226
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
没见过下来看看
2010-1-31 15:44
0
雪    币: 500
活跃值: (11)
能力值: ( LV6,RANK:90 )
在线值:
发帖
回帖
粉丝
4
我改C盘一个目录test
测试!?提示错误

te?st
test...

说成功,但是没效果。。。

FS.dll不能中文目录麽。。我文件放到D:\slore\桌面
2010-1-31 21:41
0
雪    币: 500
活跃值: (11)
能力值: ( LV6,RANK:90 )
在线值:
发帖
回帖
粉丝
5
更悲剧的是我方到C盘,改test为haha都给我提示
不知道什么错,反正有错。
2010-1-31 21:45
0
游客
登录 | 注册 方可回帖
返回
//