0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

AccessのVBAでファイルパスから親フォルダーパスを取得(FileSystemObject使用)

Last updated at Posted at 2022-08-08

やり方

参照設定で、Microsoft Scripting Runtime にチェック入れる。
image.png
image.png

サンプルコード
Dim fso_ As New FileSystemObject
Dim folder_path_ As String
folder_path_ = fso_.GetParentFolderName("C:\Users\unko\tester.jpg")
Debug.Print folder_path_

サンプルコードの出力結果は
C:\Users\unko

注意点

GetParentFolderName という名前から フォルダー が返ってきそうだけど、実際は フォルダーパス が返ってくる。

末尾に \ は付かない

存在しないファイル のパスを引数で渡しても 例外にはならない

存在しないフォルダー のパスを引数で渡しても 例外にはならない

フォルダーのパス を渡した場合、 親フォルダーのパス が返ってくる。
(特定フォルダーの親フォルダーのパス取得という用途としても使える)

引数の値 戻り値
C:\Users\unko\ C:\Users
C:\Users\unko C:\Users

参考サイトさん

バージョン

Windows 10 Pro 21H2 OSビルド 19044.1865
Microsoft Access for Microsoft 365 MSO (バージョン 2206 ビルド 16.0.15330.20260) 32 ビット

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?