NameSpace

指定されたフォルダーのFolderオブジェクトを作成して返します。

構文
  1. Folder = Shell.NameSpace( vDir )
引数
vDir必須
フォルダのパスもしくはShellSpecialFolderConstantsを指定
戻り値
指定されたフォルダのFolderオブジェクトを作成して返します。

定数一覧

ShellSpecialFolderConstants 列挙

名前説明
ssfDESKTOP0デスクトップ
ssfPROGRAMS2プログラム
C:\Users\username\AppData\Roaming\Microsoft\Windows\Start Menu\Programs
ssfCONTROLS3すべてのコントロール パネル項目
ssfPRINTERS4プリンター
ssfPERSONAL5ドキュメント
ssfFAVORITES6お気に入り
ssfSTARTUP7スタートアップ
C:\Users\username\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
ssfRECENT8最近使った項目
ssfSENDTO9送る
C:\Users\username\AppData\Roaming\Microsoft\Windows\SendTo
ssfBITBUCKET10ごみ箱
ssfSTARTMENU11スタート メニュー
ssfDESKTOPDIRECTORY16デスクトップ
C:\Documents and Settings\username\Desktop
ssfDRIVES17PC
ssfNETWORK18ネットワーク
ssfNETHOOD19Network Shortcuts
C:\Users\username\AppData\Roaming\Microsoft\Windows\Network Shortcuts
ssfFONTS20フォント
C:\Windows\Fonts
ssfTEMPLATES21Templates
C:\Users\username\AppData\Roaming\Microsoft\Windows\Templates
ssfCOMMONSTARTMENU22スタート メニュー
C:\ProgramData\Microsoft\Windows\Start Menu
ssfCOMMONPROGRAMS23プログラム
C:\ProgramData\Microsoft\Windows\Start Menu\Programs
ssfCOMMONSTARTUP24スタートアップ(全ユーザー共通)
C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp
ssfCOMMONDESKTOPDIR25パブリックデスクトップ
C:\Users\Public\Desktop
ssfAPPDATA26Roaming
C:\Users\username\AppData\Roaming
ssfPRINTHOOD27C:\Users\username\AppData\Roaming\Microsoft\Windows\Printer Shortcuts
ssfLOCALAPPDATA28Local
C:\Users\username\AppData\Local
ssfALTSTARTUP29スタートアップ(ログオンユーザー)
C:\Users\username\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
ssfCOMMONALTSTARTUP30スタートアップ(全ユーザー共通)
C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp
ssfCOMMONFAVORITES31お気に入り
C:\Users\username\Favorites
ssfINTERNETCACHE32Temporary Internet Files
ssfCOOKIES33INetCookies
ssfHISTORY34History
ssfCOMMONAPPDATA35C:\ProgramData
ssfWINDOWS36%windir% or %SystemRoot%
ssfSYSTEM37C:\Windows\System32
ssfPROGRAMFILES38C:\Program Files (x86)
ssfMYPICTURES39ピクチャ
ssfPROFILE40C:\Users\username
ssfSYSTEMx8641C:\WindowsSystem32
C:\WindowsSyswow32
ssfPROGRAMFILESx8648C:\Program Files
C:\Program Files (X86)
CONST ssfDESKTOP = 0
CONST ssfPROGRAMS = 2
CONST ssfCONTROLS = 3
CONST ssfPRINTERS = 4
CONST ssfPERSONAL = 5
CONST ssfFAVORITES = 6
CONST ssfSTARTUP = 7
CONST ssfRECENT = 8
CONST ssfSENDTO = 9
CONST ssfBITBUCKET = 10
CONST ssfSTARTMENU = 11
CONST ssfDESKTOPDIRECTORY = 16
CONST ssfDRIVES = 17
CONST ssfNETWORK = 18
CONST ssfNETHOOD = 19
CONST ssfFONTS = 20
CONST ssfTEMPLATES = 21
CONST ssfCOMMONSTARTMENU = 22
CONST ssfCOMMONPROGRAMS = 23
CONST ssfCOMMONSTARTUP = 24
CONST ssfCOMMONDESKTOPDIR = 25
CONST ssfAPPDATA = 26
CONST ssfPRINTHOOD = 27
CONST ssfLOCALAPPDATA = 28
CONST ssfALTSTARTUP = 29
CONST ssfCOMMONALTSTARTUP = 30
CONST ssfCOMMONFAVORITES = 31
CONST ssfINTERNETCACHE = 32
CONST ssfCOOKIES = 33
CONST ssfHISTORY = 34
CONST ssfCOMMONAPPDATA = 35
CONST ssfWINDOWS = 36
CONST ssfSYSTEM = 37
CONST ssfPROGRAMFILES = 38
CONST ssfMYPICTURES = 39
CONST ssfPROFILE = 40
CONST ssfSYSTEMx86 = 41
CONST ssfPROGRAMFILESx86 = 48

vDirのパスを取得

vDirの値と取得されるフォルダのパスのリストです。

PRINT Shell.NameSpace(vDir).Self.Path
vDir パス
0C:\Users\username\Desktop
1::{871C5380-42A0-1069-A2EA-08002B30309D}
2C:\Users\username\AppData\Roaming\Microsoft\Windows\Start Menu\Programs
3::{26EE0668-A00A-44D7-9371-BEB064C98683}\0
4::{21EC2020-3AEA-1069-A2DD-08002B30309D}\::{2227A280-3AEA-1069-A2DE-08002B30309D}
5C:\Users\username\Documents
6C:\Users\username\Favorites
7C:\Users\username\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
8C:\Users\username\AppData\Roaming\Microsoft\Windows\Recent
9C:\Users\username\AppData\Roaming\Microsoft\Windows\SendTo
10::{645FF040-5081-101B-9F08-00AA002F954E}
11C:\Users\username\AppData\Roaming\Microsoft\Windows\Start Menu
13C:\Users\username\Music
14C:\Users\username\Videos
17::{20D04FE0-3AEA-1069-A2D8-08002B30309D}
18::{F02C1A0D-BE21-4350-88B0-7367FC96EF3C}
19C:\Users\username\AppData\Roaming\Microsoft\Windows\Network Shortcuts
20C:\Windows\Fonts
21C:\Users\username\AppData\Roaming\Microsoft\Windows\Templates
22C:\ProgramData\Microsoft\Windows\Start Menu
23C:\ProgramData\Microsoft\Windows\Start Menu\Programs
24C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp
25C:\Users\Public\Desktop
26C:\Users\username\AppData\Roaming
27C:\Users\username\AppData\Roaming\Microsoft\Windows\Printer Shortcuts
28C:\Users\username\AppData\Local
32C:\Users\username\AppData\Local\Microsoft\Windows\INetCache
33C:\Users\username\AppData\Local\Microsoft\Windows\INetCookies
34C:\Users\username\AppData\Local\Microsoft\Windows\History
35C:\ProgramData
36C:\Windows
37C:\Windows\System32
38C:\Program Files
39C:\Users\username\Pictures
40C:\Users\username
43C:\Program Files\Common Files
45C:\ProgramData\Microsoft\Windows\Templates
46C:\Users\Public\Documents
47C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Administrative Tools
48C:\Users\username\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Administrative Tools
49::{21EC2020-3AEA-1069-A2DD-08002B30309D}\::{7007ACC7-3202-11D1-AAD2-00805FC1270E}
53C:\Users\Public\Music
54C:\Users\Public\Pictures
55C:\Users\Public\Videos
56C:\Windows\Resources
57C:\Windows\Resources\0411
58C:\ProgramData\OEM Links
59C:\Users\username\AppData\Local\Microsoft\Windows\Burn\Burn

CLSID

「ファイル名を指定して実行」で以下を実行すると対応するアプリが起動します。

explorer shell:{CLSID}
アプリ名 CLSID
Internet Explorer ::{871C5380-42A0-1069-A2EA-08002B30309D}
コントロールパネル(カテゴリ) ::{26EE0668-A00A-44D7-9371-BEB064C98683}
コントロールパネル\すべてのコントロールパネル項目(小さいアイコン) ::{26EE0668-A00A-44D7-9371-BEB064C98683}\0
すべてのコントロールパネル項目 ::{21EC2020-3AEA-1069-A2DD-08002B30309D}
PC ::{20D04FE0-3AEA-1069-A2D8-08002B30309D}
ネットワーク ::{F02C1A0D-BE21-4350-88B0-7367FC96EF3C}
すべてのコントロールパネル項目 ::{21EC2020-3AEA-1069-A2DD-08002B30309D}
すべてのコントロールパネル項目\ネットワーク ::{21EC2020-3AEA-1069-A2DD-08002B30309D}\::{7007ACC7-3202-11D1-AAD2-00805FC1270E}

プログラム実行例

指定したファイルを削除する確認メッセージを表示

CONST ssfDesktop = 0

DIM Shell = CREATEOLEOBJ("Shell.Application")
DIM Folder = Shell.NameSpace(ssfDesktop)
DIM FolderItem = Folder.ParseName("D:\Desktop\sample.txt")

FolderItem.InvokeVerb("delete")
    (3) (4) (5) (7)

指定したファイルを開く

CONST ssfDesktop = 0

DIM Shell = CREATEOLEOBJ("Shell.Application")
DIM Folder = Shell.NameSpace(ssfDesktop)

DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
DIM path = "D:\Desktop\sample.txt"
IF FSO.FileExists(path) = FALSE THEN EXIT

DIM FolderItem = Folder.ParseName(path)
FolderItem.InvokeVerb()
    (3,6) (4) (8) (10) (11)

エクスプローラーで指定したフォルダを開く

CONST ssfDESKTOP = 0

DIM Shell = CREATEOLEOBJ("Shell.Application")
DOSCMD("explorer <#DBL>" + Shell.NameSpace(ssfDESKTOP).Self.Path + "<#DBL>")
    (3) (4) (4)

新しいフォルダを作成

デスクトップに「請求書」という名前のフォルダを作成します。

CONST ssfDESKTOP = 0

DIM Shell = CREATEOLEOBJ("Shell.Application")
DIM Folder = Shell.NameSpace(ssfDESKTOP)

Folder.NewFolder("請求書")
    (3) (4) (6)

「開く(&O)」を実行

CONST ssfDESKTOP = 0

DIM Shell = CREATEOLEOBJ("Shell.Application")
DIM Folder = Shell.NameSpace(ssfDESKTOP)
DIM FolderItemVerbs = Folder.Self.Verbs()

FOR FolderItemVerb IN FolderItemVerbs
	IFB POS("&O", FolderItemVerb.Name) <> 0 THEN
		FolderItemVerb.DoIt()
	ENDIF
NEXT
    (4) (7) (9)

プロパティの項目を取得

DIM Shell = CREATEOLEOBJ("Shell.Application")
DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")

DIM path = "C:\Users\akita\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Accessories\Internet Explorer.lnk"
DIM Folder = Shell.NameSpace(FSO.GetParentFolderName(path))

HASHTBL iColumn
 
FOR i = 0 TO 350
	iColumn[Folder.GetDetailsOf(EMPTYPARAM, i)] = i	
NEXT

FOR i = 0 TO LENGTH(iColumn)
	iColumn[iColumn[i, HASH_VAL]] = iColumn[i, HASH_KEY]
NEXT

DIM FolderItem = Folder.ParseName(FSO.GetFileName(path))
DIM array[] = "名前", "項目の種類", "ファイルの説明", "フォルダーのパス", "サイズ", "作成日時", "更新日時", "アクセス日時", "属性"

FOR i = 0 TO UBound(array)
	PRINT "■" + array[i]
	PRINT Folder.GetDetailsOf(FolderItem, iColumn[array[i]])
	PRINT "-----"
NEXT

//////////////////////////////////////////////////
// 【引数】
//   配列 : 上限値を求める配列 
// 【戻値】
//   配列の上限値 
//////////////////////////////////////////////////
FUNCTION UBound(array[])
	RESULT = RESIZE(array)
FEND
    (1,2) (5) (5) (10,22) (17) (17) (20)
結果
■名前
Internet Explorer
-----
■項目の種類
ショートカット
-----
■ファイルの説明

-----
■フォルダーのパス
C:\ユーザー\akita\AppData\Roaming\Microsoft\Windows\スタート メニュー\プログラム\Windows アクセサリ
-----
■サイズ
1.31 KB
-----
■作成日時
2021/02/04 12:46
-----
■更新日時
2022/05/18 02:24
-----
■アクセス日時
2022/05/21 22:47
-----
■属性
A
-----
解説
  1. 1行目
    DIM Shell = CREATEOLEOBJ("Shell.Application")
    Shellオブジェクトを生成し、 Shell に代入します。
  2. 2行目
    DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
    FileSystemObjectオブジェクトを生成し、 FSO に代入します。
  3. 4行目
    DIM path = "C:\Users\akita\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Accessories\Internet Explorer.lnk"
    情報を取得するファイルパスを指定。
  4. 5行目
    DIM Folder = Shell.NameSpace(FSO.GetParentFolderName(path))
    pathからフォルダ名を取得し、そのFolderオブジェクトを取得。

デスクトップのファイル一覧

CONST ssfDESKTOP = 0

HASHTBL iColumn

DIM Shell = CREATEOLEOBJ("Shell.Application")
DIM Folder = Shell.NameSpace(ssfDESKTOP)
DIM FolderItems = Folder.Items

FOR n = 0 TO 350
	iColumn[Folder.GetDetailsOf(EMPTYPARAM, n)] = n
NEXT

FOR n = 0 TO FolderItems.Count - 1
	DIM FolderItem = FolderItems.Item(n)
	WITH FolderItem
		PRINT .Name
		PRINT .Size + " Byte"
		PRINT .Type
	ENDWITH
	PRINT "-----"
NEXT
    (5) (6) (7) (10) (13) (14) (15) (16) (17) (18)

フォルダ内のファイルを更新日時でソートする

DIM Shell = CREATEOLEOBJ("Shell.Application")
DIM Folder = Shell.NameSpace("C:\Program Files (x86)\UWSC")
DIM FolderItems = Folder.Items

HASHTBL iColumn

FOR i = 0 TO 350
	iColumn[Folder.GetDetailsOf(EMPTYPARAM, i)] = i
NEXT

DIM filename[-1]
DIM datetime[-1]

