다음을 통해 공유


Directory.SetCreationTime 메서드

지정된 파일 또는 디렉터리에 대한 만든 날짜와 시간을 설정합니다.

네임스페이스: System.IO
어셈블리: mscorlib(mscorlib.dll)

구문

‘선언
Public Shared Sub SetCreationTime ( _
    path As String, _
    creationTime As DateTime _
)
‘사용 방법
Dim path As String
Dim creationTime As DateTime

Directory.SetCreationTime(path, creationTime)
public static void SetCreationTime (
    string path,
    DateTime creationTime
)
public:
static void SetCreationTime (
    String^ path, 
    DateTime creationTime
)
public static void SetCreationTime (
    String path, 
    DateTime creationTime
)
public static function SetCreationTime (
    path : String, 
    creationTime : DateTime
)

매개 변수

  • path
    만든 날짜와 시간 정보를 설정할 파일 또는 디렉터리입니다.
  • creationTime
    path의 만든 날짜와 시간을 설정할 값을 포함하는 DateTime입니다. 이 값은 현지 시간으로 표현됩니다.

예외

예외 형식 조건

FileNotFoundException

지정된 경로를 찾을 수 없는 경우

ArgumentException

path가 길이가 0인 문자열이거나, 공백만 포함하거나 또는 InvalidPathChars로 정의된 하나 이상의 잘못된 문자를 포함하는 경우

ArgumentNullException

path가 Null 참조(Visual Basic의 경우 Nothing)인 경우

PathTooLongException

지정된 경로 또는 파일 이름이 시스템에 정의된 최대 길이를 초과하는 경우 예를 들어, Windows 기반 플랫폼에서는 경로에 248자 미만의 문자를 사용해야 하며 파일 이름에는 260자 미만의 문자를 사용해야 합니다.

UnauthorizedAccessException

호출자에게 필요한 권한이 없는 경우

ArgumentOutOfRangeException

creationTime에서 해당 작업에 허용된 날짜나 시간 범위를 벋어나는 값을 지정한 경우

PlatformNotSupportedException

현재 운영 체제가 Microsoft Windows NT 이상이 아닌 경우

설명

path 매개 변수에는 상대 경로나 절대 경로 정보를 지정할 수 있습니다. 상대 경로 정보는 현재 작업 디렉터리에 상대적으로 해석됩니다. 현재 작업 디렉터리를 얻는 방법에 대해서는 GetCurrentDirectory를 참조하십시오.

path 매개 변수는 대/소문자를 구분하지 않습니다.

Windows 95, Windows 98, Windows 98 Second Edition 플랫폼 참고: 이 운영 체제에서는 이 메서드를 지원하지 않습니다.

예제

다음 코드 예제에서는 UTC(Coordinated Universal Time) 출력을 사용할 경우 출력의 차이점을 보여 줍니다.

' This sample shows the differences between dates from methods that use
'coordinated universal time (UTC) format and those that do not.
Imports System
Imports System.IO



Public Class DirectoryUTCTime
   
   Public Shared Sub Main()
      ' Set the directory.
      Dim n As String = "C:\test\newdir"
      'Create two variables to use to set the time.
      Dim dtime1 As New DateTime(2002, 1, 3)
      Dim dtime2 As New DateTime(1999, 1, 1)
      
      'Create the directory.
      Try
         Directory.CreateDirectory(n)
      Catch e As IOException
         Console.WriteLine(e)
      End Try
      
      'Set the creation and last access times to a variable DateTime value.
      Directory.SetCreationTime(n, dtime1)
      Directory.SetLastAccessTimeUtc(n, dtime1)
      
      ' Print to console the results.
      Console.WriteLine("Creation Date: {0}", Directory.GetCreationTime(n))
      Console.WriteLine("UTC creation Date: {0}", Directory.GetCreationTimeUtc(n))
      Console.WriteLine("Last write time: {0}", Directory.GetLastWriteTime(n))
      Console.WriteLine("UTC last write time: {0}", Directory.GetLastWriteTimeUtc(n))
      Console.WriteLine("Last access time: {0}", Directory.GetLastAccessTime(n))
      Console.WriteLine("UTC last access time: {0}", Directory.GetLastAccessTimeUtc(n))
      
      'Set the last write time to a different value.
      Directory.SetLastWriteTimeUtc(n, dtime2)
      Console.WriteLine("Changed last write time: {0}", Directory.GetLastWriteTimeUtc(n))
   End Sub 'Main
