本ページには広告が含まれています。
指定したファイルのパスを返します。
- 構文
- File.Path
- 引数
- 戻り値
File オブジェクトを返すメソッド・プロパティ
- FSO.GetFile メソッド
- 指定したパスのFile オブジェクトを返します。
- File.Path プロパティ
- コレクションから単一のオブジェクトを返します。
プログラム実行例
Windowsフォルダのファイル情報を取得
CONST WindowsFolder = 0
DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
DIM Folder = FSO.GetSpecialFolder(WindowsFolder)
PRINT "ファイル名,パス,サイズ"
FOR File IN Folder.Files
WITH File
PRINT .Name + "," + .Path + "," + formatBytes(.Size)
ENDWITH
NEXT
//////////////////////////////////////////////////
// 【引数】
// size : バイト単位で示されるデータサイズの値
// digits : 小数点以下の桁数
// unit : 変換後のデータサイズの単位。Bytes、KB、MB、GB、TB、PB、EB、ZB、YBのいずれかを指定。省略した場合は自動的に選択されます。
// 【戻り値】
//
//////////////////////////////////////////////////
FUNCTION formatBytes(size, digits = 2, unit = "")
HASHTBL prefixes
prefixes[0] = "Bytes"
prefixes[1] = "KB"
prefixes[2] = "MB"
prefixes[3] = "GB"
prefixes[4] = "TB"
prefixes[5] = "PB"
prefixes[6] = "EB"
prefixes[7] = "ZB"
prefixes[8] = "YB"
DIM i = 0
WHILE (unit <> "" OR size >= 1024) AND prefixes[i] <> unit
size = size / 1024
i = i + 1
WEND
RESULT = TRIM(FORMAT(size, LENGTH(size), digits)) + IIF(size <> 0 AND INT(size) = size, "." + strRepeat("0", digits), "") + prefixes[i]
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
//////////////////////////////////////////////////
// 【引数】
// inputs : 繰り返す文字列
// multiplier : inputsを繰り返す回数
// 【戻り値】
// inputsをmultiplier回を繰り返した文字列を返します
//////////////////////////////////////////////////
FUNCTION strRepeat(inputs, multiplier)
DIM res = ""
FOR n = 1 TO multiplier
res = res + inputs
NEXT
RESULT = res
FEND結果
ファイル名,パス,サイズ
bfsvc.exe,C:\Windows\bfsvc.exe,79.5KB
Bluestream.bmp,C:\Windows\Bluestream.bmp,2.25MB
bootstat.dat,C:\Windows\bootstat.dat,66.00KB
BRRBCOM.INI,C:\Windows\BRRBCOM.INI,15.71KB
Core.xml,C:\Windows\Core.xml,29.16KB
csup.txt,C:\Windows\csup.txt,10.00Bytes
diagerr.xml,C:\Windows\diagerr.xml,11.17KB
diagwrn.xml,C:\Windows\diagwrn.xml,11.17KB
eiunin21.exe,C:\Windows\eiunin21.exe,609.00KB
EPMBatch.ept,C:\Windows\EPMBatch.ept,1.44KB
explorer.exe,C:\Windows\explorer.exe,5.01MB
HelpPane.exe,C:\Windows\HelpPane.exe,1.03MB
hh.exe,C:\Windows\hh.exe,18.00KB
iis.log,C:\Windows\iis.log,112.45KB
iphlpapi.dll,C:\Windows\iphlpapi.dll,92.5KB
mib.bin,C:\Windows\mib.bin,42.12KB
msdfmap.ini,C:\Windows\msdfmap.ini,1.37KB
NDSTray.INI,C:\Windows\NDSTray.INI,0Bytes
notepad.exe,C:\Windows\notepad.exe,196.5KB
pala_wsxga.bmp,C:\Windows\pala_wsxga.bmp,3.71MB
pala_wuxga.bmp,C:\Windows\pala_wuxga.bmp,6.59MB
pala_wxga.bmp,C:\Windows\pala_wxga.bmp,2.93MB
pala_xga.bmp,C:\Windows\pala_xga.bmp,2.25MB
PFRO.log,C:\Windows\PFRO.log,1.31MB
py.exe,C:\Windows\py.exe,902.67KB
pyshellext.amd64.dll,C:\Windows\pyshellext.amd64.dll,56.67KB
pyw.exe,C:\Windows\pyw.exe,902.67KB
regedit.exe,C:\Windows\regedit.exe,361.5KB
setupact.log,C:\Windows\setupact.log,6.83KB
setuperr.log,C:\Windows\setuperr.log,0Bytes
splwow64.exe,C:\Windows\splwow64.exe,160.00KB
system.ini,C:\Windows\system.ini,219.00Bytes
TPSCCfg.exe,C:\Windows\TPSCCfg.exe,460.43KB
tvgadget.scr,C:\Windows\tvgadget.scr,504.00KB
twain_32.dll,C:\Windows\twain_32.dll,63.5KB
twin.dlt,C:\Windows\twin.dlt,5.55KB
win.ini,C:\Windows\win.ini,478.00Bytes
WindowsShell.Manifest,C:\Windows\WindowsShell.Manifest,670.00Bytes
WindowsUpdate.log,C:\Windows\WindowsUpdate.log,276.00Bytes
winhlp32.exe,C:\Windows\winhlp32.exe,11.5KB
WLXPGSS.SCR,C:\Windows\WLXPGSS.SCR,294.86KB
WMPrfJpn.prx,C:\Windows\WMPrfJpn.prx,22.76KB
WMSysPr9.prx,C:\Windows\WMSysPr9.prx,309.22KB
write.exe,C:\Windows\write.exe,11.00KB
_MSRSTRT.EXE,C:\Windows\_MSRSTRT.EXE,2.5KB使用関数
古いキャッシュファイルを削除する
Localフォルダ(C:\Users\username\AppData\Local\Temp \)にあるファイルの最終更新日時が7日以上前のファイルをごみ箱に移動します。
CONST ssfBITBUCKET = 10
CONST ssfLOCALAPPDATA = 28
DIM Shell = CREATEOLEOBJ("Shell.Application")
DIM Folder2 = Shell.NameSpace(ssfLOCALAPPDATA)
DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
DIM folderspec = FSO.BuildPath(Folder2.Self.Path, "Temp")
DIM FolderTemp = FSO.GetFolder(folderspec)
DIM FolderRecycle = Shell.NameSpace(ssfBITBUCKET)
DIM base = GETTIME(-7)
DIM Files = FolderTemp.Files
DIM count = Files.Count
DIM res = MSGBOX(count + "個のフォイルをごみ箱に移動します。", BTN_YES OR BTN_NO,,, BTN_NO)
IFB res = BTN_YES THEN
FOR File IN Files
DIM datetime = File.DateLastModified
IFB GETTIME(0, datetime) - base <= 0 THEN
PRINT File.Path
FolderRecycle.MoveHere(File.Path)
ENDIF
NEXT
ENDIF使用関数
関連記事
- IE.Navigate メソッド
- URLまたは絶対パスで指定されたファイルを開きます。
- Shell.Explore メソッド
- 指定したディレクトリをエクスプローラで開きます。
- FSO.GetExtensionName メソッド
- 指定したパスの最後のコンポーネントのファイル拡張子名を返します。
- getBitmap関数 (自作関数)
- 引数に指定したビットマップ画像のサイズ・幅・高さ・ビットの深さを配列で返します。
- ShellLinkObject.Path プロパティ (Shell)
- リンク オブジェクトへのパスを取得または設定します。
- DELETEFILE関数 (スクリプト関数)
- テキストファイルを削除します。
- FCLOSE関数 (スクリプト関数)
- テキストファイルを閉じます。
- FSO.BuildPath メソッド
- フォルダパスとフォルダまたはファイルの名前を結合したパス文字列を返します。
- FSO.GetFolder メソッド
- 指定したパスのFolder オブジェクトを返します。
- FGET関数 (スクリプト関数)
- テキストファイルの読み込みを行います。