FOR i = 0 TO FolderItems.Count - 1
	DIM FolderItem = FolderItems.Item(i)
	IF FolderItem.isFolder THEN CONTINUE
	arrayPush(filename, Folder.GetDetailsOf(FolderItem,iColumn["名前"]))
	arrayPush(datetime, Folder.GetDetailsOf(FolderItem, iColumn["更新日時"]))
NEXT

QSORT(datetime, QSRT_NATURALA, filename)

FOR i = 0 TO UBound(filename)
	PRINT filename[i] + "<#TAB>" + datetime[i]
NEXT

//////////////////////////////////////////////////
// 【引数】
//   array : 要素を追加する配列(参照引数) 
//   str : 追加する要素 
// 【戻値】
//   処理後の配列の中の要素の数 
//////////////////////////////////////////////////
FUNCTION arrayPush(var arr[], str)
	DIM res = RESIZE(arr, UBound(arr) + 1)
	arr[res] = str
	RESULT = res + 1
FEND

//////////////////////////////////////////////////
// 【引数】
//   配列 : 上限値を求める配列 
// 【戻値】
//   配列の上限値 
//////////////////////////////////////////////////
FUNCTION UBound(array[])
	RESULT = RESIZE(array)
FEND
    (1) (2) (3) (8,18,19) (15) (16) (17) (21) (21) (24) (26)
結果
UDebug.chm	2014/05/11 1:58
RecIE.chm	2014/05/11 1:58
Uws2Exe.chm	2015/08/13 16:12
RecUws.dll	2016/03/25 4:57
UWSC.exe	2016/10/15 13:33
Uws2Exe.exe	2016/10/15 13:34
RecIE.exe	2016/10/15 13:35
UDebug.exe	2016/10/15 13:37
XRef.exe	2016/10/15 13:38
Readme.txt	2016/10/15 13:39
uwsc.chm	2016/10/15 13:41
unins000.exe	2018/06/27 12:48
unins000.dat	2018/06/27 12:49

写真を撮影日時毎にフォルダ分けする

