Renaming a file name with creation time results in only the seconds getting written to file

  • Thread starter Thread starter SlenderMan564
  • Start date Start date
S

SlenderMan564

Guest
I have finally being able to write the creation time and date to a file name I am trying to move. The problem I am having though is it only outputs the seconds including AM or PM to the file. I want it to output the creation time and date in long format. E.g “yyyy,mm,dd hh,mm,ss.”

I also just wanted to make a copy of a file with a new filename but can’t find the right method on MSDN. I also don’t want to have to explicitly state the file extension and for it to just make a copy of the file in the same format.

The problem lies on this line in btnConvert_click. That's where it's only returning the sconds.

_strfileName = Path.GetFileName(_strNewName);
Here is the rest including snapshot of Auto's Window that displays an error.
public partial class Form1 : Form
{
string[] _dropppedFiles;
string _strTargetPath;
string _strfileName = string.Empty;
string _strDestFile = string.Empty;
string _strNewName;

public Form1()
{
InitializeComponent();
}

private string getFileName(string _strSourcePath)
{
return Path.GetFileName(_strSourcePath);
}

private string getDirectoryName(string _strSourcePath)
{
return Path.GetDirectoryName(_strSourcePath);
}

private void Form1_DragDrop(object sender, DragEventArgs e)
{
//TAKE dropped items and store in array.
_dropppedFiles = (string[])e.Data.GetData(DataFormats.FileDrop);

//LOOP through all droppped items and display them
foreach (string file in _dropppedFiles)
{
lstDragDrop.Items.Add(file);
}
}

private void Form1_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop, false) == true)
{
e.Effect = DragDropEffects.All;
}
}

private void btnConvert_Click(object sender, EventArgs e)
{

_strTargetPath = txtFolderPath.Text;
foreach (string file in _dropppedFiles)
{
//IF filename doesn't exist in drag drop box.
if (!lstDragDrop.Items.Contains(_dropppedFiles.Length))
{
//GET Creation Date and time from file.
_strNewName = Convert.ToString(File.GetCreationTime(file));
//Get file path.
_strfileName = Path.GetFileName(_strNewName);
_strDestFile = Path.Combine(_strTargetPath, _strfileName);
File.Move(file, _strDestFile);
}

else
{
Console.WriteLine("Source path does not exist!");
}
}
}
}
1359488.png

Continue reading...
 
Back
Top