FileDir

種別 ファイル
説明 指定フォルダ内のファイルパスやフォルダパスを取得します。

構文 FileDir(PathName[, Attr])
引数 PathName:「*.*」などのワイルドカード方式で、ファイルパスまたはフォルダパスを表す文字列式を指定します。

Attr :16を指定すると、フォルダのみを返します。
戻り値 ファイルパスやフォルダパスを返す。ない場合はNULL("")を返します。
使用例 Dim sFile,sDir,i,sExt,sSrc,sDest,cnt

sDir = "C:\temp\" '取得するフォルダを指定
cnt = FileDir(sDir & "*.xdw")
'xdwファイルのみを取得、全ファイルなら「*.*」。戻り値はファイル数

For i=1 to cnt 'Forループで、必要な回数を回してください。
  sFile = FileDir() 'ファイルパスの取得
  
  sExt = FileInfo(sFile, 3) '拡張子の取得
  sSrc = sFile '変更元ファイル名
  sDest = sDir & Format(i, "0000") & "." & sExt'変更先ファイル名
  
  FileRename(sSrc, sDest)'ファイル名を変更する
Next i
実例  
備考 ※ 2020/04/20 戻り値をファイル名から、ファイルパスに変更しました。

関連する関数(CopyFolder、CreateFolder、FolderExists、
CommonDialog、DeleteFolder、FileCopy、FileDelete、
FileRename、FileExists、FileInfo、FileDir、FileLock)