End Class 'DirectoryUTCTime

' Since this sample deals with dates and times, the output will vary
' depending on when you run the executable. Here is one example of the output:

' Creation Date: 1/3/2002 12:00:00 AM
' UTC creation Date: 1/3/2002 8:00:00 AM
' Last write time: 12/31/1998 4:00:00 PM
' UTC last write time: 1/1/1999 12:00:00 AM
' Last access time: 1/2/2002 4:00:00 PM
' UTC last access time: 1/3/2002 12:00:00 AM
' Changed last write time: 1/1/1999 12:00:00 AM
// This sample shows the differences between dates from methods that use
//coordinated universal time (UTC) format and those that do not.
using System;
using System.IO;

namespace IOSamples
{
  public class DirectoryUTCTime
  {
    public static void Main()
    {
    // Set the directory.
      string n = @"C:\test\newdir";
        //Create two variables to use to set the time.
      DateTime dtime1 = new DateTime(2002, 1, 3);
      DateTime dtime2 = new DateTime(1999, 1, 1);

    //Create the directory.
      try
      {
          Directory.CreateDirectory(n);
      }
      catch (IOException e)
      {
          Console.WriteLine(e);
      }

    //Set the creation and last access times to a variable DateTime value.
      Directory.SetCreationTime(n, dtime1);
      Directory.SetLastAccessTimeUtc(n, dtime1);

        // Print to console the results.
      Console.WriteLine("Creation Date: {0}", Directory.GetCreationTime(n));
      Console.WriteLine("UTC creation Date: {0}", Directory.GetCreationTimeUtc(n));
      Console.WriteLine("Last write time: {0}", Directory.GetLastWriteTime(n));
      Console.WriteLine("UTC last write time: {0}", Directory.GetLastWriteTimeUtc(n));
      Console.WriteLine("Last access time: {0}", Directory.GetLastAccessTime(n));
      Console.WriteLine("UTC last access time: {0}", Directory.GetLastAccessTimeUtc(n));

        //Set the last write time to a different value.
      Directory.SetLastWriteTimeUtc(n, dtime2);
      Console.WriteLine("Changed last write time: {0}", Directory.GetLastWriteTimeUtc(n));
    }
  }
}
// Obviously, since this sample deals with dates and times, the output will vary
// depending on when you run the executable. Here is one example of the output:
//Creation Date: 1/3/2002 12:00:00 AM
//UTC creation Date: 1/3/2002 8:00:00 AM
//Last write time: 12/31/1998 4:00:00 PM
//UTC last write time: 1/1/1999 12:00:00 AM
//Last access time: 1/2/2002 4:00:00 PM
//UTC last access time: 1/3/2002 12:00:00 AM
//Changed last write time: 1/1/1999 12:00:00 AM
// This sample shows the differences between dates from methods that use
//coordinated universal time (UTC) format and those that do not.
using namespace System;
using namespace System::IO;
int main()
{
   
   // Set the directory.
   String^ n = "C:\\test\\newdir";
   
   //Create two variables to use to set the time.
   DateTime dtime1 = DateTime(2002,1,3);
   DateTime dtime2 = DateTime(1999,1,1);
   
   //Create the directory.
   try
   {
      Directory::CreateDirectory( n );
   }
   catch ( IOException^ e ) 
   {
      Console::WriteLine( e );
   }

   
   //Set the creation and last access times to a variable DateTime value.
   Directory::SetCreationTime( n, dtime1 );
   Directory::SetLastAccessTimeUtc( n, dtime1 );
   
   // Print to console the results.
   Console::WriteLine( "Creation Date: {0}", Directory::GetCreationTime( n ) );
   Console::WriteLine( "UTC creation Date: {0}", Directory::GetCreationTimeUtc( n ) );
   Console::WriteLine( "Last write time: {0}", Directory::GetLastWriteTime( n ) );
   Console::WriteLine( "UTC last write time: {0}", Directory::GetLastWriteTimeUtc( n ) );
   Console::WriteLine( "Last access time: {0}", Directory::GetLastAccessTime( n ) );
   Console::WriteLine( "UTC last access time: {0}", Directory::GetLastAccessTimeUtc( n ) );
   
   //Set the last write time to a different value.
   Directory::SetLastWriteTimeUtc( n, dtime2 );
   Console::WriteLine( "Changed last write time: {0}", Directory::GetLastWriteTimeUtc( n ) );
}

