- May 27 Thu 2010 20:18
-
C# Tutorial – 7. Control Statements Tutorial
- May 24 Mon 2010 12:11
-
利用VBS定期刪除過期檔案
本文主要介紹如何利用VBS在WINDOWS上刪除過期檔案,雖然不是很常用,但久久就會有人問一次,寫下來當作備忘。
DeleteFolder.vbs
' ====== Code Start ===================
Option Explicit
WScript.Echo("作業開始執行:" & Date & " " & Time)
Dim FSO, agoDays, modifiedDate, delFolder
' 設定過期檔案預期天數
agoDays = 3
' 欲刪除檔案所在之目錄
delFolder = "D:\Temp"
Set FSO = CreateObject("Scripting.FileSystemObject")
modifiedDate = DateAdd("d", -agoDays, Date)
DelFilesInFolder FSO.GetFolder(delFolder)
Sub DelFilesInFolder(folder)
Dim file, subFolder
For Each file In folder.Files
If ((file.DateLastModified <= modifiedDate)) Then
file.delete
End If
Next
' 如果遇到子目錄,也要進去檢查並刪除
For Each subFolder in folder.SubFolders
DelFilesInFolder subFolder
Next
End Sub
WScript.Echo("作業執行完畢:" & Date & " " & Time)
' ====== Code End ===================
DeleteFolder.vbs
' ====== Code Start ===================
Option Explicit
WScript.Echo("作業開始執行:" & Date & " " & Time)
Dim FSO, agoDays, modifiedDate, delFolder
' 設定過期檔案預期天數
agoDays = 3
' 欲刪除檔案所在之目錄
delFolder = "D:\Temp"
Set FSO = CreateObject("Scripting.FileSystemObject")
modifiedDate = DateAdd("d", -agoDays, Date)
DelFilesInFolder FSO.GetFolder(delFolder)
Sub DelFilesInFolder(folder)
Dim file, subFolder
For Each file In folder.Files
If ((file.DateLastModified <= modifiedDate)) Then
file.delete
End If
Next
' 如果遇到子目錄,也要進去檢查並刪除
For Each subFolder in folder.SubFolders
DelFilesInFolder subFolder
Next
End Sub
WScript.Echo("作業執行完畢:" & Date & " " & Time)
' ====== Code End ===================
- May 18 Tue 2010 16:57
-
C# Tutorial - 6. String Tutorial
- May 17 Mon 2010 16:22
-
C# Tutorial - 5. Array Tutorial
陣列是各語言最常用的資料結構,本文主要介紹C#操作陣列的方法,以供有興趣的朋友參考。
陣列是一種資料結構,其中會包含多個相同型別的變數。陣列是用型別宣告:
type[] arrayName;
陣列是一種資料結構,其中會包含多個相同型別的變數。陣列是用型別宣告:
type[] arrayName;
- May 17 Mon 2010 15:45
-
C# Tutorial - 4. Statements and Expression Tutorial
本文主要介紹C#最基本要件和運算式,以供有興趣的朋友參考。
Statements
Statement為C#最基本的組成,所有程式都是由Statement建構的,可以宣告區域變數、常數、呼叫方法、建立物件,或指派值給變數、屬性或欄位。
Statements
Statement為C#最基本的組成,所有程式都是由Statement建構的,可以宣告區域變數、常數、呼叫方法、建立物件,或指派值給變數、屬性或欄位。
- May 17 Mon 2010 11:41
-
C# Tutorial - 3. Operators, Types, and Variables Tutorial
- May 12 Wed 2010 13:48
-
C# Tutorial - 2. Command Line Arguments Tutorial
本文主要介紹C#如何處理從Command line帶進來的變數值,以供有興趣的朋友參考。
using System;
using System.Collections.Generic;
using System.Text;
namespace CmdLineInput
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("You entered the following {0} command line arguments:", args.Length);
for (int i = 0; i < args.Length; i++) {
Console.WriteLine("{0}", args[i]);
}
}
}
}
Output:
You entered the following 4 command line arguments:
A
B
C
D
說明:
1. 不像 C 和 C++,程式名稱不會當做第一個命令列引數處理。
2. 使用 for 迴圈, 將帶入的參數逐一顯示在 console 上.
另一種方式, 使用 foreach statement
using System;
using System.Collections.Generic;
using System.Text;
namespace CmdLineArgus
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("You entered the following {0} command line arguments:", args.Length);
foreach (string s in args)
{
Console.WriteLine("{0}", s);
}
}
}
}
說明:
1. foreach 提供了一個簡單且清楚的方法來逐一查看陣列中的元素.
* 用 console mode 啟動測式應該都很OK, 但大部分都是殺雞用牛刀, 使用Visual Studio編輯器請照下面步驟:
Project -> 專案名稱的 Properties -> Debug -> Start Option -> Command line arguments
然後輸入程式啟始時想帶入的參數, 如 A B C D
using System;
using System.Collections.Generic;
using System.Text;
namespace CmdLineInput
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("You entered the following {0} command line arguments:", args.Length);
for (int i = 0; i < args.Length; i++) {
Console.WriteLine("{0}", args[i]);
}
}
}
}
Output:
You entered the following 4 command line arguments:
A
B
C
D
說明:
1. 不像 C 和 C++,程式名稱不會當做第一個命令列引數處理。
2. 使用 for 迴圈, 將帶入的參數逐一顯示在 console 上.
另一種方式, 使用 foreach statement
using System;
using System.Collections.Generic;
using System.Text;
namespace CmdLineArgus
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("You entered the following {0} command line arguments:", args.Length);
foreach (string s in args)
{
Console.WriteLine("{0}", s);
}
}
}
}
說明:
1. foreach 提供了一個簡單且清楚的方法來逐一查看陣列中的元素.
* 用 console mode 啟動測式應該都很OK, 但大部分都是殺雞用牛刀, 使用Visual Studio編輯器請照下面步驟:
Project -> 專案名稱的 Properties -> Debug -> Start Option -> Command line arguments
然後輸入程式啟始時想帶入的參數, 如 A B C D
- May 12 Wed 2010 12:28
-
C# Tutorial - 1. Hello World Tutorial
所有語言的第一個程式, Hello World
來點不一樣的, Hello C#, :)
using System;
using System.Collections.Generic;
using System.Text;
namespace Hello1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello, C#");
}
}
}
說明:
1. Main 方法是程式的進入點,程式控制會在此開始和結束。
Main method 必須在類別或結構中宣告。它必須為靜態且不應該為 public
傳回型別可以是 void 或 int。
2. WriteLine method 屬於 System.Console class, 用來將資料顯示在 console 中.
程式碼其實可以更簡潔一點, 只是用Visual Studio產生專案時, 會加了一堆東西
來點不一樣的, Hello C#, :)
using System;
using System.Collections.Generic;
using System.Text;
namespace Hello1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello, C#");
}
}
}
說明:
1. Main 方法是程式的進入點,程式控制會在此開始和結束。
Main method 必須在類別或結構中宣告。它必須為靜態且不應該為 public
傳回型別可以是 void 或 int。
2. WriteLine method 屬於 System.Console class, 用來將資料顯示在 console 中.
程式碼其實可以更簡潔一點, 只是用Visual Studio產生專案時, 會加了一堆東西