ソース掲示板




すべてから検索

キーワード   条件 表示 現行ログ 過去ログ トピックス 名前 本文
.NET Framework WIN32 API 呼び出し ( ディレクトリ内一覧 )
日時: 2009/02/21 18:36
名前: lightbox



↓Microsoft ドキュメント
引き渡す際のキャラクタセット変換
↓Console.WriteLine の書式指定
http://msdn.microsoft.com/ja-jp/library/txafckwd.aspx

拡張子:
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
メンテナンス

C# で WIN32 API 呼び出し ( ディレクトリ内一覧 ) ( No.1 )
日時: 2007/06/08 21:57
名前: lightbox


日時: 2007/06/08 21:57
名前: lightbox
拡張子:
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;
}
このアーティクルの参照用URLをクリップボードにコピー メンテナンス
VB .NET Framework ディレクトリ内【ファイル一覧】 ( No.2 )
日時: 2007/06/08 23:05
名前: lightbox
ファイルのみです
拡張子:
C:\php\PEAR\.depdb 4124
C:\php\PEAR\.depdblock 0
C:\php\PEAR\.filemap 7901
C:\php\PEAR\.lock 0
C:\php\PEAR\go-pear.phar 582211
C:\php\PEAR\Image_Canvas-0.3.0.tgz 43423
C:\php\PEAR\Image_Graph-0.7.2.tgz 368056
C:\php\PEAR\PEAR.php 35365
C:\php\PEAR\pearcmd.php 15207
C:\php\PEAR\peclcmd.php 1837
C:\php\PEAR\System.php 19956
拡張子:
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
このアーティクルの参照用URLをクリップボードにコピー メンテナンス