FSO.DeleteFileデリートファイル メソッド

本ページには広告が含まれています。

指定したファイルを削除します。ごみ箱には移動せず完全に削除されます。ごみ箱に移動させる場合はFSO.DeleteFile メソッドを使います。

構文
FileSystemObject.DeleteFile( filespec, force )
引数
filespec 省略可
削除するファイルの名前を指定。最後のパスコンポーネントではワイルドカード文字を使用可。
force 省略可
読み取り専用属性が設定されているファイルを削除する場合はTrue、そうでない場合はFalse。既定値はFalse。
戻り値

プログラム実行例

システム起動時間を取得

システムの起動時間をyyyy/mm/dd, hh:nn:ssの形式で取得します。

UWSC
HASHTBL INFO

DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")

DIM filename = uniqueFilename(FSO.BuildPath(GET_CUR_DIR, "SYSTEMINFO.csv"))
FID = FOPEN(filename, F_READ OR F_WRITE)
FPUT(FID, DOSCMD("systeminfo /FO CSV"))
FCLOSE(FID)

FID = FOPEN(filename, F_READ OR F_WRITE)
FOR col = 0 TO 33
	INFO[FGET(FID, 1, col)] = FGET(FID, 2, col)
NEXT
FCLOSE(FID)

FSO.DeleteFile(filename)

PRINT INFO["システム起動時間"]

//////////////////////////////////////////////////
// 【引数】
//   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
結果
プレーンテキスト
2019/12/21, 15:53:56
使用関数
解説

Windowsの稼働時間を取得

Windowsシステムの起動時間から稼働時間を求めます。

結果はd:hh:nn:ssの形式で出力されます。

UWSC
HASHTBL INFO

DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")

DIM filename = uniqueFilename(FSO.BuildPath(GET_CUR_DIR, "SYSTEMINFO.csv"))
DIM FID = FOPEN(filename, F_READ OR F_WRITE)
FPUT(FID, DOSCMD("systeminfo /FO CSV"))
FCLOSE(FID)

FID = FOPEN(filename, F_READ OR F_WRITE)
DIM col = 1

WHILE FGET(FID, 1, col) <> ""
	INFO[FGET(FID, 1, col)] = FGET(FID, 2, col)
	col = col + 1
WEND

FCLOSE(FID)

FSO.DeleteFile(filename)

DIM startupTime = INFO["システム起動時間"]
DIM date1 = dateValue(startupTime) + timeValue(startupTime)
DIM date2 = uwscToSerial(GETTIME())
PRINT INT(date2 - date1) + ":" + text(date2 - date1, "hh:mm:ss")

//////////////////////////////////////////////////
// 【引数】
//   needle : 検索する値 
//   haystack : 配列 
// 【戻り値】
//   
//////////////////////////////////////////////////
FUNCTION arraySearch(needle, haystack[])
	DIM i = 0
	FOR item IN haystack
		IFB item = needle THEN
			RESULT = i
			EXIT
		ENDIF
		i = i + 1
	NEXT
FEND

