FileSystemInfo.LastWriteTime 속성
현재 파일이나 디렉터리에 마지막으로 쓴 시간을 가져오거나 설정합니다.
네임스페이스: System.IO
어셈블리: mscorlib(mscorlib.dll)
구문
‘선언
Public Property LastWriteTime As DateTime
‘사용 방법
Dim instance As FileSystemInfo
Dim value As DateTime
value = instance.LastWriteTime
instance.LastWriteTime = value
public DateTime LastWriteTime { get; set; }
public:
property DateTime LastWriteTime {
DateTime get ();
void set (DateTime value);
}
/** @property */
public DateTime get_LastWriteTime ()
/** @property */
public void set_LastWriteTime (DateTime value)
public function get LastWriteTime () : DateTime
public function set LastWriteTime (value : DateTime)
속성 값
현재 파일에 마지막으로 쓴 시간입니다.
예외
예외 형식 | 조건 |
---|---|
Refresh가 데이터를 초기화할 수 없는 경우 |
|
현재 운영 체제가 Microsoft Windows NT 이상이 아닌 경우 |
설명
처음으로 호출될 때 FileSystemInfo는 Refresh를 호출하고 캐시된 정보를 API에 반환하여 특성 등을 가져옵니다. 다음에 호출할 때 Refresh를 호출하여 정보의 최신 복사본을 얻어야 합니다.
파일을 포함하는 파일 시스템이 이 정보를 지원하지 않으면 이 속성 값은 Null 참조(Visual Basic의 경우 Nothing)입니다.
다음 표에서는 일반적인 예 또는 관련된 I/O 작업의 예를 보여 줍니다.
수행 작업 |
참조 항목 |
---|---|
텍스트 파일에 씁니다. |
|
텍스트 파일에서 읽습니다. |
|
파일에 텍스트를 추가합니다. |
|
파일 이름을 바꾸거나 이동합니다. |
|
파일 특성을 가져옵니다. |
|
파일의 특성을 설정합니다. |
Windows 95, Windows 98, Windows 98 Second Edition 플랫폼 참고: 이 운영 체제에서는 이 속성을 지원하지 않으므로 이 속성의 DirectoryInfo 구현은 지원되지 않습니다.
Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows CE 플랫폼 참고: 이 속성은 읽기 전용입니다.
예제
다음 코드 예제에서는 "터치(touch)" 작업을 통해 LastWriteTime 속성을 업데이트하는 방법을 보여 줍니다. 이 예제에서는 파일이 "터치(touch)"되었으므로 CreationTime, LastAccessTime 및 LastWriteTime 속성을 현재 날짜 및 시간으로 업데이트합니다.
Imports System
Imports System.IO
Public Class Touch
Public Shared Sub Main(ByVal args() As String)
' Make sure an argument (filename) was provided.
If args.Length > 0 Then
' Verify that the provided filename exists.
If File.Exists(args(0)) Then
Dim fi As FileInfo = New FileInfo(args(0))
touchFile(fi)
Else
Console.WriteLine("Could not find the file {0}", args(0))
End If
Else
Console.WriteLine("No file specified.")
End If
End Sub
Public Shared Sub touchFile(ByVal fsi As FileSystemInfo)
Console.WriteLine("Touching: {0}", fsi.FullName)
' Update the CreationTime, LastWriteTime and LastAccessTime.
Try
fsi.CreationTime = DateTime.Now
fsi.LastAccessTime = DateTime.Now
fsi.LastWriteTime = DateTime.Now
Catch e As Exception
Console.WriteLine("Error: {0}", e.Message)
End Try
End Sub
End Class
using System;
using System.IO;
namespace touch
{
class Touch
{
static void Main(string[] args)
{
// Make sure a filename was provided.
if (args.Length > 0)
{
// Verify that the provided filename exists.
if (File.Exists(args[0]))
{
FileInfo fi = new FileInfo(args[0]);
touchFile(fi);
}
else
{
Console.WriteLine(
"Could not find the file: {0}.", args[0]);
}
}
else
{
Console.WriteLine("No file was specified.");
}
}
static void touchFile(FileSystemInfo fsi)
{
Console.WriteLine("Touching: {0}", fsi.FullName);
// Update the CreationTime, LastWriteTime and LastAccessTime.
try
{
fsi.CreationTime = fsi.LastWriteTime = fsi.LastAccessTime =
DateTime.Now;
}
catch (Exception e)
{
Console.WriteLine("Error: {0}", e.Message);
}
}
}
}
.NET Framework 보안
- FileIOPermission 마지막으로 쓴 시간을 설정합니다. 연관된 열거형: FileIOPermissionAccess.Write
플랫폼
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.
버전 정보
.NET Framework
2.0, 1.1, 1.0에서 지원
.NET Compact Framework
2.0, 1.0에서 지원
참고 항목
참조
FileSystemInfo 클래스
FileSystemInfo 멤버
System.IO 네임스페이스