260文字以上の長いパス名を短いパス名に変える。

例えば、fso.GetFile("長いパス名").ShortPath で簡単に短いパス名に変えられそうですが、fso.GetFile("260文字以上の長いパス名").ShortPath はエラーになって使えません。
そこで、ディレクトリ階層を上に遡って、上から順に短くして行きます。

Set fso=CreateObject("Scripting.FileSystemObject")

MsgBox GetShortPathName("長~いパス名")

Function GetShortPathName(Path)
GetShortPathName=Path
If Len(Path)>259 Then
  GetShortPathName=fso.BuildPath(GetShortPathName(fso.GetParentFolderName(Path)),fso.GetFileName(Path))
  If Len(GetShortPathName)>259 Then Exit Function
End If
If fso.FileExists(GetShortPathName) Then
  GetShortPathName=fso.GetFile(GetShortPathName).ShortPath
Else
  GetShortPathName=fso.GetFolder(GetShortPathName).ShortPath
End If
End Function

パソコン・インターネット | プログラミング
2009/06/11




カテゴリー一覧
最近のコメント

このブログを友達に教える

コミュニティ | 有名人・芸能人ブログ | ケータイ占い | ケータイ小説 | 掲示板


画面TOP↑


powered by cocolog