// Obviously, since this sample deals with dates and times, the output will vary
// depending on when you run the executable. Here is one example of the output:
//Creation Date: 1/3/2002 12:00:00 AM
//UTC creation Date: 1/3/2002 8:00:00 AM
//Last write time: 12/31/1998 4:00:00 PM
//UTC last write time: 1/1/1999 12:00:00 AM
//Last access time: 1/2/2002 4:00:00 PM
//UTC last access time: 1/3/2002 12:00:00 AM
//Changed last write time: 1/1/1999 12:00:00 AM
// This sample shows the differences between dates from methods that use
// coordinated universal time (UTC) format and those that do not.
import System.*;
import System.IO.*;

public class DirectoryUTCTime
{
    public static void main(String[] args)
    {
        // Set the directory.
        String n = "C:\\test\\newdir";
        //Create two variables to use to set the time.
        DateTime dTime1 = new DateTime(2002, 1, 3);
        DateTime dTime2 = new DateTime(1999, 1, 1);
        //Create the directory.
        try {
            Directory.CreateDirectory(n);
        }
        catch (IOException e) {
            Console.WriteLine(e);
        }
        //Set the creation and last access times to a variable DateTime value.
        Directory.SetCreationTime(n, dTime1);
        Directory.SetLastAccessTimeUtc(n, dTime1);
        // Print to console the results.
        Console.WriteLine("Creation Date: {0}", Directory.GetCreationTime(n));
        Console.WriteLine("UTC creation Date: {0}",
            Directory.GetCreationTimeUtc(n));
        Console.WriteLine("Last write time: {0}",
            Directory.GetLastWriteTime(n));
        Console.WriteLine("UTC last write time: {0}",
            Directory.GetLastWriteTimeUtc(n));
        Console.WriteLine("Last access time: {0}", 
            Directory.GetLastAccessTime(n));
        Console.WriteLine("UTC last access time: {0}", 
            Directory.GetLastAccessTimeUtc(n));
        //Set the last write time to a different value.
        Directory.SetLastWriteTimeUtc(n, dTime2);
        Console.WriteLine("Changed last write time: {0}", 
            Directory.GetLastWriteTimeUtc(n));
    } //main
} //DirectoryUTCTime
// Obviously, since this sample deals with dates and times, the output
// will vary depending on when you run the executable. Here is one example
// of the output:
// Creation Date: 1/3/2002 12:00:00 AM
// UTC creation Date: 1/3/2002 8:00:00 AM
// Last write time: 12/31/1998 4:00:00 PM
// UTC last write time: 1/1/1999 12:00:00 AM
// Last access time: 1/2/2002 4:00:00 PM
// UTC last access time: 1/3/2002 12:00:00 AM
// Changed last write time: 1/1/1999 12:00:00 AM

.NET Framework 보안

플랫폼

Windows 98, Windows 2000 SP4, Windows Millennium Edition, 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에서 지원

참고 항목

참조

Directory 클래스
Directory 멤버
System.IO 네임스페이스

기타 리소스

파일 및 스트림 I/O
방법: 파일의 텍스트 읽기
방법: 파일에 텍스트 쓰기