2008/03/15

[VBS]更改資料夾內檔名

最近都在用PDA看小說,可是下載下來的檔案都很大,如果一次開啟,就會造成一整個LAG。

然後就在網路上找切割程式,但是好像沒有找到文字檔的切割,就隨便找一個切割軟體來使用。

但是,如果檔名為"xxx.txt",切割後就會變成"xxx.txt.001",於是我就寫了一個程式,把後面的001 跟 txt 互換的程式。

原始碼如下:



' 日期:20080308
' 作者:Kwedr
' 作用:更改檔名
'
'開啟瀏覽資料夾畫面,選擇資料夾
dim oShell
dim oFolder
dim oFolderItem
set oShell = CreateObject("Shell.Application")
set oFolder = oShell.BrowseForFolder(0, "選擇你要更改檔名的資料夾", 0)
set oFolderItem = oFolder.Items.Item
dim fileItem
dim tmp,pos,name,ext,no,strlen
dim oldname,newname
Set objFSO = CreateObject("Scripting.FileSystemObject")
For each fileItem in oFolder.Items
strlen=Len(fileItem.name)
oldname = oFolderItem.Path & "\" & fileItem.name
'Wscript.echo "oldname:"&oldname
if pos <= 0 then
Wscript.echo "oldname:"&oldname
end if
pos = InStr(fileItem.name,".")
name = Left(fileItem.name,pos-1)
'Wscript.echo "name:"&name
tmp = Right(fileItem.name,strlen-pos)
pos = InStr(tmp,".")
'Wscript.echo "tmp:"&tmp
strlen=Len(tmp)
ext = Left(tmp,pos-1)
'Wscript.echo "ext:"&ext
tmp = Right(tmp,strlen-pos)
no = String(3-Len(tmp),"0")+tmp
'Wscript.echo "no:"&no
newname = oFolderItem.Path & "\" & name&"_"+no&"."&ext
'Wscript.echo "newname:"&newname
objFSO.MoveFile oldname, newname
Next
Wscript.echo "完成"

沒有留言: