How to get the date and time of the machine to create a folder?

Asked

Viewed 90 times

2

Hello! How best to get the date and time of the machine using C# and create a folder with the format 'DD/MM/YYYY HH:MM:SS' ensuring you never have two folders with the same name?

  • What’s the goal? You want to create a command line tool for you md only with date and time?

1 answer

3


Try using this example below, you should change the path!

DateTime dta = DateTime.Now; 
string dtaStr = dta.ToString("dd" + "-" + "MM" + "-" + "yyyy" + " " + "HH" + "-" + "mm"); //data formatada to string
string subPath ="/path/"+dtaStr; // Seu codigo com a data e hora vai aqui

bool exists = System.IO.Directory.Exists(Server.MapPath(subPath)); // verifica se a pasta ja existe

if(!exists)
    System.IO.Directory.CreateDirectory(Server.MapPath(subPath)); //se não existir ele cria

Browser other questions tagged

You are not signed in. Login or sign up in order to post.