顯示具有 VBS 標籤的文章。 顯示所有文章
顯示具有 VBS 標籤的文章。 顯示所有文章

2008/03/31

[VBS]資料夾內檔案內容增加

就是會在同一個目錄內檔案增加幾行的文字,程式碼如下:




' 日期: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 name
Const ForAppend = 8
Set objFSO = CreateObject("Scripting.FileSystemObject")
For each fileItem in oFolder.Items
name = oFolderItem.Path & "\" & fileItem.name
Set opFile = objFSO.OpenTextFile( name , ForAppend)
opFile.WriteLine("")
opFile.Close
Next
Wscript.echo "完成"

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 "完成"

2007/12/21

USB AutoRun vs VBS

由於"我的最愛"在公司跟家裡的電腦一直想要合併成一個,於是前一陣子買了一個隨身碟,來當作個人資料的儲存與備份。

如果要讓AutoRun隨插即啟動,首先就要灌APO Usb Autorun,這軟體網路上的文章不少,有需要請自行尋找估狗大神。不過之前隨身碟病毒不少,要小心服用。

然後在隨身碟根目錄建一個Autorun.inf內容如下,如果有喜歡的小icon也可以在這裡設定:



[autorun]
shellexecute=autorun.vbs


然後再建立一個autorun.vbs的檔案,如下:



Dim PIM
Set PIM = CreateObject("WScript.Shell")
PIM.Run "Tools\Essentialpimport2\EssentialPIM.exe" ,7
Dim BackUp
Set BackUp = CreateObject("WScript.Shell")
BackUp.Run "Tools\FileBackupPro\FileBackup.exe" ,7
WScript.Quit


本來是用BAT檔,不過一執行就會跳出Dos視窗,而我也找不到如何不顯現。VBS我也不熟,從網路上參考而來的,非常簡單,Run "路徑檔案",7代表的是一執行就最小化。

我的隨身碟中,一開始就啟用的有個人行事曆(EssentialPIM)和備份系統(FileBackup),之前曾經發生插入電腦之後就發生資料不見,所以就一插入電腦就讓他自動備份。