Imports System.Text
Imports System.Runtime.InteropServices
Module MyModule
REM ********************************************************
REM * WIN32_FIND_DATA 構造体と同等のクラス定義
REM ********************************************************
< StructLayout( LayoutKind.Sequential, CharSet := CharSet.Ansi )> _
Public Class WIN32_FIND_DATA
Public fileAttributes As Integer = 0
Public creationTime_lowDateTime As Integer = 0
Public creationTime_highDateTime As Integer = 0
Public lastAccessTime_lowDateTime As Integer = 0
Public lastAccessTime_highDateTime As Integer = 0
Public lastWriteTime_lowDateTime As Integer = 0
Public lastWriteTime_highDateTime As Integer = 0
Public nFileSizeHigh As Integer = 0
Public nFileSizeLow As Integer = 0
Public dwReserved0 As Integer = 0
Public dwReserved1 As Integer = 0
< MarshalAs( UnmanagedType.ByValTStr, SizeConst := 256 )> _
Public fileName As String = Nothing
< MarshalAs( UnmanagedType.ByValTStr, SizeConst := 14 )> _
Public alternateFileName As String = Nothing
End Class
REM ********************************************************
REM * DLL 内 関数宣言
REM ********************************************************
Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" ( _
ByVal fileName As String, _
<[In], Out> ByVal findFileData As WIN32_FIND_DATA _
) As Integer
Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" ( _
ByVal hFindFile As Integer, _
<[In], Out> ByVal findFileData As WIN32_FIND_DATA _
) As Integer
REM ********************************************************
REM * 実行
REM ********************************************************
Sub Main()
Dim wfd As New WIN32_FIND_DATA()
Dim handle As Integer
Dim ret As Integer
handle = FindFirstFile( "C:\tmp\*.*", wfd )
ret = -1
Do While( handle <> -1 and ret <> 0 )
Call System.Console.WriteLine( "{1,-10} {0}", wfd.fileName, wfd.nFileSizeLow )
ret = FindNextFile( handle, wfd )
Loop
End Sub
End Module
using System;
using System.Text;
using System.Runtime.InteropServices;
public class App
{
[DllImport( "Kernel32.dll", CharSet=CharSet.Auto )]
public static extern int FindFirstFile(
String fileName,
[ In, Out ] FindData findFileData
);
[DllImport( "Kernel32.dll", CharSet=CharSet.Auto )]
public static extern int FindNextFile(
int hFindFile,
[ In, Out ] FindData findFileData
);
public static void Main() {
FindData wfd = new FindData();
int handle = FindFirstFile( "C:\\tmp\\*.*", wfd );
int ret = -1;
while( handle != -1 && ret != 0 ) {
Console.WriteLine( "{1,-10} {0}", wfd.fileName, wfd.nFileSizeLow );
ret = FindNextFile( handle, wfd );
}
}
}
[ StructLayout( LayoutKind.Sequential, CharSet=CharSet.Auto )]
public class FindData
{
public int fileAttributes = 0;
public int creationTime_lowDateTime = 0 ;
public int creationTime_highDateTime = 0;
public int lastAccessTime_lowDateTime = 0;
public int lastAccessTime_highDateTime = 0;
public int lastWriteTime_lowDateTime = 0;
public int lastWriteTime_highDateTime = 0;
public int nFileSizeHigh = 0;
public int nFileSizeLow = 0;
public int dwReserved0 = 0;
public int dwReserved1 = 0;
[ MarshalAs( UnmanagedType.ByValTStr, SizeConst=256 )]
public String fileName = null;
[ MarshalAs( UnmanagedType.ByValTStr, SizeConst=14 )]
public String alternateFileName = null;
}
Imports System.IO
Module MyModule
REM ********************************************************
REM * 実行
REM ********************************************************
Sub Main()
Try
Dim dirs As String() = Directory.GetFiles("C:\php\PEAR\", "*.*")
Console.WriteLine("ファイルの数 : {0}", dirs.Length)
Dim dir As String
Dim fi As FileInfo
For Each dir In dirs
fi = new FileInfo( dir )
dir &= " "
dir &= fi.Length
Console.WriteLine(dir)
Next
Catch e As Exception
Console.WriteLine("エラーの内容 : {0}", e.ToString())
End Try
End Sub
End Module