您所在的位置: 程序员家园 -> 家园博客 ->
 
在哪里摔倒
就在哪里自己爬起来

用户登录

查  找

最新评论

最新留言

常用网站

网易邮箱 GMAIL  

百度搜索 MSDN

霏凡软件 BT精品

影视帝国 射 手 网

电驴下载 全 库 网

友情连接

茄菲的窝 冰冰博客

枫叶飘零 玫  瑰

ACEN 云 豹 子

统  计



一个批量换名的程序 
狼子 发表于 2007-2-18 22:00:00 阅读全文 | 回复(1) | 引用通告 | 编辑

(修改一下,正确的方法在第一个回复里写着,这里是那天晚上的方法)

刚刚用PB写的,现在用的是FileCopy,肯定不对头,因为复制文件后要不要把原来的文件删除啊?

在cmd里可以使用rename,我想要用run执行,没有反应,用

run("rename e:\aaa.txt e:\bbb.txt")

这样的语句也不可以,一点反应都没有

我想到的是先for...next,读取信息生成一个bat文件,然后呢,在pb里执行这个bat文件,就是我又不想改了,困了,明天吧,明天想重装机器,重装完吧,嗯,不准说我懒

现在用的是FileCopy,就是觉得不对头,先记下这个,现在困了,等我玩够了想一下run的问题,嗯,如果不是用run,用什么好呢?不知道C#执行这个是不是会快很多,会不会占用的资源少很多

界面是这个

设置按钮是cb_2,确定按钮是cb_1,显示信息的是MulityLineEdit(mle_1),列出文件的是ListBox(lb_1),cb_2的代码

string dic
dic=trim(sle_1.text)
if dic="" then
 messagebox('','please in put the source directory')
 return
end if
if not directoryexists(dic) then
 messagebox('','no such directory')
 return
end if
mle_1.visible=false
lb_1.visible=true
lb_1.dirlist(dic,1)

cb_1的代码

string dicSource,dicAim,wordNeedReplace,wordForReplace

//get info
dicSource=trim(sle_1.text)
dicAim=trim(sle_2.text)
wordNeedReplace=trim(sle_3.text)
wordForReplace=trim(sle_4.text)
if dicSource="" or dicAim="" then
 messagebox('','please input the directories')
 return
end if
if wordNeedReplace=wordForReplace then
 messagebox('','please set the rename ruler')
 return
end if

//list the file
cb_2.triggerevent("clicked")

//create aim directory
if not directoryexists(dicAim) then
 createdirectory(dicAim)
end if

//copy files for rename
mle_1.visible=true
lb_1.visible=false
string fileSource,fileAim,errMsg
integer i,allFile,posReturn,t
allFile=lb_1.totalitems()
for i=1 to allFile
 fileSource=lb_1.text(i)
 posReturn=pos(fileSource,wordNeedReplace)
 if posReturn>0 then
  fileAim=replace(fileSource,posReturn,len(wordNeedReplace),wordForReplace)
 else
  if dicSource=dicAim then
   continue
  else
   fileAim=fileSource
  end if
 end if
 fileAim=dicAim + '\' + fileAim
 t=filecopy(fileSource,fileAim,true)
 //errMsg="rename " + fileSource + " " + fileAim
 //run(errMsg)
 if t=-1 then
  errMsg=errMsg + fileSource + ' open the file in error~r~n'
 elseif t=-1 then
  errMsg=errMsg + fileSource + ' write the file in error~r~n'
 else
  errMsg=fileSource + ' is ok~r~n'
 end if
 mle_1.text=mle_1.text + errMsg
next

Re:一个批量换名的程序
mountain315发表评论于2007-2-21 16:24:00 个人主页 | 引用 | 返回 | 删除 | 回复

改成用bat文件了,先生成一个bat文件,然后执行这个bat文件,现在改名的速度很快很快,我试过了

string dicSource,dicAim,wordNeedReplace,wordForReplace

//get info
dicSource=trim(sle_1.text)
dicAim=trim(sle_2.text)
wordNeedReplace=trim(sle_3.text)
wordForReplace=trim(sle_4.text)
if dicSource="" or dicAim="" then
 messagebox('','please input the directories')
 return
end if
if wordNeedReplace=wordForReplace then
 messagebox('','please set the rename ruler')
 return
end if

//list the file
cb_2.triggerevent("clicked")

//create aim directory
if not directoryexists(dicAim) then
 createdirectory(dicAim)
end if

//copy files for rename
mle_1.visible=true
lb_1.visible=false
string fileSource,fileAim,errMsg,ls_t
integer i,allFile,posReturn,t,li_file_no
allFile=lb_1.totalitems()

//open the file
string ls_bat
ls_bat=appDir + "\rename.bat"
if fileExists(ls_bat) then
 fileDelete(ls_bat)
end if
li_file_no=fileopen(ls_bat,linemode!,write!,shared!,append!)
if li_file_no=0 then
 messagebox('','open rename.bat in error')
end if

//write the file
for i=1 to allFile
 //get name
 fileSource=lb_1.text(i)
 posReturn=pos(fileSource,wordNeedReplace)
 if posReturn>0 then
  fileAim=replace(fileSource,posReturn,len(wordNeedReplace),wordForReplace)
 else
  if dicSource=dicAim then
   continue
  else
   fileAim=fileSource
  end if
 end if
 //create bat file
 if i=1 then
  ls_t="@echo off"
  if filewrite(li_file_no,ls_t)<0 then
   errMsg="error"
   mle_1.text=errMsg
   return
  end if
 end if
 //write a line
 ls_t="rename " + trim(dicSource) + "\" + trim(fileSource) + " " + trim(fileAim)
 if filewrite(li_file_no,ls_t)<0 then
  errMsg=errMsg + "~n~r" + fileSource + "出错"
 end if
next

//close the bat file
fileclose(li_file_no)

//run the bat file
ChangeDirectory(appDir)
run("rename.bat")

//show the info
mle_1.text="文件改名完成"

发表评论:

    昵称:
    密码:
    主页:
    标题:
Powered by Oblog.