CONST ssfMYPICTURES = 39
DIM Folder[1]
DIM folderspec[1]
DIM Shell = CREATEOLEOBJ("Shell.Application")
folderspec[0] = "D:\Pictures\100ANDRO\"
Folder[0] = Shell.NameSpace(folderspec[0])
DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
HASHTBL iColumn
FOR i = 0 TO 350
iColumn[Folder[0].GetDetailsOf(EMPTYPARAM, i)] = i
NEXT
DIM destination[-1]
DIM path[-1]
DIM cnt = Folder[0].Items.Count - 1
FOR i = cnt TO 0 STEP -1
FUKIDASI(i + "/" + cnt)
DIM FolderItem = Folder[0].Items.Item(i)
IF FolderItem.isFolder THEN CONTINUE
DIM filename = FolderItem.Name
DIM datetime = deleteControlCharacter(Folder[0].GetDetailsOf(FolderItem, iColumn["撮影日時"]))
PRINT filename
PRINT datetime
PRINT "-----"
TRY
DIM date = text(dateValue(datetime), "yyyy-mm-dd")
EXCEPT
date = "0000-00-00"
ENDTRY
folderspec[1] = FSO.BuildPath(folderspec[0], date)
Folder[1] = Shell.NameSpace(folderspec[1])
arrayPush(destination, folderspec[1])
arrayPush(path, FolderItem.Path)
NEXT
FOR i = 0 TO UBound(destination)
IF !FSO.FolderExists(destination[i]) THEN CreateFolders(destination[i])
Folders = Shell.NameSpace(destination[i])
Folders.MoveHere(path[i])
NEXT
FUNCTION deleteControlCharacter(str)
DIM array[] = CHR(8206), CHR(8207)
FOR item IN array
str = REPLACE(str, item, "")
NEXT
RESULT = str
FEND
//////////////////////////////////////////////////
// 【引数】
//   callback : 配列の各要素に適用するコールバック関数 
//   array : コールバック関数を適用する配列 
// 【戻値】
//   callback関数を適用した後、 適用後の要素を含む配列 
//////////////////////////////////////////////////
PROCEDURE arrayMap(callback, var array[])
DIM tmp[RESIZE(array)]
DIM n = 0
FOR %val% IN array
tmp[n] = EVAL(callback)
n = n + 1
NEXT
RESIZE(array, RESIZE(tmp))
FOR n = 0 TO RESIZE(tmp)
array[n] = tmp[n]
NEXT
FEND
//////////////////////////////////////////////////
// 【引数】
//   array : 要素を追加する配列(参照引数) 
//   str : 追加する要素 
// 【戻値】
//   処理後の配列の中の要素の数 
//////////////////////////////////////////////////
FUNCTION arrayPush(var arr[], str)
DIM res = RESIZE(arr, UBound(arr) + 1)
arr[res] = str
RESULT = res + 1
FEND
//////////////////////////////////////////////////
// 【引数】
//   needle : 検索する値 
//   haystack : 配列 
// 【戻値】
//   needleが見つかった場合に配列のキー 
//////////////////////////////////////////////////
FUNCTION arraySearch(needle, haystack[])
DIM i = 0
FOR item IN haystack
IFB item = needle THEN
RESULT = i
EXIT
ENDIF
i = i + 1
NEXT
FEND
//////////////////////////////////////////////////
// 【引数】
//   folderspec : 作成するフォルダのパス 
// 【戻値】
//   
//////////////////////////////////////////////////
PROCEDURE CreateFolders(folderspec)
DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
folderspec = FSO.GetAbsolutePathName(folderspec)
IF !FSO.DriveExists(FSO.GetDriveName(folderspec)) THEN EXIT
DIM parentPath = FSO.GetParentFolderName(folderspec)
IFB !FSO.FolderExists(parentPath) THEN
CreateFolders(parentPath)
ENDIF
IF !FSO.FolderExists(folderspec) THEN FSO.CreateFolder(folderspec)
FEND
//////////////////////////////////////////////////
// 【引数】
//   interval : 加算する時間間隔を表す文字列式(yyyy:年、m:月、d:日、ww:週、h:時、n:分、s:秒) 
//   num : dateに加算する値。未来は正、過去は負で指定 
//   date : 時間間隔を加算する日付 
// 【戻値】
//   日時(date)に、指定した単位(interval)の時間(num)を加算して返します 
//////////////////////////////////////////////////
FUNCTION dateAdd(interval, num, date)
DIM year, month, day, d
GETTIME(0, date)
DIM time = G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2
SELECT interval
CASE "yyyy"
d = (G_TIME_YY + num) + "/" + G_TIME_MM2 + "/" + G_TIME_DD2
IF time <> "00:00:00" THEN d = d + " " + time
CASE "m"
IFB num > 0 THEN
year = G_TIME_YY + INT((G_TIME_MM + num) / 12)
month = REPLACE(FORMAT(((G_TIME_MM + num) MOD 12), 2), " ", "0")
ELSE
year = G_TIME_YY + CEIL((G_TIME_MM + num) / 12 - 1)
month = REPLACE(FORMAT(G_TIME_MM - (ABS(num) MOD 12), 2), " ", "0")
ENDIF
IF month = "00" THEN month = 12
day = G_TIME_DD2
d = "" + year + month + day
IFB !isDate(d) THEN
d = year + "/" + month + "/" + "01"
d = getEndOfMonth(d)
ELSE
d = year + "/" + month + "/" + day
ENDIF
IF time <> "00:00:00" THEN d = d + " " + time
CASE "d"
t = GETTIME(num, date)
d = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2 + IIF(t MOD 86400, " " + G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2, "")
CASE "ww"
t = GETTIME(num * 7, date)
d = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2 + IIF(t MOD 86400, " " + G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2, "")
CASE "h"
t = GETTIME(num / 24, date)
d = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2 + IIF(t MOD 86400, " " + G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2, "")
CASE "n"
t = GETTIME(num / 1440, date)
d = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2 + IIF(t MOD 86400, " " + G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2, "")
CASE "s"
t = GETTIME(num / 86400, date)
d = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2 + IIF(t MOD 86400, " " + G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2, "")
SELEND
RESULT = d
FEND
//////////////////////////////////////////////////
// 【引数】
//   interval : 時間単位(yyyy︰年、q:四半期、m︰月、d︰日、w:週日、ww:週、h:時、n:分、s:秒) 
//   date1 : 日時1 
//   date2 : 日時2 
// 【戻値】
//   date2からdate1を引いた時間間隔を求めます。 
//////////////////////////////////////////////////
FUNCTION dateDiff(interval, date1, date2)
DIM y1, y2, m1, m2, d1, d2, d
SELECT interval
CASE "yyyy"
GETTIME(0, date1)
y1 = G_TIME_YY
GETTIME(0, date2)
y2 = G_TIME_YY
d = y2 - y1
CASE "q"
GETTIME(0, date1)
y1 = G_TIME_YY
m1 = G_TIME_MM
GETTIME(0, date2)
y2 = G_TIME_YY
m2 = G_TIME_MM
d = y2 * 4 + CEIL(m2/3) - (y1 * 4 + CEIL(m1/3))
CASE "m"
GETTIME(0, date1)
y1 = G_TIME_YY
m1 = G_TIME_MM
GETTIME(0, date2)
y2 = G_TIME_YY
m2 = G_TIME_MM
d = (y2 - y1) * 12 + m2 - m1
CASE "d"
d1 = GETTIME(0, date1)
d2 = GETTIME(0, date2)
d = (d2 - d1) / 86400
CASE "w"
d = INT(dateDiff("d", date1, date2) / 7)
CASE "ww"
date1 = dateAdd("d", -1 * getWeekday(date1), date1)
d = INT(dateDiff("d", date1, date2) / 7)
CASE "h"
d = dateDiff("d", date1, date2) * 24
CASE "n"
d = dateDiff("d", date1, date2) * 1440
CASE "s"
d = dateDiff("d", date1, date2) * 86400
SELEND
RESULT = d
FEND
//////////////////////////////////////////////////
// 【引数】
//   str : 日付文字列。yyyy/mm/dd、dd/mm/yyyy、yyyy年mm月dd日、yyyy年mm月、ge年mm月dd日、mm/dd、mm月dd日 
// 【戻値】
//   シリアル値 
//////////////////////////////////////////////////
FUNCTION dateValue(str)
HASHTBL Pattern
Pattern["year"] = "(190[0-9]|19[1-9][0-9]|[2-9][0-9]{3})"
Pattern["month"] = "(1[0-2]|0?[1-9]|Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Ap(?:ril)?|May|Jun(?:e)?|Jul(?:y)?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)"
Pattern["day"] = "([1-2][0-9]|3[0-1]|0?[1-9])"
SELECT TRUE
CASE reTest(str, Pattern["year"] + "/" + Pattern["month"] + "/" + Pattern["day"])
Matches = reExecute(str, Pattern["year"] + "/" + Pattern["month"] + "/" + Pattern["day"])
WITH Matches.Item(0)
date = .SubMatches(0) + "/" + text(VAL(.SubMatches(1)), "00") + "/" + text(VAL(.SubMatches(2)), "00")
ENDWITH
CASE reTest(str, Pattern["day"] + "/" + Pattern["month"] + "/" + Pattern["year"])
Matches = reExecute(str, Pattern["day"] + "/" + Pattern["month"] + "/" + Pattern["year"])
WITH Matches.Item(0)
IFB reTest(.SubMatches(1), "Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Ap(?:ril)?|May|Jun(?:e)?|Jul(?:y)?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?")
DIM array[] = "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
IF LENGTH(.SubMatches(1)) = 3 THEN arrayMap("COPY(%val%, 1, 3)", array)
m = arraySearch(.SubMatches(1), array) + 1
ELSE
m = .SubMatches(1)
ENDIF
date = .SubMatches(2) + "/" + text(m, "00") + "/" + .SubMatches(0)
ENDWITH
CASE reTest(str, Pattern["year"] + "年" + Pattern["month"] + "月" + Pattern["day"] + "日")
Matches = reExecute(str, Pattern["year"] + "年" + Pattern["month"] + "月" + Pattern["day"] + "日")
WITH Matches.Item(0)
date = .SubMatches(0) + "/" + text(VAL(.SubMatches(1)), "00") + "/" + text(VAL(.SubMatches(2)), "00")
ENDWITH
CASE reTest(str, Pattern["year"] + "/" + Pattern["month"])
Matches = reExecute(str, Pattern["year"] + "/" + Pattern["month"])
WITH Matches.Item(0)
date = .SubMatches(0) + "/" + .SubMatches(1) + "/01"
ENDWITH
CASE reTest(str, "([MTSHR])(\d+)/" + Pattern["month"] + "/" + Pattern["day"])
Matches = reExecute(str, "([MTSHR])(\d+)/" + Pattern["month"] + "/" + Pattern["day"])
WITH Matches.Item(0)
y = VAL(.SubMatches(1))
SELECT .SubMatches(0)
CASE "M"; y = y + 1867
CASE "T"; y = y + 1911
CASE "S"; y = y + 1925
CASE "H"; y = y + 1988
CASE "R"; y = y + 2018
SELEND
date = y + "/" + .SubMatches(2) + "/" + .SubMatches(3)
ENDWITH
CASE reTest(str, Pattern["month"] + "/" + Pattern["day"])
Matches = reExecute(str, Pattern["month"] + "/" + Pattern["day"])
GETTIME()
WITH Matches.Item(0)
date = G_TIME_YY4 + "/" + text(VAL(.SubMatches(0)), "00") + "/" + text(VAL(.SubMatches(1)), "00")
ENDWITH
CASE reTest(str, Pattern["month"] + "月" + Pattern["day"] + "日")
Matches = reExecute(str, Pattern["month"] + "月" + Pattern["day"] + "日")
GETTIME()
WITH Matches.Item(0)
date = G_TIME_YY4 + "/" + text(VAL(.SubMatches(0)), "00") + "/" + text(VAL(.SubMatches(1)), "00")
ENDWITH
SELEND
RESULT = uwscToSerial(GETTIME(0, date))
FEND
//////////////////////////////////////////////////
// 【引数】
//   arr : 最大公約数を求める数値を格納した配列 
// 【戻値】
//   最大公約数 
//////////////////////////////////////////////////
FUNCTION GCD(arr[])
DIM c = LENGTH(arr)
DIM rem = arr[c-1] MOD arr[c-2]
IFB rem = 0 THEN
IFB LENGTH(arr) = 2 THEN
RESULT = arr[c-2]
EXIT
ENDIF
RESIZE(arr, c-2)
RESULT = GCD(arr)
EXIT
ENDIF
arr[c-1] = arr[c-2]
arr[c-2] = rem
RESULT = GCD(arr)
FEND
//////////////////////////////////////////////////
// 【引数】
//   date : 日付(”YYYYMMDD” or “YYYY/MM/DD” or “YYYY-MM-DD” or “YYYYMMDDHHNNSS” or “YYYY/MM/DD HH:NN:SS”) 
//   m : 第一引数の指定日からプラスマイナス m 月とする(デフォルト=0) 
// 【戻値】
//   date から m 月後の月末の日付 
//////////////////////////////////////////////////
FUNCTION getEndOfMonth(date, m = 0)
date = dateAdd("m", m + 1, date)
GETTIME(0, date)
GETTIME(-G_TIME_DD, date)
RESULT = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2
FEND
//////////////////////////////////////////////////
// 【引数】
//   date
(”YYYYMMDD” or “YYYY/MM/DD” or “YYYY-MM-DD” or “YYYYMMDDHHNNSS” or “YYYY/MM/DD HH:NN:SS”) : 
// 【戻値】
//   曜日 (0:日曜…、6:土曜) 
//////////////////////////////////////////////////
FUNCTION getWeekday(date)
GETTIME(0, date)
RESULT = G_TIME_WW
FEND
//////////////////////////////////////////////////
// 【引数】
//   数値 : GETTIMEで取得した曜日の番号(G_TIME_WW=0:日曜….6:土曜) 
//   フォーマット : 以下のアルファベットは数値で指定した対応する曜日に置き換えられます。(aaa : 日〜土、aaaa : 日曜日〜土曜日、ddd : Sun〜Sat、dddd : Sunday〜Saturday) 
// 【戻値】
//   数値をフォーマットした文字列を返します。 
//////////////////////////////////////////////////
FUNCTION getWeekdayName(num, format = "aaa")
DIM re = CREATEOLEOBJ("VBScript.RegExp")
DIM aaa[] = "日", "月", "火", "水", "木", "金", "土";
DIM aaaa[] = "日曜日", "月曜日", "火曜日", "水曜日", "木曜日", "金曜日", "土曜日";
DIM ddd[] = "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat";
DIM dddd[] = "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday";
match = reExecute(format, "(a|d)+")
type = match.Item(0).Value
RESULT = reReplace(format, EVAL(type + "[" + num + "]"), type)
FEND
//////////////////////////////////////////////////
// 【引数】
//   serial : 時間を表すシリアル値を指定 
// 【戻値】
//   例)0…00、0.5…12、1.0…24 
//////////////////////////////////////////////////
FUNCTION Hour(serial)
RESULT = INT(serial * 24) MOD 24
FEND
//////////////////////////////////////////////////
// 【引数】
//   expr : 評価する式 
//   truepart : 評価した式がTrueのときに返す値 
//   falsepart : 評価した式がFalseのときに返す値 
// 【戻値】
//   truepart : 評価した式がTrueのとき、falsepart : 評価した式がFalseのとき 
//////////////////////////////////////////////////
FUNCTION IIF(expr, truepart, falsepart)
IFB EVAL(expr) THEN
RESULT = truepart
ELSE
RESULT = falsepart
ENDIF
FEND
//////////////////////////////////////////////////
// 【引数】
//   date
YYYYMMDD : 
// 【戻値】
//   TRUE : 日付として認識できる、FALSE : 日付として認識できない 
//////////////////////////////////////////////////
FUNCTION isDate(date)
DIM Pattern = "^(?!([02468][1235679]|[13579][01345789])000229)(([0-9]{4}(01|03|05|07|08|10|12)(0[1-9]|[12][0-9]|3[01]))|([0-9]{4}(04|06|09|11)(0[1-9]|[12][0-9]|30))|([0-9]{4}02(0[1-9]|1[0-9]|2[0-8]))|([0-9]{2}([02468][048]|[13579][26])0229))$"
DIM Match = reExecute(date, Pattern)
RESULT = IIF(Match.Count <> 0, TRUE, FALSE)
FEND
//////////////////////////////////////////////////
// 【引数】
//   str : 正規表現による検索の対象となる文字列 
//   Pattern : 正規表現で使用するパターンを設定 
//   IgnoreCase : 大文字・小文字を区別しない場合はTrue、区別する場合はFalse 
//   Global : 文字列全体を検索する場合はTrue、しない場合はFalse 
// 【戻値】
//   正規表現で検索した結果をMatchesコレクションとして返します。 
//////////////////////////////////////////////////
FUNCTION reExecute(str, Pattern, IgnoreCase = TRUE, Global = TRUE)
DIM re = CREATEOLEOBJ("VBScript.RegExp")
re.Pattern = Pattern
re.IgnoreCase = IgnoreCase
re.Global = Global
RESULT = re.Execute(str)
FEND
//////////////////////////////////////////////////
// 【引数】
//   str1 : 置換される文字列 
//   str2 : 置換後の文字列 
//   Pattern : 置換する文字列のパターン 
//   IgnoreCase : 大文字・小文字を区別しない場合はTrue、区別する場合はFalse 
//   Global : 文字列全体を検索する場合はTrue、しない場合はFalse 
// 【戻値】
//   正規表現置換後の文字列 
//////////////////////////////////////////////////
FUNCTION reReplace(str1, str2, Pattern, IgnoreCase = TRUE, Global = TRUE)
DIM re = CREATEOLEOBJ("VBScript.RegExp")
re.Pattern = Pattern
re.IgnoreCase = IgnoreCase
re.Global = Global
RESULT = re.Replace(str1, str2)
FEND
//////////////////////////////////////////////////
// 【引数】
//   str : 正規表現による検索の対象となる文字列 
//   Pattern : 正規表現で使用するパターンを設定 
//   IgnoreCase : 大文字・小文字を区別しない場合はTrue、区別する場合はFalse 
//   Global : 文字列全体を検索する場合はTrue、しない場合はFalse 
// 【戻値】
//   正規表現にマッチするかどうか 
//////////////////////////////////////////////////
FUNCTION reTest(str, Pattern, IgnoreCase = TRUE, Global = TRUE)
DIM re = CREATEOLEOBJ("VBScript.RegExp")
re.Pattern = Pattern
re.IgnoreCase = IgnoreCase
re.Global = Global
RESULT = re.Test(str)
FEND
//////////////////////////////////////////////////
// 【引数】
//   inputs : 繰り返す文字列 
//   multiplier : inputsを繰り返す回数 
// 【戻値】
//   inputsをmultiplier回を繰り返した文字列を返します 
//////////////////////////////////////////////////
FUNCTION strRepeat(inputs, multiplier)
DIM res = ""
FOR n = 1 TO multiplier
res = res + inputs
NEXT
RESULT = res
FEND
//////////////////////////////////////////////////
// 【引数】
//   serial : シリアル値 
//   format : フォーマット 
// 【戻値】
//   数値を表示書式に基づいて変換した文字列 
//////////////////////////////////////////////////
FUNCTION text(serial, format, hour12 = FALSE)
HASHTBL startDate
startDate["明治"] = "1868/01/25"
startDate["大正"] = "1912/07/30"
startDate["昭和"] = "1926/12/25"
startDate["平成"] = "1989/01/08"
startDate["令和"] = "2019/05/01"
DIM baseDate = "1899/12/30"
SELECT TRUE
CASE reTest(format, "\[h+\]")
Matches = reExecute(format, "\[(h+)\]")
DIM hour = iif(hour12, Hour(serial) MOD 12, Hour(serial))
RESULT = text(hour, strRepeat("0", LENGTH(Matches.Item(0).SubMatches(0))))
CASE reTest(format, "^h+$")
Matches = reExecute(format, "^(h+)$")
hour = iif(hour12, Hour(serial) MOD 12, Hour(serial))
RESULT = text(hour MOD 24, strRepeat("0", LENGTH(Matches.Item(0).SubMatches(0))))
CASE reTest(format, "\[m+\]")
Matches = reExecute(format, "\[(m+)\]")
RESULT = text(serial * 1440, strRepeat("0", LENGTH(Matches.Item(0).SubMatches(0))))
CASE format = "m"
GETTIME(serial, baseDate)
RESULT = text(G_TIME_MM, "0")
CASE format = "mm"
GETTIME(serial, baseDate)
RESULT = G_TIME_MM2
CASE format = "n"
GETTIME(serial, baseDate)
RESULT = G_TIME_NN
CASE format = "nn"
GETTIME(serial, baseDate)
RESULT = G_TIME_NN2
CASE format = "s"
GETTIME(serial, baseDate)
RESULT = text(G_TIME_SS, "0")
CASE format = "ss"
GETTIME(serial, baseDate)
RESULT = G_TIME_SS2
CASE format = "yyyy"
GETTIME(serial, baseDate)
RESULT = G_TIME_YY4
CASE format = "yy"
GETTIME(serial, baseDate)
RESULT = COPY(G_TIME_YY4, 3, 2)
CASE format = "e"
SELECT TRUE
CASE dateDiff("d", startDate["令和"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(serial, "yyyy") - 2018
CASE dateDiff("d", startDate["平成"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(serial, "yyyy") - 1988
CASE dateDiff("d", startDate["昭和"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(serial, "yyyy") - 1925
CASE dateDiff("d", startDate["大正"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(serial, "yyyy") - 1911
CASE dateDiff("d", startDate["明治"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(serial, "yyyy") - 1867
SELEND
CASE format = "ee"
SELECT TRUE
CASE dateDiff("d", startDate["令和"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(text(serial, "yyyy") - 2018, "00")
CASE dateDiff("d", startDate["平成"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(text(serial, "yyyy") - 1988, "00")
CASE dateDiff("d", startDate["昭和"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(text(serial, "yyyy") - 1925, "00")
CASE dateDiff("d", startDate["大正"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(text(serial, "yyyy") - 1911, "00")
CASE dateDiff("d", startDate["明治"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(text(serial, "yyyy") - 1867, "00")
SELEND
CASE format = "g"
SELECT TRUE
CASE dateDiff("d", startDate["令和"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "R"
CASE dateDiff("d", startDate["平成"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "H"
CASE dateDiff("d", startDate["昭和"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "S"
CASE dateDiff("d", startDate["大正"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "T"
CASE dateDiff("d", startDate["明治"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "M"
SELEND
CASE format = "gg"
RESULT = COPY(text(serial, "ggg"), 1, 1)
CASE format = "ggg"
SELECT TRUE
CASE dateDiff("d", startDate["令和"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "令和"
CASE dateDiff("d", startDate["平成"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "平成"
CASE dateDiff("d", startDate["昭和"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "昭和"
CASE dateDiff("d", startDate["大正"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "大正"
CASE dateDiff("d", startDate["明治"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "明治"
SELEND
CASE format = "mmmmm"
RESULT = COPY(text(serial, "mmmm"), 1, 1)
CASE format = "mmmm"
DIM month[] = "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
RESULT = month[text(serial, "m") - 1]
CASE format = "mmm"
RESULT = COPY(text(serial, "mmmm"), 1, 3)
CASE format = "dd"
GETTIME(serial, baseDate)
RESULT = text(G_TIME_DD2, "00")
CASE format = "d"
GETTIME(serial, baseDate)
RESULT = text(G_TIME_DD, "0")
CASE reTest(format, "^[ad]{3,4}$")
Matches = reExecute(format, "([ad]{3,4})")
GETTIME(serial, baseDate)
RESULT = getWeekdayName(G_TIME_WW, Matches.Item(0).SubMatches(0))
CASE reTest(format, "(0+\.?0+)?%")
Matches = reExecute(format, "(0+\.?0+)?%")
RESULT = text(serial * 100, Matches.Item(0).SubMatches(0)) + "%"
CASE reTest(format, "^\[DBNum\d{1,4}\](.*?)$")
Matches = reExecute(format, "^\[DBNum(\d{1,4})\](.*?)$")
DIM value = VAL(Matches.Item(0).SubMatches(0))
DIM sss = text(serial, Matches.Item(0).SubMatches(1))
Matches = reExecute(sss, "(\D+)?(\d+)(\D+)?")
DIM res = ""
FOR m = 0 TO Matches.Count - 1
serial = Matches.Item(m).SubMatches(1)
SELECT value
CASE 1, 2
DIM n[][9] = "〇", "一", "二", "三", "四", "五", "六", "七", "八", "九", + _
"", "壱", "弐", "参", "四", "伍", "六", "七", "八", "九"
DIM a[][3] = "", "十", "百", "千", + _
"", "拾", "百", "阡"
DIM b[][3] = "", "万", "億", "兆", + _
"", "萬", "億", "兆"
DIM r = ""
DIM j = 0
type = value - 1
REPEAT
DIM str = ""
DIM n4 = serial MOD 10000
FOR i = LENGTH(n4) TO 1 STEP -1
s = COPY(n4, i, 1)
IFB s = 1 AND a[type][LENGTH(n4)-i] <> "" THEN
str = IIF(s, a[type][LENGTH(n4)-i], "") + str
ELSE	
str = n[type][s] + IIF(s, a[type][LENGTH(n4)-i], "") + str
ENDIF
NEXT
IF str <> "" THEN r = str + b[type][j] + r
j = j + 1
serial = INT(serial / 10000)
UNTIL serial = 0
res = res + Matches.Item(m).SubMatches(0) + r + Matches.Item(m).SubMatches(2)
CASE 3
res = res + Matches.Item(m).SubMatches(0) + STRCONV(serial, SC_FULLWIDTH) + Matches.Item(m).SubMatches(2)
CASE 4
res = res + Matches.Item(m).SubMatches(0) + STRCONV(serial, SC_HALFWIDTH) + Matches.Item(m).SubMatches(2)
SELEND
NEXT
RESULT = res
CASE reTest(format, "^(.*?)(AM\/PM|am\/pm|A\/P|a\/p)(.*?)$")
Matches = reExecute(format, "^(.*?)(AM\/PM|am\/pm|A\/P|a\/p)(.*?)$")
DIM array = SPLIT(Matches.Item(0).SubMatches(1), "/")
ampm = array[IIF(serial - INT(serial) >= 0.5, 1, 0)]
hour12 = TRUE
res = ""
WITH Matches.Item(0)
res = text(serial, .SubMatches(0), hour12) + ampm + text(serial, .SubMatches(2), hour12)
ENDWITH
RESULT = res
CASE reTest(format, "([^ymdagehns]{0,})?(([ymdagehns])\3{0,})([^ymdagehns]+)?")
Matches = reExecute(format, "([^ymdagehns]{0,})?(([ymdagehns])\3{0,})([^ymdagehns]+)?")
FOR n = 0 TO Matches.Count - 1
IF n = 0 THEN res = Matches.Item(n).SubMatches(0)
NEXT
FOR n = 0 TO Matches.Count - 1
WITH Matches.Item(n)
res = res + text(serial, .SubMatches(1), hour12) + .SubMatches(3)
ENDWITH
NEXT
RESULT = res
CASE format = "0/0"
DIM separator = POS(".", serial)
DIM g = 0
IFB separator <> 0 THEN
DIM keta = LENGTH(serial)
DIM shift = POWER(10, keta - separator)
IFB shift >= POWER(10, 15) THEN
DIM position = 0
FOR i = 0 TO 14
IFB serial * POWER(10, i) - serial >= 1 THEN
position = i
BREAK
ENDIF
NEXT
tmp = serial * POWER(10, position)
FOR i = 1 TO 15
r = (tmp * POWER(10, i)) / serial - (tmp / serial)
a1 = tmp * POWER(10, i) - tmp
IF a1 = INT(a1) THEN BREAK 
NEXT
DIM frac[] = a1, r
g = GCD(frac)
RESULT = (a1/g) + "/" + (r/g)
ELSE
DIM molecule = serial * shift	// 分子
DIM denominator = shift		// 分母
DIM nums[] = molecule, denominator
g = GCD(nums)
molecule = molecule / g
denominator = denominator / g
RESULT = molecule + "/" + denominator
ENDIF
ELSE
RESULT = serial + "/1"
ENDIF
CASE reTest(format, "(0+)\.?(0+)?") AND UBound(SPLIT(format, ".")) <= 1 
Matches = reExecute(format, "(0+)\.?(0+)?")
len1 = LENGTH(Matches.Item(0).SubMatches(0))
len2 = LENGTH(Matches.Item(0).SubMatches(1))
DIM arr[] = LENGTH(INT(serial)), len1
IFB POS(".", format) THEN
RESULT = REPLACE(FORMAT(serial, CALCARRAY(arr, CALC_MAX) + len2 + 1, len2), " ", "0")
ELSE
RESULT = REPLACE(FORMAT(serial, CALCARRAY(arr, CALC_MAX)), " ", "0")
ENDIF
SELEND
FEND
//////////////////////////////////////////////////
// 【引数】
//   配列 : 上限値を求める配列 
// 【戻値】
//   配列の上限値 
//////////////////////////////////////////////////
FUNCTION UBound(array[])
RESULT = RESIZE(array)
FEND
//////////////////////////////////////////////////
// 【引数】
//   uwscTime : UWSC時間 
// 【戻値】
//   シリアル値 
//////////////////////////////////////////////////
FUNCTION uwscToSerial(uwscTime)
uwscDate = uwscTime / 86400
RESULT = 36526 + uwscDate
FEND
    (6,10) (8,38,46) (15,27) (21) (21) (24) (25) (26) (27) (33) (33) (37) (40,41) (41) (44) (45) (45) (47)

全ファイルをサブフォルダから直下に取り出す

「D:\Pictures\100ANDRO\」より下層フォルダにあるファイルを直下に移動させます。ファイル名が重複する場合は「 - コピー」、「 - コピー (2)」のような連番をつけて変更されます。

空になったフォルダを削除するにはdeleteEmptyFoldersを使います。

CONST FOF_RENAMEONCOLLISION = 8
DIM folderspec = "D:\Pictures\100ANDRO\"
DIM array = getFileList(folderspec)
DIM Shell = CREATEOLEOBJ("Shell.Application")
DIM Folder = Shell.NameSpace(folderspec)
DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
FOR item IN array
IF FSO.FolderExists(item) THEN CONTINUE
PRINT Folder.Self.Path
PRINT item
Folder.MoveHere(item, FOF_RENAMEONCOLLISION)
NEXT
//////////////////////////////////////////////////
// 【引数】
//   folderspec : フォルダのパス 
//   TextStream : TextStreamオブジェクト 
//   filename : 一時ファイル名 
//   bool : 再帰呼び出しの深さが最上部か 
// 【戻値】
//   
//////////////////////////////////////////////////
FUNCTION getFileList(folderspec, TextStream = NOTHING, filename = "", bool = TRUE)
DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
IFB TextStream = NOTHING THEN
CONST TemporaryFolder = 2
DIM TempFolder = FSO.GetSpecialFolder(TemporaryFolder)
DIM TempFolderspec = TempFolder.Path
DIM name = FSO.GetTempName
filename = FSO.BuildPath(Tempfolderspec, name)
TextStream = FSO.CreateTextFile(filename)
ENDIF
DIM Folder = FSO.GetFolder(folderspec)
DIM Folders = Folder.SubFolders
FOR Folder IN Folders
getFileList(Folder.Path, TextStream, filename, FALSE)
FOR File IN Folder.Files
TextStream.WriteLine(File.Path)
NEXT
NEXT
IFB bool THEN
TextStream.Close
TextStream = FSO.OpenTextFile(filename)
DIM str = TextStream.ReadAll
TextStream.Close
FSO.DeleteFile(filename)
RESULT = SPLIT(str, "<#CR>")
ENDIF
FEND
    (4) (6,9) (7) (12)
  1. Shell.Folder.Self.Path(13)
  2. (15)

フォルダ内の音声ファイルをすべて再生

HASHTBL iColumn
DIM Shell = CREATEOLEOBJ("Shell.Application")
DIM Folder = Shell.NameSpace("C:\Windows\Media")
FOR i = 0 TO 350
iColumn[Folder.GetDetailsOf(EMPTYPARAM, i)] = i
NEXT
DIM FolderItems = Folder.Items
DIM extensions[] = ".wav", ".mid", ".avi", ".mp3"
FOR FolderItem IN FolderItems
DIM path = FolderItem.Path
IF inArray(Folder.GetDetailsOf(FolderItem, iColumn["ファイル拡張子"]), extensions) = FALSE THEN CONTINUE
FUKIDASI(path)
SOUND(path, TRUE)
NEXT
//////////////////////////////////////////////////
// 【引数】
//   needle : 探す値 
//   haystack : 配列 
//   strict 
// 【戻値】
//   TRUE : 配列中に指定した値が存在する、FALSE : 配列中に指定した値が存在しない 
//////////////////////////////////////////////////
FUNCTION inArray( needle, haystack[], strict = FALSE)
DIM res = FALSE
FOR item IN haystack
IFB needle = item THEN
res = TRUE
BREAK
ENDIF
NEXT
RESULT = res
FEND
    (3) (4) (7,15) (10) (10) (13) (14) (15) (16) (17)

指定したファイルをゴミ箱に移動する

CONST ssfBITBUCKET = 10
DIM Shell = CREATEOLEOBJ("Shell.Application")
DIM Folder = Shell.NameSpace(ssfBITBUCKET)
DIM source = "D:\Desktop\sample.txt"
Folder.MoveHere(source)
    (3) (4) (7)

デスクトップのパスを取得

CONST ssfDesktop = 0
DIM Shell = CREATEOLEOBJ("Shell.Application")
DIM Folder = Shell.NameSpace(ssfDesktop)
PRINT Folder.Self.Path
    (3) (4)
結果
D:\Desktop

デスクトップにあるアイテムの数

CONST ssfDesktop = 0
DIM Shell = CREATEOLEOBJ("Shell.Application")
DIM Folder = Shell.NameSpace(ssfDesktop)
DIM FolderItems = Folder.Items
PRINT FolderItems.Count
    (4) (5) (7)
結果
25

右クリックメニュー取得

CONST ssfDesktop = 0
DIM Shell = CREATEOLEOBJ("Shell.Application")
DIM Folder = Shell.NameSpace(ssfDesktop)
DIM FolderItem = Folder.ParseName("sample.txt")
DIM FolderItemVerbs = FolderItem.Verbs
FOR i = 0 TO FolderItemVerbs.Count - 1
PRINT FolderItemVerbs.Item(i).Name
NEXT
    (4) (5) (7)
  1. Shell.FolderItemsVerbs(7)
  2. Shell.FolderItemsVerbs.Count(9)
  3. Shell.FolderItemsVerbs.Item(10)
  4. Shell.FolderItemsVerb.Name(10)
結果
開く(&O)
印刷(&P)
編集(&E)
ALZipで圧縮(&L)
管理者権限で圧縮(&Y)
"a.zip" で圧縮(&Q)
コピー(&C)
削除(&D)
共有​​
以前のバージョンの復元(&V)
切り取り(&T)
コピー(&C)
ショートカットの作成(&S)
削除(&D)
名前の変更(&M)
プロパティ(&R)

画像ファイルの情報を取得

「ピクチャ\100ANDRO\20210314」にある画像ファイルの情報を出力。

CONST ssfMYPICTURES = 39
HASHTBL iColumn
DIM Shell = CREATEOLEOBJ("Shell.Application")
DIM Folder = Shell.NameSpace(ssfMYPICTURES)
DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
DIM path = FSO.BuildPath(Folder.Self.Path, "100ANDRO\20210314")
Folder = Shell.NameSpace(path)
FolderItems = Folder.Items
FOR n = 0 TO 350
iColumn[Folder.GetDetailsOf(EMPTYPARAM, n)] = n
NEXT
DIM temp = uniqueFilename(FSO.BuildPath(path, "Info.csv"))
FSO.CreateTextFile(temp, FALSE, FALSE)
DIM FID = FOPEN(temp, F_READ OR F_WRITE)
DIM array[] = "ファイル名", "撮影日時", "幅", "高さ", "サイズ", "ビットの深さ", "パス", "焦点距離", "向き"
FOR i = 1 TO UBound(array)
FPUT(FID, array[i], 1, i)
NEXT
DIM row = 2
DIM extensions[] = ".jpg", ".jpeg", ".png", ".bmp"
FOR FolderItem IN FolderItems
FUKIDASI(row + "/" + FolderItems.Count)
IF inArray(Folder.GetDetailsOf(FolderItem, iColumn["ファイル拡張子"]), extensions) = FALSE THEN CONTINUE
FOR i = 1 TO UBound(array)
FPUT(FID, Folder.GetDetailsOf(FolderItem, iColumn[array[i]]), row, i)
NEXT
row = row + 1
NEXT
FCLOSE(FID)
//////////////////////////////////////////////////
// 【引数】
//   needle : 探す値 
//   haystack : 配列 
//   strict 
// 【戻値】
//   TRUE : 配列中に指定した値が存在する、FALSE : 配列中に指定した値が存在しない 
//////////////////////////////////////////////////
FUNCTION inArray( needle, haystack[], strict = FALSE)
DIM res = FALSE
FOR item IN haystack
IFB needle = item THEN
res = TRUE
BREAK
ENDIF
NEXT
RESULT = res
FEND
//////////////////////////////////////////////////
// 【引数】
//   配列 : 上限値を求める配列 
// 【戻値】
//   配列の上限値 
//////////////////////////////////////////////////
FUNCTION UBound(array[])
RESULT = RESIZE(array)
FEND
//////////////////////////////////////////////////
// 【引数】
//   path : ファイルのパス 
// 【戻値】
//   重複しないファイル名 
//////////////////////////////////////////////////
FUNCTION uniqueFilename(path)
DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
IFB FSO.FileExists(path) THEN
DIM fol = FSO.GetParentFolderName(path)
DIM filename = FSO.GetBaseName(path)
DIM extension = FSO.GetExtensionName(path)
DIM i = 2
WHILE FSO.FileExists(FSO.BuildPath(fol, filename + " (" + i + ")." + extension))
i = i + 1
WEND
RESULT = FSO.BuildPath(fol, filename + " (" + i + ")." + extension)
ELSE
RESULT = path
ENDIF
FEND
    (5,7) (6,9) (8) (10) (16) (17) (19) (23,33) (24,34) (31) (32) (32) (39)

デフォルトプリンターを取得

CONST ssfPRINTERS = 4
DIM Shell = CREATEOLEOBJ("Shell.Application")
DIM Folder = Shell.NameSpace(ssfPRINTERS)
DIM FolderItems = Folder.Items
HASHTBL iColumn
FOR n = 0 TO 350
iColumn[Folder.GetDetailsOf(EMPTYPARAM, n)] = n
NEXT
FOR n = 0 TO FolderItems.Count - 1
DIM FolderItem = FolderItems.Item(n)
DIM PrinterName = Folder.GetDetailsOf(FolderItem, iColumn["名前"])
FOR i = 0 TO FolderItem.Verbs.Count - 1
IF POS("通常使うプリンターに設定", FolderItem.Verbs.Item(i).Name) <> 0 THEN CONTINUE 2
NEXT
PRINT PrinterName
BREAK
NEXT
    (3) (4) (5) (10,15) (14) (14) (17) (17) (17) (17)
結果
Brother DCP-J963N Printer

歌ネットから歌詞を取得してテキストファイルに保存

CONST ssfDesktop = 0
DIM IE = CREATEOLEOBJ("InternetExplorer.Application")
IE.Visible = TRUE
IE.Navigate("https://www.uta-net.com/song/280568/")
BusyWait(IE)
DIM element, elements, name, lyrics
element = IE.document.getElementById("view_kashi")
elements = element.getElementsByClassName("title")
name = TRIM(elements.Item(0).innerText)
element = IE.document.getElementById("kashi_area")
lyrics = element.innerText
IE.Quit
DIM Shell = CREATEOLEOBJ("Shell.Application")
DIM Folder = Shell.NameSpace(ssfDesktop)
DIM path = Folder.Self.Path
DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
path = uniqueFilename(FSO.BuildPath(path, name + ".txt"))
DIM FID = FOPEN(path, F_READ OR F_WRITE)
FPUT(FID, lyrics)
FCLOSE(FID)
//////////////////////////////////////////////////
// 【引数】
//   IE : IEオブジェクト 
// 【戻値】
//   
//////////////////////////////////////////////////
PROCEDURE BusyWait(Var IE)
SLEEP(0.500)
DIM t = GETTIME()
TRY
REPEAT
DIM tm = GETTIME() - t
FUKIDASI("BusyWait:" + tm)
SLEEP(0.010)
IF tm >= 60 THEN BREAK
UNTIL !IE.Busy AND IE.readyState = 4
EXCEPT
IE = getIEObj(-1)
PRINT IE.document.URL + " のIEオブジェクトを取得しました。"
BusyWait(IE)
ENDTRY
FUKIDASI()
FEND
//////////////////////////////////////////////////
// 【引数】
//   文字列 or 数値 : 取得したいIEオブジェクトのタイトル・URLもしくは数値を指定 
//   完全一致フラグ : (TRUE : 文字列が完全一致したものを取得、FALSE : 文字列の一部を含むものを取得) 
// 【戻値】
//   Internet Explorerオブジェクト 
//////////////////////////////////////////////////
FUNCTION getIEObj(str, flg = FALSE)
DIM Shell = CREATEOLEOBJ("Shell.Application")
SELECT CHKNUM(str)
CASE TRUE
DIM cnt = 0
SELECT TRUE
CASE str > 0
FOR n = 0 TO Shell.Windows.Count - 1
TRY
IFB Shell.Windows.Item(n).Name = "Internet Explorer" THEN
cnt = cnt + 1
IFB str = cnt THEN
RESULT = Shell.Windows.Item(n)
EXIT
ENDIF
ENDIF
EXCEPT
ENDTRY
NEXT
CASE str < 0
FOR n = Shell.Windows.Count - 1 TO 0 STEP -1
TRY
IFB Shell.Windows.Item(n).Name = "Internet Explorer" THEN
cnt = cnt + 1
IFB ABS(str) = cnt THEN
RESULT = Shell.Windows.Item(n)
EXIT
ENDIF
ENDIF
EXCEPT
ENDTRY
NEXT
CASE str = 0
FOR n = 0 TO Shell.Windows.Count - 1
TRY
IF Shell.Windows.Item(n).Name = "Internet Explorer" THEN cnt = cnt + 1
EXCEPT
ENDTRY
NEXT
RESULT = cnt
EXIT
SELEND
CASE FALSE
DIM t = GETTIME()
REPEAT
FOR n = 0 TO Shell.Windows.Count - 1
TRY
DIM targetObj = Shell.Windows.Item(n)
IFB targetObj.Name = "Internet Explorer" THEN
SELECT flg
CASE TRUE
IFB targetObj.document.title = str OR targetObj.LocationURL = str THEN
RESULT = Shell.Windows.Item(n)
EXIT
ENDIF
CASE FALSE
IFB POS(str, targetObj.document.title) OR POS(str, targetObj.LocationURL) THEN
RESULT = Shell.Windows.Item(n)
EXIT
ENDIF
SELEND
ENDIF
EXCEPT
ENDTRY
NEXT
UNTIL GETTIME() - t >= 5
SELEND
RESULT = ERR_VALUE
FEND
//////////////////////////////////////////////////
// 【引数】
//   path : ファイルのパス 
// 【戻値】
//   重複しないファイル名 
//////////////////////////////////////////////////
FUNCTION uniqueFilename(path)
DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
IFB FSO.FileExists(path) THEN
DIM fol = FSO.GetParentFolderName(path)
DIM filename = FSO.GetBaseName(path)
DIM extension = FSO.GetExtensionName(path)
DIM i = 2
WHILE FSO.FileExists(FSO.BuildPath(fol, filename + " (" + i + ")." + extension))
i = i + 1
WEND
RESULT = FSO.BuildPath(fol, filename + " (" + i + ")." + extension)
ELSE
RESULT = path
ENDIF
FEND
    ([3,19,22]) (4) (5) (6) ([) (10) (11) (20) (23) (25) (26) (27)

指定したフォルダの曲名と合計時間を出力

DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
DIM Excel = CREATEOLEOBJ("Excel.Application")
DIM Shell = CREATEOLEOBJ("Shell.Application")
DIM Folder = Shell.NameSpace("D:\Music\Hey! Say! JUMP\COSMIC☆HUMAN")
DIM serial
HASHTBL iColumn
FOR n = 0 TO 350
iColumn[Folder.GetDetailsOf(EMPTYPARAM, n)] = n
NEXT
FOR n = 0 TO Folder.Items.Count - 1
WITH Folder
DIM FolderItem = .Items.Item(n)
PRINT .GetDetailsOf(FolderItem, iColumn["名前"])
serial = serial + timeValue(.GetDetailsOf(FolderItem, iColumn["長さ"]))
ENDWITH
NEXT
PRINT "----------"
PRINT "合計時間<#TAB>" + text(serial, "h:m:s")
//////////////////////////////////////////////////
// 【引数】
//   interval : 加算する時間間隔を表す文字列式(yyyy:年、m:月、d:日、ww:週、h:時、n:分、s:秒) 
//   num : dateに加算する値。未来は正、過去は負で指定 
//   date : 時間間隔を加算する日付 
// 【戻値】
//   日時(date)に、指定した単位(interval)の時間(num)を加算して返します 
//////////////////////////////////////////////////
FUNCTION dateAdd(interval, num, date)
DIM year, month, day, d
GETTIME(0, date)
DIM time = G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2
SELECT interval
CASE "yyyy"
d = (G_TIME_YY + num) + "/" + G_TIME_MM2 + "/" + G_TIME_DD2
IF time <> "00:00:00" THEN d = d + " " + time
CASE "m"
IFB num > 0 THEN
year = G_TIME_YY + INT((G_TIME_MM + num) / 12)
month = REPLACE(FORMAT(((G_TIME_MM + num) MOD 12), 2), " ", "0")
ELSE
year = G_TIME_YY + CEIL((G_TIME_MM + num) / 12 - 1)
month = REPLACE(FORMAT(G_TIME_MM - (ABS(num) MOD 12), 2), " ", "0")
ENDIF
IF month = "00" THEN month = 12
day = G_TIME_DD2
d = "" + year + month + day
IFB !isDate(d) THEN
d = year + "/" + month + "/" + "01"
d = getEndOfMonth(d)
ELSE
d = year + "/" + month + "/" + day
ENDIF
IF time <> "00:00:00" THEN d = d + " " + time
CASE "d"
t = GETTIME(num, date)
d = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2 + IIF(t MOD 86400, " " + G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2, "")
CASE "ww"
t = GETTIME(num * 7, date)
d = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2 + IIF(t MOD 86400, " " + G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2, "")
CASE "h"
t = GETTIME(num / 24, date)
d = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2 + IIF(t MOD 86400, " " + G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2, "")
CASE "n"
t = GETTIME(num / 1440, date)
d = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2 + IIF(t MOD 86400, " " + G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2, "")
CASE "s"
t = GETTIME(num / 86400, date)
d = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2 + IIF(t MOD 86400, " " + G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2, "")
SELEND
RESULT = d
FEND
//////////////////////////////////////////////////
// 【引数】
//   interval : 時間単位(yyyy︰年、q:四半期、m︰月、d︰日、w:週日、ww:週、h:時、n:分、s:秒) 
//   date1 : 日時1 
//   date2 : 日時2 
// 【戻値】
//   date2からdate1を引いた時間間隔を求めます。 
//////////////////////////////////////////////////
FUNCTION dateDiff(interval, date1, date2)
DIM y1, y2, m1, m2, d1, d2, d
SELECT interval
CASE "yyyy"
GETTIME(0, date1)
y1 = G_TIME_YY
GETTIME(0, date2)
y2 = G_TIME_YY
d = y2 - y1
CASE "q"
GETTIME(0, date1)
y1 = G_TIME_YY
m1 = G_TIME_MM
GETTIME(0, date2)
y2 = G_TIME_YY
m2 = G_TIME_MM
d = y2 * 4 + CEIL(m2/3) - (y1 * 4 + CEIL(m1/3))
CASE "m"
GETTIME(0, date1)
y1 = G_TIME_YY
m1 = G_TIME_MM
GETTIME(0, date2)
y2 = G_TIME_YY
m2 = G_TIME_MM
d = (y2 - y1) * 12 + m2 - m1
CASE "d"
d1 = GETTIME(0, date1)
d2 = GETTIME(0, date2)
d = (d2 - d1) / 86400
CASE "w"
d = INT(dateDiff("d", date1, date2) / 7)
CASE "ww"
date1 = dateAdd("d", -1 * getWeekday(date1), date1)
d = INT(dateDiff("d", date1, date2) / 7)
CASE "h"
d = dateDiff("d", date1, date2) * 24
CASE "n"
d = dateDiff("d", date1, date2) * 1440
CASE "s"
d = dateDiff("d", date1, date2) * 86400
SELEND
RESULT = d
FEND
//////////////////////////////////////////////////
// 【引数】
//   arr : 最大公約数を求める数値を格納した配列 
// 【戻値】
//   最大公約数 
//////////////////////////////////////////////////
FUNCTION GCD(arr[])
DIM c = LENGTH(arr)
DIM rem = arr[c-1] MOD arr[c-2]
IFB rem = 0 THEN
IFB LENGTH(arr) = 2 THEN
RESULT = arr[c-2]
EXIT
ENDIF
RESIZE(arr, c-2)
RESULT = GCD(arr)
EXIT
ENDIF
arr[c-1] = arr[c-2]
arr[c-2] = rem
RESULT = GCD(arr)
FEND
//////////////////////////////////////////////////
// 【引数】
//   date : 日付(”YYYYMMDD” or “YYYY/MM/DD” or “YYYY-MM-DD” or “YYYYMMDDHHNNSS” or “YYYY/MM/DD HH:NN:SS”) 
//   m : 第一引数の指定日からプラスマイナス m 月とする(デフォルト=0) 
// 【戻値】
//   date から m 月後の月末の日付 
//////////////////////////////////////////////////
FUNCTION getEndOfMonth(date, m = 0)
date = dateAdd("m", m + 1, date)
GETTIME(0, date)
GETTIME(-G_TIME_DD, date)
RESULT = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2
FEND
//////////////////////////////////////////////////
// 【引数】
//   date
(”YYYYMMDD” or “YYYY/MM/DD” or “YYYY-MM-DD” or “YYYYMMDDHHNNSS” or “YYYY/MM/DD HH:NN:SS”) : 
// 【戻値】
//   曜日 (0:日曜…、6:土曜) 
//////////////////////////////////////////////////
FUNCTION getWeekday(date)
GETTIME(0, date)
RESULT = G_TIME_WW
FEND
//////////////////////////////////////////////////
// 【引数】
//   数値 : GETTIMEで取得した曜日の番号(G_TIME_WW=0:日曜….6:土曜) 
//   フォーマット : 以下のアルファベットは数値で指定した対応する曜日に置き換えられます。(aaa : 日〜土、aaaa : 日曜日〜土曜日、ddd : Sun〜Sat、dddd : Sunday〜Saturday) 
// 【戻値】
//   数値をフォーマットした文字列を返します。 
//////////////////////////////////////////////////
FUNCTION getWeekdayName(num, format = "aaa")
DIM re = CREATEOLEOBJ("VBScript.RegExp")
DIM aaa[] = "日", "月", "火", "水", "木", "金", "土";
DIM aaaa[] = "日曜日", "月曜日", "火曜日", "水曜日", "木曜日", "金曜日", "土曜日";
DIM ddd[] = "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat";
DIM dddd[] = "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday";
match = reExecute(format, "(a|d)+")
type = match.Item(0).Value
RESULT = reReplace(format, EVAL(type + "[" + num + "]"), type)
FEND
//////////////////////////////////////////////////
// 【引数】
//   serial : 時間を表すシリアル値を指定 
// 【戻値】
//   例)0…00、0.5…12、1.0…24 
//////////////////////////////////////////////////
FUNCTION Hour(serial)
RESULT = INT(serial * 24) MOD 24
FEND
//////////////////////////////////////////////////
// 【引数】
//   expr : 評価する式 
//   truepart : 評価した式がTrueのときに返す値 
//   falsepart : 評価した式がFalseのときに返す値 
// 【戻値】
//   truepart : 評価した式がTrueのとき、falsepart : 評価した式がFalseのとき 
//////////////////////////////////////////////////
FUNCTION IIF(expr, truepart, falsepart)
IFB EVAL(expr) THEN
RESULT = truepart
ELSE
RESULT = falsepart
ENDIF
FEND
//////////////////////////////////////////////////
// 【引数】
//   date
YYYYMMDD : 
// 【戻値】
//   TRUE : 日付として認識できる、FALSE : 日付として認識できない 
//////////////////////////////////////////////////
FUNCTION isDate(date)
DIM Pattern = "^(?!([02468][1235679]|[13579][01345789])000229)(([0-9]{4}(01|03|05|07|08|10|12)(0[1-9]|[12][0-9]|3[01]))|([0-9]{4}(04|06|09|11)(0[1-9]|[12][0-9]|30))|([0-9]{4}02(0[1-9]|1[0-9]|2[0-8]))|([0-9]{2}([02468][048]|[13579][26])0229))$"
DIM Match = reExecute(date, Pattern)
RESULT = IIF(Match.Count <> 0, TRUE, FALSE)
FEND
//////////////////////////////////////////////////
// 【引数】
//   str : 正規表現による検索の対象となる文字列 
//   Pattern : 正規表現で使用するパターンを設定 
//   IgnoreCase : 大文字・小文字を区別しない場合はTrue、区別する場合はFalse 
//   Global : 文字列全体を検索する場合はTrue、しない場合はFalse 
// 【戻値】
//   正規表現で検索した結果をMatchesコレクションとして返します。 
//////////////////////////////////////////////////
FUNCTION reExecute(str, Pattern, IgnoreCase = TRUE, Global = TRUE)
DIM re = CREATEOLEOBJ("VBScript.RegExp")
re.Pattern = Pattern
re.IgnoreCase = IgnoreCase
re.Global = Global
RESULT = re.Execute(str)
FEND
//////////////////////////////////////////////////
// 【引数】
//   str1 : 置換される文字列 
//   str2 : 置換後の文字列 
//   Pattern : 置換する文字列のパターン 
//   IgnoreCase : 大文字・小文字を区別しない場合はTrue、区別する場合はFalse 
//   Global : 文字列全体を検索する場合はTrue、しない場合はFalse 
// 【戻値】
//   正規表現置換後の文字列 
//////////////////////////////////////////////////
FUNCTION reReplace(str1, str2, Pattern, IgnoreCase = TRUE, Global = TRUE)
DIM re = CREATEOLEOBJ("VBScript.RegExp")
re.Pattern = Pattern
re.IgnoreCase = IgnoreCase
re.Global = Global
RESULT = re.Replace(str1, str2)
FEND
//////////////////////////////////////////////////
// 【引数】
//   str : 正規表現による検索の対象となる文字列 
//   Pattern : 正規表現で使用するパターンを設定 
//   IgnoreCase : 大文字・小文字を区別しない場合はTrue、区別する場合はFalse 
//   Global : 文字列全体を検索する場合はTrue、しない場合はFalse 
// 【戻値】
//   正規表現にマッチするかどうか 
//////////////////////////////////////////////////
FUNCTION reTest(str, Pattern, IgnoreCase = TRUE, Global = TRUE)
DIM re = CREATEOLEOBJ("VBScript.RegExp")
re.Pattern = Pattern
re.IgnoreCase = IgnoreCase
re.Global = Global
RESULT = re.Test(str)
FEND
//////////////////////////////////////////////////
// 【引数】
//   inputs : 繰り返す文字列 
//   multiplier : inputsを繰り返す回数 
// 【戻値】
//   inputsをmultiplier回を繰り返した文字列を返します 
//////////////////////////////////////////////////
FUNCTION strRepeat(inputs, multiplier)
DIM res = ""
FOR n = 1 TO multiplier
res = res + inputs
NEXT
RESULT = res
FEND
//////////////////////////////////////////////////
// 【引数】
//   serial : シリアル値 
//   format : フォーマット 
// 【戻値】
//   数値を表示書式に基づいて変換した文字列 
//////////////////////////////////////////////////
FUNCTION text(serial, format, hour12 = FALSE)
HASHTBL startDate
startDate["明治"] = "1868/01/25"
startDate["大正"] = "1912/07/30"
startDate["昭和"] = "1926/12/25"
startDate["平成"] = "1989/01/08"
startDate["令和"] = "2019/05/01"
DIM baseDate = "1899/12/30"
SELECT TRUE
CASE reTest(format, "\[h+\]")
Matches = reExecute(format, "\[(h+)\]")
DIM hour = iif(hour12, Hour(serial) MOD 12, Hour(serial))
RESULT = text(hour, strRepeat("0", LENGTH(Matches.Item(0).SubMatches(0))))
CASE reTest(format, "^h+$")
Matches = reExecute(format, "^(h+)$")
hour = iif(hour12, Hour(serial) MOD 12, Hour(serial))
RESULT = text(hour MOD 24, strRepeat("0", LENGTH(Matches.Item(0).SubMatches(0))))
CASE reTest(format, "\[m+\]")
Matches = reExecute(format, "\[(m+)\]")
RESULT = text(serial * 1440, strRepeat("0", LENGTH(Matches.Item(0).SubMatches(0))))
CASE format = "m"
GETTIME(serial, baseDate)
RESULT = text(G_TIME_MM, "0")
CASE format = "mm"
GETTIME(serial, baseDate)
RESULT = G_TIME_MM2
CASE format = "n"
GETTIME(serial, baseDate)
RESULT = G_TIME_NN
CASE format = "nn"
GETTIME(serial, baseDate)
RESULT = G_TIME_NN2
CASE format = "s"
GETTIME(serial, baseDate)
RESULT = text(G_TIME_SS, "0")
CASE format = "ss"
GETTIME(serial, baseDate)
RESULT = G_TIME_SS2
CASE format = "yyyy"
GETTIME(serial, baseDate)
RESULT = G_TIME_YY4
CASE format = "yy"
GETTIME(serial, baseDate)
RESULT = COPY(G_TIME_YY4, 3, 2)
CASE format = "e"
SELECT TRUE
CASE dateDiff("d", startDate["令和"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(serial, "yyyy") - 2018
CASE dateDiff("d", startDate["平成"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(serial, "yyyy") - 1988
CASE dateDiff("d", startDate["昭和"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(serial, "yyyy") - 1925
CASE dateDiff("d", startDate["大正"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(serial, "yyyy") - 1911
CASE dateDiff("d", startDate["明治"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(serial, "yyyy") - 1867
SELEND
CASE format = "ee"
SELECT TRUE
CASE dateDiff("d", startDate["令和"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(text(serial, "yyyy") - 2018, "00")
CASE dateDiff("d", startDate["平成"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(text(serial, "yyyy") - 1988, "00")
CASE dateDiff("d", startDate["昭和"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(text(serial, "yyyy") - 1925, "00")
CASE dateDiff("d", startDate["大正"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(text(serial, "yyyy") - 1911, "00")
CASE dateDiff("d", startDate["明治"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(text(serial, "yyyy") - 1867, "00")
SELEND
CASE format = "g"
SELECT TRUE
CASE dateDiff("d", startDate["令和"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "R"
CASE dateDiff("d", startDate["平成"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "H"
CASE dateDiff("d", startDate["昭和"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "S"
CASE dateDiff("d", startDate["大正"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "T"
CASE dateDiff("d", startDate["明治"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "M"
SELEND
CASE format = "gg"
RESULT = COPY(text(serial, "ggg"), 1, 1)
CASE format = "ggg"
SELECT TRUE
CASE dateDiff("d", startDate["令和"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "令和"
CASE dateDiff("d", startDate["平成"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "平成"
CASE dateDiff("d", startDate["昭和"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "昭和"
CASE dateDiff("d", startDate["大正"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "大正"
CASE dateDiff("d", startDate["明治"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "明治"
SELEND
CASE format = "mmmmm"
RESULT = COPY(text(serial, "mmmm"), 1, 1)
CASE format = "mmmm"
DIM month[] = "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
RESULT = month[text(serial, "m") - 1]
CASE format = "mmm"
RESULT = COPY(text(serial, "mmmm"), 1, 3)
CASE format = "dd"
GETTIME(serial, baseDate)
RESULT = text(G_TIME_DD2, "00")
CASE format = "d"
GETTIME(serial, baseDate)
RESULT = text(G_TIME_DD, "0")
CASE reTest(format, "^[ad]{3,4}$")
Matches = reExecute(format, "([ad]{3,4})")
GETTIME(serial, baseDate)
RESULT = getWeekdayName(G_TIME_WW, Matches.Item(0).SubMatches(0))
CASE reTest(format, "(0+\.?0+)?%")
Matches = reExecute(format, "(0+\.?0+)?%")
RESULT = text(serial * 100, Matches.Item(0).SubMatches(0)) + "%"
CASE reTest(format, "^\[DBNum\d{1,4}\](.*?)$")
Matches = reExecute(format, "^\[DBNum(\d{1,4})\](.*?)$")
DIM value = VAL(Matches.Item(0).SubMatches(0))
DIM sss = text(serial, Matches.Item(0).SubMatches(1))
Matches = reExecute(sss, "(\D+)?(\d+)(\D+)?")
DIM res = ""
FOR m = 0 TO Matches.Count - 1
serial = Matches.Item(m).SubMatches(1)
SELECT value
CASE 1, 2
DIM n[][9] = "〇", "一", "二", "三", "四", "五", "六", "七", "八", "九", + _
"", "壱", "弐", "参", "四", "伍", "六", "七", "八", "九"
DIM a[][3] = "", "十", "百", "千", + _
"", "拾", "百", "阡"
DIM b[][3] = "", "万", "億", "兆", + _
"", "萬", "億", "兆"
DIM r = ""
DIM j = 0
type = value - 1
REPEAT
DIM str = ""
DIM n4 = serial MOD 10000
FOR i = LENGTH(n4) TO 1 STEP -1
s = COPY(n4, i, 1)
IFB s = 1 AND a[type][LENGTH(n4)-i] <> "" THEN
str = IIF(s, a[type][LENGTH(n4)-i], "") + str
ELSE	
str = n[type][s] + IIF(s, a[type][LENGTH(n4)-i], "") + str
ENDIF
NEXT
IF str <> "" THEN r = str + b[type][j] + r
j = j + 1
serial = INT(serial / 10000)
UNTIL serial = 0
res = res + Matches.Item(m).SubMatches(0) + r + Matches.Item(m).SubMatches(2)
CASE 3
res = res + Matches.Item(m).SubMatches(0) + STRCONV(serial, SC_FULLWIDTH) + Matches.Item(m).SubMatches(2)
CASE 4
res = res + Matches.Item(m).SubMatches(0) + STRCONV(serial, SC_HALFWIDTH) + Matches.Item(m).SubMatches(2)
SELEND
NEXT
RESULT = res
CASE reTest(format, "^(.*?)(AM\/PM|am\/pm|A\/P|a\/p)(.*?)$")
Matches = reExecute(format, "^(.*?)(AM\/PM|am\/pm|A\/P|a\/p)(.*?)$")
DIM array = SPLIT(Matches.Item(0).SubMatches(1), "/")
ampm = array[IIF(serial - INT(serial) >= 0.5, 1, 0)]
hour12 = TRUE
res = ""
WITH Matches.Item(0)
res = text(serial, .SubMatches(0), hour12) + ampm + text(serial, .SubMatches(2), hour12)
ENDWITH
RESULT = res
CASE reTest(format, "([^ymdagehns]{0,})?(([ymdagehns])\3{0,})([^ymdagehns]+)?")
Matches = reExecute(format, "([^ymdagehns]{0,})?(([ymdagehns])\3{0,})([^ymdagehns]+)?")
FOR n = 0 TO Matches.Count - 1
IF n = 0 THEN res = Matches.Item(n).SubMatches(0)
NEXT
FOR n = 0 TO Matches.Count - 1
WITH Matches.Item(n)
res = res + text(serial, .SubMatches(1), hour12) + .SubMatches(3)
ENDWITH
NEXT
RESULT = res
CASE format = "0/0"
DIM separator = POS(".", serial)
DIM g = 0
IFB separator <> 0 THEN
DIM keta = LENGTH(serial)
DIM shift = POWER(10, keta - separator)
IFB shift >= POWER(10, 15) THEN
DIM position = 0
FOR i = 0 TO 14
IFB serial * POWER(10, i) - serial >= 1 THEN
position = i
BREAK
ENDIF
NEXT
tmp = serial * POWER(10, position)
FOR i = 1 TO 15
r = (tmp * POWER(10, i)) / serial - (tmp / serial)
a1 = tmp * POWER(10, i) - tmp
IF a1 = INT(a1) THEN BREAK 
NEXT
DIM frac[] = a1, r
g = GCD(frac)
RESULT = (a1/g) + "/" + (r/g)
ELSE
DIM molecule = serial * shift	// 分子
DIM denominator = shift		// 分母
DIM nums[] = molecule, denominator
g = GCD(nums)
molecule = molecule / g
denominator = denominator / g
RESULT = molecule + "/" + denominator
ENDIF
ELSE
RESULT = serial + "/1"
ENDIF
CASE reTest(format, "(0+)\.?(0+)?") AND UBound(SPLIT(format, ".")) <= 1 
Matches = reExecute(format, "(0+)\.?(0+)?")
len1 = LENGTH(Matches.Item(0).SubMatches(0))
len2 = LENGTH(Matches.Item(0).SubMatches(1))
DIM arr[] = LENGTH(INT(serial)), len1
IFB POS(".", format) THEN
RESULT = REPLACE(FORMAT(serial, CALCARRAY(arr, CALC_MAX) + len2 + 1, len2), " ", "0")
ELSE
RESULT = REPLACE(FORMAT(serial, CALCARRAY(arr, CALC_MAX)), " ", "0")
ENDIF
SELEND
FEND
//////////////////////////////////////////////////
// 【引数】
//   str : 時刻文字列。hh:nn:ss AM/PM、hh:nn AM/PM、hh AM/PM、hh:nn:ss、hh:nn、hh時nn分ss秒、hh時nn分のいずれかの形式を指定。 
// 【戻値】
//   シリアル値 (例)0…00:00:00、0.5…12:00:00、0.999988425925926…23:59:59 
//////////////////////////////////////////////////
FUNCTION timeValue(str)
DIM serial = 0
DIM Matches
DIM pattern = "(\d+)"
DIM hh = "(0?[0-9]|1[0-2])"
DIM ampm = "([AP]M|[ap]m)"
SELECT TRUE
CASE reTest(str, "\b" + hh + ":" + pattern + ":" + pattern + " " + ampm + "\b")
Matches = reExecute(str, "\b" + hh + ":" + pattern + ":" + pattern + " " + ampm + "\b")
WITH Matches.Item(0)
serial = timeValue(.SubMatches(0) + " " + .SubMatches(3)) + VAL(.SubMatches(1)) / 1440 + VAL(.SubMatches(2)) / 86400
ENDWITH
CASE reTest(str, "\b" + hh + ":" + pattern + " " + ampm + "\b")
Matches = reExecute(str, "\b" + hh + ":" + pattern + " " + ampm + "\b")
WITH Matches.Item(0)
serial = timeValue(.SubMatches(0) + " " + .SubMatches(2)) + VAL(.SubMatches(1)) / 1440
ENDWITH
CASE reTest(str, "\b" + hh + " " + ampm + "\b")
Matches = reExecute(str, "\b" + hh + " " + ampm + "\b")
WITH Matches.Item(0)
serial = VAL(.SubMatches(0) MOD 12) + IIF(reTest(.SubMatches(1), "AM|am"), 0, 12)
serial = serial / 24
ENDWITH
CASE reTest(str, "\b" + pattern + ":" + pattern + ":" + pattern + "\b")
Matches = reExecute(str, "\b" + pattern + ":" + pattern + ":" + pattern + "\b")
WITH Matches.Item(0)
serial = VAL(.SubMatches(0)) / 24 + VAL(.SubMatches(1)) / 1440 + VAL(.SubMatches(2)) / 86400
ENDWITH
CASE reTest(str, "\b" + pattern + ":" + pattern + "\b")
Matches = reExecute(str, "\b" + pattern + ":" + pattern + "\b")
WITH Matches.Item(0)
serial = VAL(.SubMatches(0)) / 24 + VAL(.SubMatches(1)) / 1440
ENDWITH
CASE reTest(str, "\b" + pattern + "時" + pattern + "分" + pattern + "秒")
Matches = reExecute(str, "\b" + pattern + "時" + pattern + "分" + pattern + "秒")
WITH Matches.Item(0)
serial = VAL(.SubMatches(0)) / 24 + VAL(.SubMatches(1)) / 1440 + VAL(.SubMatches(2)) / 86400
ENDWITH
CASE reTest(str, "\b" + pattern + "時" + pattern + "分")
Matches = reExecute(str, "\b" + pattern + "時" + pattern + "分")
WITH Matches.Item(0)
serial = VAL(.SubMatches(0)) / 24 + VAL(.SubMatches(1)) / 1440
ENDWITH
DEFAULT
serial = ERR_VALUE
SELEND
RESULT = serial - INT(serial)
FEND
//////////////////////////////////////////////////
// 【引数】
//   配列 : 上限値を求める配列 
// 【戻値】
//   配列の上限値 
//////////////////////////////////////////////////
FUNCTION UBound(array[])
RESULT = RESIZE(array)
FEND
    ([1,2,3]) (4) (13) (13) (13) (⎜,17]) (22)
結果
01 COSMIC☆HUMAN.wav
02 SWEET or HOT?.wav
03 ルーレット.wav
04 Draw My Life!.wav
05 COSMIC☆HUMAN (オリジナル・カラオケ).wav
06 SWEET or HOT- (オリジナル・カラオケ).wav
07 ルーレット (オリジナル・カラオケ).wav
08 Draw My Life! (オリジナル・カラオケ).wav
----------
合計時間	00:34:16

指定したフォルダの動画の合計時間を求める

DIM Shell = CREATEOLEOBJ("Shell.Application")
DIM Folder = Shell.NameSpace("D:\Videos\")
DIM FolderItems = Folder.Items
DIM serial
HASHTBL iColumn
FOR n = 0 TO 350
iColumn[Folder.GetDetailsOf(EMPTYPARAM, n)] = n
NEXT
FOR n = 0 TO FolderItems.Count - 1
WITH Folder
DIM FolderItem = .Items.Item(n)
extension = .GetDetailsOf(FolderItem, iColumn["ファイル拡張子"])
IFB FolderItem.IsFolder = FALSE THEN
serial = serial + timeValue(.GetDetailsOf(FolderItem, iColumn["長さ"]))
ENDIF
ENDWITH
NEXT
PRINT text(serial, "hh:mm:ss")
//////////////////////////////////////////////////
// 【引数】
//   interval : 加算する時間間隔を表す文字列式(yyyy:年、m:月、d:日、ww:週、h:時、n:分、s:秒) 
//   num : dateに加算する値。未来は正、過去は負で指定 
//   date : 時間間隔を加算する日付 
// 【戻値】
//   日時(date)に、指定した単位(interval)の時間(num)を加算して返します 
//////////////////////////////////////////////////
FUNCTION dateAdd(interval, num, date)
DIM year, month, day, d
GETTIME(0, date)
DIM time = G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2
SELECT interval
CASE "yyyy"
d = (G_TIME_YY + num) + "/" + G_TIME_MM2 + "/" + G_TIME_DD2
IF time <> "00:00:00" THEN d = d + " " + time
CASE "m"
IFB num > 0 THEN
year = G_TIME_YY + INT((G_TIME_MM + num) / 12)
month = REPLACE(FORMAT(((G_TIME_MM + num) MOD 12), 2), " ", "0")
ELSE
year = G_TIME_YY + CEIL((G_TIME_MM + num) / 12 - 1)
month = REPLACE(FORMAT(G_TIME_MM - (ABS(num) MOD 12), 2), " ", "0")
ENDIF
IF month = "00" THEN month = 12
day = G_TIME_DD2
d = "" + year + month + day
IFB !isDate(d) THEN
d = year + "/" + month + "/" + "01"
d = getEndOfMonth(d)
ELSE
d = year + "/" + month + "/" + day
ENDIF
IF time <> "00:00:00" THEN d = d + " " + time
CASE "d"
t = GETTIME(num, date)
d = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2 + IIF(t MOD 86400, " " + G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2, "")
CASE "ww"
t = GETTIME(num * 7, date)
d = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2 + IIF(t MOD 86400, " " + G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2, "")
CASE "h"
t = GETTIME(num / 24, date)
d = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2 + IIF(t MOD 86400, " " + G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2, "")
CASE "n"
t = GETTIME(num / 1440, date)
d = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2 + IIF(t MOD 86400, " " + G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2, "")
CASE "s"
t = GETTIME(num / 86400, date)
d = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2 + IIF(t MOD 86400, " " + G_TIME_HH2 + ":" + G_TIME_NN2 + ":" + G_TIME_SS2, "")
SELEND
RESULT = d
FEND
//////////////////////////////////////////////////
// 【引数】
//   interval : 時間単位(yyyy︰年、q:四半期、m︰月、d︰日、w:週日、ww:週、h:時、n:分、s:秒) 
//   date1 : 日時1 
//   date2 : 日時2 
// 【戻値】
//   date2からdate1を引いた時間間隔を求めます。 
//////////////////////////////////////////////////
FUNCTION dateDiff(interval, date1, date2)
DIM y1, y2, m1, m2, d1, d2, d
SELECT interval
CASE "yyyy"
GETTIME(0, date1)
y1 = G_TIME_YY
GETTIME(0, date2)
y2 = G_TIME_YY
d = y2 - y1
CASE "q"
GETTIME(0, date1)
y1 = G_TIME_YY
m1 = G_TIME_MM
GETTIME(0, date2)
y2 = G_TIME_YY
m2 = G_TIME_MM
d = y2 * 4 + CEIL(m2/3) - (y1 * 4 + CEIL(m1/3))
CASE "m"
GETTIME(0, date1)
y1 = G_TIME_YY
m1 = G_TIME_MM
GETTIME(0, date2)
y2 = G_TIME_YY
m2 = G_TIME_MM
d = (y2 - y1) * 12 + m2 - m1
CASE "d"
d1 = GETTIME(0, date1)
d2 = GETTIME(0, date2)
d = (d2 - d1) / 86400
CASE "w"
d = INT(dateDiff("d", date1, date2) / 7)
CASE "ww"
date1 = dateAdd("d", -1 * getWeekday(date1), date1)
d = INT(dateDiff("d", date1, date2) / 7)
CASE "h"
d = dateDiff("d", date1, date2) * 24
CASE "n"
d = dateDiff("d", date1, date2) * 1440
CASE "s"
d = dateDiff("d", date1, date2) * 86400
SELEND
RESULT = d
FEND
//////////////////////////////////////////////////
// 【引数】
//   arr : 最大公約数を求める数値を格納した配列 
// 【戻値】
//   最大公約数 
//////////////////////////////////////////////////
FUNCTION GCD(arr[])
DIM c = LENGTH(arr)
DIM rem = arr[c-1] MOD arr[c-2]
IFB rem = 0 THEN
IFB LENGTH(arr) = 2 THEN
RESULT = arr[c-2]
EXIT
ENDIF
RESIZE(arr, c-2)
RESULT = GCD(arr)
EXIT
ENDIF
arr[c-1] = arr[c-2]
arr[c-2] = rem
RESULT = GCD(arr)
FEND
//////////////////////////////////////////////////
// 【引数】
//   date : 日付(”YYYYMMDD” or “YYYY/MM/DD” or “YYYY-MM-DD” or “YYYYMMDDHHNNSS” or “YYYY/MM/DD HH:NN:SS”) 
//   m : 第一引数の指定日からプラスマイナス m 月とする(デフォルト=0) 
// 【戻値】
//   date から m 月後の月末の日付 
//////////////////////////////////////////////////
FUNCTION getEndOfMonth(date, m = 0)
date = dateAdd("m", m + 1, date)
GETTIME(0, date)
GETTIME(-G_TIME_DD, date)
RESULT = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2
FEND
//////////////////////////////////////////////////
// 【引数】
//   date
(”YYYYMMDD” or “YYYY/MM/DD” or “YYYY-MM-DD” or “YYYYMMDDHHNNSS” or “YYYY/MM/DD HH:NN:SS”) : 
// 【戻値】
//   曜日 (0:日曜…、6:土曜) 
//////////////////////////////////////////////////
FUNCTION getWeekday(date)
GETTIME(0, date)
RESULT = G_TIME_WW
FEND
//////////////////////////////////////////////////
// 【引数】
//   数値 : GETTIMEで取得した曜日の番号(G_TIME_WW=0:日曜….6:土曜) 
//   フォーマット : 以下のアルファベットは数値で指定した対応する曜日に置き換えられます。(aaa : 日〜土、aaaa : 日曜日〜土曜日、ddd : Sun〜Sat、dddd : Sunday〜Saturday) 
// 【戻値】
//   数値をフォーマットした文字列を返します。 
//////////////////////////////////////////////////
FUNCTION getWeekdayName(num, format = "aaa")
DIM re = CREATEOLEOBJ("VBScript.RegExp")
DIM aaa[] = "日", "月", "火", "水", "木", "金", "土";
DIM aaaa[] = "日曜日", "月曜日", "火曜日", "水曜日", "木曜日", "金曜日", "土曜日";
DIM ddd[] = "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat";
DIM dddd[] = "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday";
match = reExecute(format, "(a|d)+")
type = match.Item(0).Value
RESULT = reReplace(format, EVAL(type + "[" + num + "]"), type)
FEND
//////////////////////////////////////////////////
// 【引数】
//   serial : 時間を表すシリアル値を指定 
// 【戻値】
//   例)0…00、0.5…12、1.0…24 
//////////////////////////////////////////////////
FUNCTION Hour(serial)
RESULT = INT(serial * 24) MOD 24
FEND
//////////////////////////////////////////////////
// 【引数】
//   expr : 評価する式 
//   truepart : 評価した式がTrueのときに返す値 
//   falsepart : 評価した式がFalseのときに返す値 
// 【戻値】
//   truepart : 評価した式がTrueのとき、falsepart : 評価した式がFalseのとき 
//////////////////////////////////////////////////
FUNCTION IIF(expr, truepart, falsepart)
IFB EVAL(expr) THEN
RESULT = truepart
ELSE
RESULT = falsepart
ENDIF
FEND
//////////////////////////////////////////////////
// 【引数】
//   date
YYYYMMDD : 
// 【戻値】
//   TRUE : 日付として認識できる、FALSE : 日付として認識できない 
//////////////////////////////////////////////////
FUNCTION isDate(date)
DIM Pattern = "^(?!([02468][1235679]|[13579][01345789])000229)(([0-9]{4}(01|03|05|07|08|10|12)(0[1-9]|[12][0-9]|3[01]))|([0-9]{4}(04|06|09|11)(0[1-9]|[12][0-9]|30))|([0-9]{4}02(0[1-9]|1[0-9]|2[0-8]))|([0-9]{2}([02468][048]|[13579][26])0229))$"
DIM Match = reExecute(date, Pattern)
RESULT = IIF(Match.Count <> 0, TRUE, FALSE)
FEND
//////////////////////////////////////////////////
// 【引数】
//   str : 正規表現による検索の対象となる文字列 
//   Pattern : 正規表現で使用するパターンを設定 
//   IgnoreCase : 大文字・小文字を区別しない場合はTrue、区別する場合はFalse 
//   Global : 文字列全体を検索する場合はTrue、しない場合はFalse 
// 【戻値】
//   正規表現で検索した結果をMatchesコレクションとして返します。 
//////////////////////////////////////////////////
FUNCTION reExecute(str, Pattern, IgnoreCase = TRUE, Global = TRUE)
DIM re = CREATEOLEOBJ("VBScript.RegExp")
re.Pattern = Pattern
re.IgnoreCase = IgnoreCase
re.Global = Global
RESULT = re.Execute(str)
FEND
//////////////////////////////////////////////////
// 【引数】
//   str1 : 置換される文字列 
//   str2 : 置換後の文字列 
//   Pattern : 置換する文字列のパターン 
//   IgnoreCase : 大文字・小文字を区別しない場合はTrue、区別する場合はFalse 
//   Global : 文字列全体を検索する場合はTrue、しない場合はFalse 
// 【戻値】
//   正規表現置換後の文字列 
//////////////////////////////////////////////////
FUNCTION reReplace(str1, str2, Pattern, IgnoreCase = TRUE, Global = TRUE)
DIM re = CREATEOLEOBJ("VBScript.RegExp")
re.Pattern = Pattern
re.IgnoreCase = IgnoreCase
re.Global = Global
RESULT = re.Replace(str1, str2)
FEND
//////////////////////////////////////////////////
// 【引数】
//   str : 正規表現による検索の対象となる文字列 
//   Pattern : 正規表現で使用するパターンを設定 
//   IgnoreCase : 大文字・小文字を区別しない場合はTrue、区別する場合はFalse 
//   Global : 文字列全体を検索する場合はTrue、しない場合はFalse 
// 【戻値】
//   正規表現にマッチするかどうか 
//////////////////////////////////////////////////
FUNCTION reTest(str, Pattern, IgnoreCase = TRUE, Global = TRUE)
DIM re = CREATEOLEOBJ("VBScript.RegExp")
re.Pattern = Pattern
re.IgnoreCase = IgnoreCase
re.Global = Global
RESULT = re.Test(str)
FEND
//////////////////////////////////////////////////
// 【引数】
//   inputs : 繰り返す文字列 
//   multiplier : inputsを繰り返す回数 
// 【戻値】
//   inputsをmultiplier回を繰り返した文字列を返します 
//////////////////////////////////////////////////
FUNCTION strRepeat(inputs, multiplier)
DIM res = ""
FOR n = 1 TO multiplier
res = res + inputs
NEXT
RESULT = res
FEND
//////////////////////////////////////////////////
// 【引数】
//   serial : シリアル値 
//   format : フォーマット 
// 【戻値】
//   数値を表示書式に基づいて変換した文字列 
//////////////////////////////////////////////////
FUNCTION text(serial, format, hour12 = FALSE)
HASHTBL startDate
startDate["明治"] = "1868/01/25"
startDate["大正"] = "1912/07/30"
startDate["昭和"] = "1926/12/25"
startDate["平成"] = "1989/01/08"
startDate["令和"] = "2019/05/01"
DIM baseDate = "1899/12/30"
SELECT TRUE
CASE reTest(format, "\[h+\]")
Matches = reExecute(format, "\[(h+)\]")
DIM hour = iif(hour12, Hour(serial) MOD 12, Hour(serial))
RESULT = text(hour, strRepeat("0", LENGTH(Matches.Item(0).SubMatches(0))))
CASE reTest(format, "^h+$")
Matches = reExecute(format, "^(h+)$")
hour = iif(hour12, Hour(serial) MOD 12, Hour(serial))
RESULT = text(hour MOD 24, strRepeat("0", LENGTH(Matches.Item(0).SubMatches(0))))
CASE reTest(format, "\[m+\]")
Matches = reExecute(format, "\[(m+)\]")
RESULT = text(serial * 1440, strRepeat("0", LENGTH(Matches.Item(0).SubMatches(0))))
CASE format = "m"
GETTIME(serial, baseDate)
RESULT = text(G_TIME_MM, "0")
CASE format = "mm"
GETTIME(serial, baseDate)
RESULT = G_TIME_MM2
CASE format = "n"
GETTIME(serial, baseDate)
RESULT = G_TIME_NN
CASE format = "nn"
GETTIME(serial, baseDate)
RESULT = G_TIME_NN2
CASE format = "s"
GETTIME(serial, baseDate)
RESULT = text(G_TIME_SS, "0")
CASE format = "ss"
GETTIME(serial, baseDate)
RESULT = G_TIME_SS2
CASE format = "yyyy"
GETTIME(serial, baseDate)
RESULT = G_TIME_YY4
CASE format = "yy"
GETTIME(serial, baseDate)
RESULT = COPY(G_TIME_YY4, 3, 2)
CASE format = "e"
SELECT TRUE
CASE dateDiff("d", startDate["令和"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(serial, "yyyy") - 2018
CASE dateDiff("d", startDate["平成"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(serial, "yyyy") - 1988
CASE dateDiff("d", startDate["昭和"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(serial, "yyyy") - 1925
CASE dateDiff("d", startDate["大正"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(serial, "yyyy") - 1911
CASE dateDiff("d", startDate["明治"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(serial, "yyyy") - 1867
SELEND
CASE format = "ee"
SELECT TRUE
CASE dateDiff("d", startDate["令和"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(text(serial, "yyyy") - 2018, "00")
CASE dateDiff("d", startDate["平成"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(text(serial, "yyyy") - 1988, "00")
CASE dateDiff("d", startDate["昭和"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(text(serial, "yyyy") - 1925, "00")
CASE dateDiff("d", startDate["大正"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(text(serial, "yyyy") - 1911, "00")
CASE dateDiff("d", startDate["明治"], text(serial, "yyyy/mm/dd")) >= 0
RESULT = text(text(serial, "yyyy") - 1867, "00")
SELEND
CASE format = "g"
SELECT TRUE
CASE dateDiff("d", startDate["令和"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "R"
CASE dateDiff("d", startDate["平成"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "H"
CASE dateDiff("d", startDate["昭和"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "S"
CASE dateDiff("d", startDate["大正"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "T"
CASE dateDiff("d", startDate["明治"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "M"
SELEND
CASE format = "gg"
RESULT = COPY(text(serial, "ggg"), 1, 1)
CASE format = "ggg"
SELECT TRUE
CASE dateDiff("d", startDate["令和"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "令和"
CASE dateDiff("d", startDate["平成"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "平成"
CASE dateDiff("d", startDate["昭和"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "昭和"
CASE dateDiff("d", startDate["大正"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "大正"
CASE dateDiff("d", startDate["明治"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "明治"
SELEND
CASE format = "mmmmm"
RESULT = COPY(text(serial, "mmmm"), 1, 1)
CASE format = "mmmm"
DIM month[] = "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
RESULT = month[text(serial, "m") - 1]
CASE format = "mmm"
RESULT = COPY(text(serial, "mmmm"), 1, 3)
CASE format = "dd"
GETTIME(serial, baseDate)
RESULT = text(G_TIME_DD2, "00")
CASE format = "d"
GETTIME(serial, baseDate)
RESULT = text(G_TIME_DD, "0")
CASE reTest(format, "^[ad]{3,4}$")
Matches = reExecute(format, "([ad]{3,4})")
GETTIME(serial, baseDate)
RESULT = getWeekdayName(G_TIME_WW, Matches.Item(0).SubMatches(0))
CASE reTest(format, "(0+\.?0+)?%")
Matches = reExecute(format, "(0+\.?0+)?%")
RESULT = text(serial * 100, Matches.Item(0).SubMatches(0)) + "%"
CASE reTest(format, "^\[DBNum\d{1,4}\](.*?)$")
Matches = reExecute(format, "^\[DBNum(\d{1,4})\](.*?)$")
DIM value = VAL(Matches.Item(0).SubMatches(0))
DIM sss = text(serial, Matches.Item(0).SubMatches(1))
Matches = reExecute(sss, "(\D+)?(\d+)(\D+)?")
DIM res = ""
FOR m = 0 TO Matches.Count - 1
serial = Matches.Item(m).SubMatches(1)
SELECT value
CASE 1, 2
DIM n[][9] = "〇", "一", "二", "三", "四", "五", "六", "七", "八", "九", + _
"", "壱", "弐", "参", "四", "伍", "六", "七", "八", "九"
DIM a[][3] = "", "十", "百", "千", + _
"", "拾", "百", "阡"
DIM b[][3] = "", "万", "億", "兆", + _
"", "萬", "億", "兆"
DIM r = ""
DIM j = 0
type = value - 1
REPEAT
DIM str = ""
DIM n4 = serial MOD 10000
FOR i = LENGTH(n4) TO 1 STEP -1
s = COPY(n4, i, 1)
IFB s = 1 AND a[type][LENGTH(n4)-i] <> "" THEN
str = IIF(s, a[type][LENGTH(n4)-i], "") + str
ELSE	
str = n[type][s] + IIF(s, a[type][LENGTH(n4)-i], "") + str
ENDIF
NEXT
IF str <> "" THEN r = str + b[type][j] + r
j = j + 1
serial = INT(serial / 10000)
UNTIL serial = 0
res = res + Matches.Item(m).SubMatches(0) + r + Matches.Item(m).SubMatches(2)
CASE 3
res = res + Matches.Item(m).SubMatches(0) + STRCONV(serial, SC_FULLWIDTH) + Matches.Item(m).SubMatches(2)
CASE 4
res = res + Matches.Item(m).SubMatches(0) + STRCONV(serial, SC_HALFWIDTH) + Matches.Item(m).SubMatches(2)
SELEND
NEXT
RESULT = res
CASE reTest(format, "^(.*?)(AM\/PM|am\/pm|A\/P|a\/p)(.*?)$")
Matches = reExecute(format, "^(.*?)(AM\/PM|am\/pm|A\/P|a\/p)(.*?)$")
DIM array = SPLIT(Matches.Item(0).SubMatches(1), "/")
ampm = array[IIF(serial - INT(serial) >= 0.5, 1, 0)]
hour12 = TRUE
res = ""
WITH Matches.Item(0)
res = text(serial, .SubMatches(0), hour12) + ampm + text(serial, .SubMatches(2), hour12)
ENDWITH
RESULT = res
CASE reTest(format, "([^ymdagehns]{0,})?(([ymdagehns])\3{0,})([^ymdagehns]+)?")
Matches = reExecute(format, "([^ymdagehns]{0,})?(([ymdagehns])\3{0,})([^ymdagehns]+)?")
FOR n = 0 TO Matches.Count - 1
IF n = 0 THEN res = Matches.Item(n).SubMatches(0)
NEXT
FOR n = 0 TO Matches.Count - 1
WITH Matches.Item(n)
res = res + text(serial, .SubMatches(1), hour12) + .SubMatches(3)
ENDWITH
NEXT
RESULT = res
CASE format = "0/0"
DIM separator = POS(".", serial)
DIM g = 0
IFB separator <> 0 THEN
DIM keta = LENGTH(serial)
DIM shift = POWER(10, keta - separator)
IFB shift >= POWER(10, 15) THEN
DIM position = 0
FOR i = 0 TO 14
IFB serial * POWER(10, i) - serial >= 1 THEN
position = i
BREAK
ENDIF
NEXT
tmp = serial * POWER(10, position)
FOR i = 1 TO 15
r = (tmp * POWER(10, i)) / serial - (tmp / serial)
a1 = tmp * POWER(10, i) - tmp
IF a1 = INT(a1) THEN BREAK 
NEXT
DIM frac[] = a1, r
g = GCD(frac)
RESULT = (a1/g) + "/" + (r/g)
ELSE
DIM molecule = serial * shift	// 分子
DIM denominator = shift		// 分母
DIM nums[] = molecule, denominator
g = GCD(nums)
molecule = molecule / g
denominator = denominator / g
RESULT = molecule + "/" + denominator
ENDIF
ELSE
RESULT = serial + "/1"
ENDIF
CASE reTest(format, "(0+)\.?(0+)?") AND UBound(SPLIT(format, ".")) <= 1 
Matches = reExecute(format, "(0+)\.?(0+)?")
len1 = LENGTH(Matches.Item(0).SubMatches(0))
len2 = LENGTH(Matches.Item(0).SubMatches(1))
DIM arr[] = LENGTH(INT(serial)), len1
IFB POS(".", format) THEN
RESULT = REPLACE(FORMAT(serial, CALCARRAY(arr, CALC_MAX) + len2 + 1, len2), " ", "0")
ELSE
RESULT = REPLACE(FORMAT(serial, CALCARRAY(arr, CALC_MAX)), " ", "0")
ENDIF
SELEND
FEND
//////////////////////////////////////////////////
// 【引数】
//   str : 時刻文字列。hh:nn:ss AM/PM、hh:nn AM/PM、hh AM/PM、hh:nn:ss、hh:nn、hh時nn分ss秒、hh時nn分のいずれかの形式を指定。 
// 【戻値】
//   シリアル値 (例)0…00:00:00、0.5…12:00:00、0.999988425925926…23:59:59 
//////////////////////////////////////////////////
FUNCTION timeValue(str)
DIM serial = 0
DIM Matches
DIM pattern = "(\d+)"
DIM hh = "(0?[0-9]|1[0-2])"
DIM ampm = "([AP]M|[ap]m)"
SELECT TRUE
CASE reTest(str, "\b" + hh + ":" + pattern + ":" + pattern + " " + ampm + "\b")
Matches = reExecute(str, "\b" + hh + ":" + pattern + ":" + pattern + " " + ampm + "\b")
WITH Matches.Item(0)
serial = timeValue(.SubMatches(0) + " " + .SubMatches(3)) + VAL(.SubMatches(1)) / 1440 + VAL(.SubMatches(2)) / 86400
ENDWITH
CASE reTest(str, "\b" + hh + ":" + pattern + " " + ampm + "\b")
Matches = reExecute(str, "\b" + hh + ":" + pattern + " " + ampm + "\b")
WITH Matches.Item(0)
serial = timeValue(.SubMatches(0) + " " + .SubMatches(2)) + VAL(.SubMatches(1)) / 1440
ENDWITH
CASE reTest(str, "\b" + hh + " " + ampm + "\b")
Matches = reExecute(str, "\b" + hh + " " + ampm + "\b")
WITH Matches.Item(0)
serial = VAL(.SubMatches(0) MOD 12) + IIF(reTest(.SubMatches(1), "AM|am"), 0, 12)
serial = serial / 24
ENDWITH
CASE reTest(str, "\b" + pattern + ":" + pattern + ":" + pattern + "\b")
Matches = reExecute(str, "\b" + pattern + ":" + pattern + ":" + pattern + "\b")
WITH Matches.Item(0)
serial = VAL(.SubMatches(0)) / 24 + VAL(.SubMatches(1)) / 1440 + VAL(.SubMatches(2)) / 86400
ENDWITH
CASE reTest(str, "\b" + pattern + ":" + pattern + "\b")
Matches = reExecute(str, "\b" + pattern + ":" + pattern + "\b")
WITH Matches.Item(0)
serial = VAL(.SubMatches(0)) / 24 + VAL(.SubMatches(1)) / 1440
ENDWITH
CASE reTest(str, "\b" + pattern + "時" + pattern + "分" + pattern + "秒")
Matches = reExecute(str, "\b" + pattern + "時" + pattern + "分" + pattern + "秒")
WITH Matches.Item(0)
serial = VAL(.SubMatches(0)) / 24 + VAL(.SubMatches(1)) / 1440 + VAL(.SubMatches(2)) / 86400
ENDWITH
CASE reTest(str, "\b" + pattern + "時" + pattern + "分")
Matches = reExecute(str, "\b" + pattern + "時" + pattern + "分")
WITH Matches.Item(0)
serial = VAL(.SubMatches(0)) / 24 + VAL(.SubMatches(1)) / 1440
ENDWITH
DEFAULT
serial = ERR_VALUE
SELEND
RESULT = serial - INT(serial)
FEND
//////////////////////////////////////////////////
// 【引数】
//   配列 : 上限値を求める配列 
// 【戻値】
//   配列の上限値 
//////////////////////////////////////////////////
FUNCTION UBound(array[])
RESULT = RESIZE(array)
FEND
    (1) (2) (3) ([) (12) (16) (17) (22)
結果
09:24:43

デスクトップにあるフォルダ一覧を取得

CONST ssfDesktop = 0
DIM Shell = CREATEOLEOBJ("Shell.Application")
DIM Folder = Shell.NameSpace(ssfDesktop)
DIM path = Folder.Self.Path
GETDIR(path, "\")
FOR item IN GETDIR_FILES
PRINT item
NEXT
    (3) (4)
  1. Shell.Folder.Self.Path(5)
  2. (7)

ファイルシステムかどうか

DIM Shell = CREATEOLEOBJ("Shell.Application")
DIM Folder = Shell.NameSpace("C:\Windows")
DIM FolderItems = Folder.Items
FOR n = 0 TO FolderItems.Count - 1
DIM FolderItem = FolderItems.Item(n)
WITH FolderItem
PRINT .IsFileSystem + "<#TAB>" + .Name
ENDWITH
NEXT
    (1) (2) (3) (5) (6) (8) (8)