//////////////////////////////////////////////////
// 【引数】
//   interval : 加算する時間間隔を表す文字列式(yyyy:年、m:月、d:日、ww:週、h:時、n:分、s:秒) 
//   num : dateに加算する値。未来は正、過去は負で指定 
//   date : 時間間隔を加算する日付 
// 【戻り値】
//   
//////////////////////////////////////////////////
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 
// 【戻り値】
//   
//////////////////////////////////////////////////
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、mm/dd/yyyy、dd/mm/yyyy、yyyy-mm-dd、mm-dd-yyyy、yyyy年mm月dd日、yyyy年mm月、yyyy/mm、ge/mm/dd、ge/mm、mm/dd、ggge年mm月dd日、ggge年mm月、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])"

	DIM date = ""
	DIM Months[] = "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
	
	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["month"] + "/" + Pattern["day"] + "/" + Pattern["year"])
			Matches = reExecute(str, Pattern["month"] + "/" + Pattern["day"] + "/" + Pattern["year"])
			WITH Matches.Item(0)
				IFB reTest(.SubMatches(0), "Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Ap(?:ril)?|May|Jun(?:e)?|Jul(?:y)?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?") THEN
					IFB LENGTH(.SubMatches(0)) = 3 THEN
						FOR i = 0 TO UBound(Months)
							Months[i] = COPY(Months[i], 1, 3)
						NEXT
					ENDIF
					m = arraySearch(.SubMatches(0), Months) + 1
				ELSE
					m = .SubMatches(0)
				ENDIF
				date = .SubMatches(2) + "/" + text(VAL(.SubMatches(0)), "00") + "/" + text(VAL(.SubMatches(1)), "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)?") THEN
					IFB LENGTH(.SubMatches(1)) = 3 THEN
						FOR i = 0 TO UBound(Months)
							Months[i] = COPY(Months[i], 1, 3)
						NEXT
					ENDIF
					m = arraySearch(.SubMatches(1), Months) + 1
				ELSE
					m = .SubMatches(1)
				ENDIF
				date = .SubMatches(2) + "/" + text(m, "00") + "/" + text(VAL(.SubMatches(0)), "00")
			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["month"] + "-" + Pattern["day"] + "-" + Pattern["year"])
			Matches = reExecute(str, Pattern["month"] + "-" + Pattern["day"] + "-" + Pattern["year"])
			WITH Matches.Item(0)
				IFB reTest(.SubMatches(0), "Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Ap(?:ril)?|May|Jun(?:e)?|Jul(?:y)?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?") THEN
					IFB LENGTH(.SubMatches(0)) = 3 THEN
						FOR i = 0 TO UBound(Months)
							Months[i] = COPY(Months[i], 1, 3)
						NEXT
					ENDIF
					m = arraySearch(.SubMatches(0), Months) + 1
				ELSE
					m = .SubMatches(0)
				ENDIF
				date = .SubMatches(2) + "/" + text(VAL(.SubMatches(0)), "00") + "/" + text(VAL(.SubMatches(1)), "00")
			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, 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 = IIF(.SubMatches(1)="元", 1, 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 + "/" + text(VAL(.SubMatches(2)), "00") + "/" + text(VAL(.SubMatches(1)), "00")
			ENDWITH
		CASE reTest(str, "([MTSHR])(元|\d+)/" + Pattern["month"])
			Matches = reExecute(str, "([MTSHR])(元|\d+)/" + Pattern["month"])
			WITH Matches.Item(0)
				y = IIF(.SubMatches(1)="元", 1, 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 + "/" + text(VAL(.SubMatches(2)), "00") + "/01"
			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, "(明治|大正|昭和|平成|令和)(元|\d+)年" + Pattern["month"] + "月" + Pattern["day"]+ "日")
			Matches = reExecute(str, "(明治|大正|昭和|平成|令和)(元|\d+)年" + Pattern["month"] + "月" + Pattern["day"]+ "日")
			WITH Matches.Item(0)
				y = IIF(.SubMatches(1)="元", 1, VAL(.Submatches(1)))
				SELECT .SubMatches(0)
					CASE "明治"; y = y + 1867
					CASE "大正"; y = y + 1911
					CASE "昭和"; y = y + 1925
					CASE "平成"; y = y + 1988
					CASE "令和"; y = y + 2018
				SELEND
				date = y + "/" + text(VAL(.SubMatches(2)), "00") + "/" + text(VAL(.SubMatches(3)), "00")
			ENDWITH
		CASE reTest(str, "(明治|大正|昭和|平成|令和)(元|\d+)年" + Pattern["month"] + "月")
			Matches = reExecute(str, "(明治|大正|昭和|平成|令和)(元|\d+)年" + Pattern["month"] + "月")
			WITH Matches.Item(0)
				y = IIF(.SubMatches(1)="元", 1, VAL(.Submatches(1)))
				SELECT .SubMatches(0)
					CASE "明治"; y = y + 1867
					CASE "大正"; y = y + 1911
					CASE "昭和"; y = y + 1925
					CASE "平成"; y = y + 1988
					CASE "令和"; y = y + 2018
				SELEND
				date = y + "/" + text(VAL(.SubMatches(2)), "00") + "/01"
			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
	IFB isDate(date) THEN
		RESULT = uwscToSerial(GETTIME(0, date))
	ELSE
		RESULT = ERR_VALUE
	ENDIF
FEND

//////////////////////////////////////////////////
// 【引数】
//   array : 最大公約数を求める数値を格納した配列 
// 【戻り値】
//   
//////////////////////////////////////////////////
FUNCTION GCD(array[])
	DIM c = LENGTH(array)
	DIM rem = array[c-1] MOD array[c-2]
	IFB rem = 0 THEN
		IFB LENGTH(array) = 2 THEN
			RESULT = array[c-2]
			EXIT
		ENDIF
		RESIZE(array, c-2)
		RESULT = GCD(array)
		EXIT
	ENDIF
	array[c-1] = array[c-2]
	array[c-2] = rem
	RESULT = GCD(array)
FEND

//////////////////////////////////////////////////
// 【引数】
//   date : 日付(”YYYYMMDD” or “YYYY/MM/DD” or “YYYY-MM-DD” or “YYYYMMDDHHNNSS” or “YYYY/MM/DD HH:NN:SS”) 
//   m : 第一引数の指定日からプラスマイナス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”) 
// 【戻り値】
//   
//////////////////////////////////////////////////
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 : 時間を表すシリアル値を指定 
// 【戻り値】
//   
//////////////////////////////////////////////////
FUNCTION Hour(serial)
	RESULT = INT(serial * 24) MOD 24
FEND

//////////////////////////////////////////////////
// 【引数】
//   expr : 評価する式 
//   truepart : 評価した式がTrueのときに返す値 
//   falsepart : 評価した式がFalseのときに返す値 
// 【戻り値】
//   
//////////////////////////////////////////////////
FUNCTION IIF(expr, truepart, falsepart)
	IFB EVAL(expr) THEN
		RESULT = truepart
	ELSE
		RESULT = falsepart
	ENDIF
FEND

//////////////////////////////////////////////////
// 【引数】
//   date : 存在するかを調べる日付文字列。YYYYMMDD or YYYY/MM/DD or YYYY-MM-DDのいずれかの形式。 
// 【戻り値】
//   
//////////////////////////////////////////////////
FUNCTION isDate(date)
	TRY
		GETTIME(0, date)
		RESULT = TRUE
	EXCEPT
		RESULT = FALSE
	ENDTRY
FEND

//////////////////////////////////////////////////
// 【引数】
//   str : 正規表現による検索の対象となる文字列 
//   Pattern : 正規表現で使用するパターンを設定 
//   IgnoreCase : 大文字・小文字を区別しない場合はTrue、区別する場合はFalse 
//   Global : 文字列全体を検索する場合はTrue、しない場合はFalse 
// 【戻り値】
//   
//////////////////////////////////////////////////
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を繰り返す回数 
// 【戻り値】
//   
//////////////////////////////////////////////////
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分のいずれかの形式を指定。 
// 【戻り値】
//   
//////////////////////////////////////////////////
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

//////////////////////////////////////////////////
// 【引数】
//   arrayname : 上限値を求める配列の名前 
//   dimension : 返す次元を示す整数 
// 【戻り値】
//   
//////////////////////////////////////////////////
FUNCTION UBound(arrayname[], dimension = 1)
	RESULT = EVAL("RESIZE(arrayname" + strRepeat("[0]", dimension - 1) + ")")
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

//////////////////////////////////////////////////
// 【引数】
//   uwscTime : UWSC時間 
// 【戻り値】
//   
//////////////////////////////////////////////////
FUNCTION uwscToSerial(uwscTime)
	uwscDate = uwscTime / 86400
	RESULT = 36526 + uwscDate
FEND
結果
プレーンテキスト
0:08:16:46
使用関数
解説

一時ファイルを作成・削除

UWSC
CONST TemporaryFolder = 2

DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
DIM Folder = FSO.GetSpecialFolder(TemporaryFolder)
DIM folderspec = Folder.Path
DIM filename = FSO.GetTempName
DIM path = FSO.BuildPath(folderspec, filename)

PRINT path

DIM TextStream = FSO.CreateTextFile(path)
// 現在の日時をファイルに書き込む
TextStream.WriteLine(now())
TextStream.Close

// Tempファイルを削除
// FSO.DeleteFile(path)

FUNCTION now()
	GETTIME()
	RESULT = G_TIME_YY4 + "/" + G_TIME_MM2 + "/" + G_TIME_DD2 + " " + G_TIME_HH2 + ":" + G_TIME_NN2
FEND
結果
プレーンテキスト
D:\TMP\rad83BB3.tmp
使用関数
解説

ファイルを開いているプロセスを調べる

UWSC
SETHOTKEY(VK_ESC, EMPTYPARAM, "forceQuit")

CONST TemporaryFolder = 2

DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")

WITH FSO
	DIM Folder = .GetSpecialFolder(TemporaryFolder)
	DIM folderspec = Folder.Path
	DIM filename = .GetTempName
	DIM path = .BuildPath(folderspec, filename)
ENDWITH

DIM Shell = CREATEOLEOBJ("Shell.Application")
Shell.FileRun()

DIM ID = GETID("ファイル名を指定して実行", "#32770")

SENDSTR(ID, "cmd /c openfiles /query /fo CSV > " + path)
CLKITEM(ID, "OK", CLK_BTN)
SLEEP(0.500)

REPEAT
	SLEEP(0.100)
UNTIL GETID("C:\WINDOWS\system32\cmd.exe", "ConsoleWindowClass") = -1

DIM FID = FOPEN(path, F_READ)

TRY
	DIM ID2 = GETID("使用中", "OperationStatusWindow")

	GETITEM(ID2, ITM_ACCTXT, 1)
	DIM str = ALL_ITEM_LIST[1]
	
	DIM sep = IIF(POS("フォルダー", STATUS(ID2, ST_TITLE)) <> 0, "\", "")
	DIM msg = "■" + str + "<#CR>"
	
	FOR r = 5 TO FGET(FID, F_LINECOUNT)
		IF POS("\" + str + sep,  FGET(FID, r, 3)) <> 0 THEN
			msg = msg + "ID:" + FGET(FID, r, 1) + ", プロセス名:" + FGET(FID, r, 2) + "<#CR>"
		ENDIF
	NEXT
	FCLOSE(FID)

	REPEAT
		FUKIDASI(TRIM(msg))
		SLEEP(0.100)
	UNTIL GETID("使用中", "OperationStatusWindow") = -1
FINALLY
	FSO.DeleteFile(path)
ENDTRY

//////////////////////////////////////////////////
// 【引数】
//   
// 【戻り値】
//   
//////////////////////////////////////////////////
PROCEDURE forceQuit()
	EXITEXIT
FEND

//////////////////////////////////////////////////
// 【引数】
//   expr : 評価する式 
//   truepart : 評価した式がTrueのときに返す値 
//   falsepart : 評価した式がFalseのときに返す値 
// 【戻り値】
//   
//////////////////////////////////////////////////
FUNCTION IIF(expr, truepart, falsepart)
	IFB EVAL(expr) THEN
		RESULT = truepart
	ELSE
		RESULT = falsepart
	ENDIF
FEND
使用関数
解説

関連記事

DELETEFILE関数 (スクリプト関数)
テキストファイルを削除します。
FDELLINE関数 (スクリプト関数)
テキストファイルの指定行を削除します。
FCLOSE関数 (スクリプト関数)
テキストファイルを閉じます。
FGET関数 (スクリプト関数)
テキストファイルの読み込みを行います。
FOPEN関数 (スクリプト関数)
テキストファイルを開き、ファイルIDを取得します。
GETDIR関数 (スクリプト関数)
Folder.CopyHere メソッド (Shell)
1つまたは複数のアイテムをフォルダにコピーします。
Folder.MoveHere メソッド (Shell)
1つまたは複数のアイテムをこのフォルダーに移動します。
FileSystemObject オブジェクト
FSO.GetFile メソッド
指定したパスのFile オブジェクトを返します。