Output file does not display extension even after using GetFiles method.

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

SlenderMan564

Guest
Hi a problem,

Output file does not display extension. Have to find correct program to reveal file extension. That is the problem. The problem I’m trying to solve is to write all renamed files with time and date to target folder with extensions.

I can’t figure out for the life of me how to output a file by its extension. I know I can use the GetFiles() method but I’m not too sure as how to output it. The problem I've got lies in the RenameFile method... I think?

public partial class Form1 : Form
{
static string[] _dropppedFiles;
string _strSourcePath;
string _strTargetPath;
string _strfileName = string.Empty;
string _strDestFile = string.Empty;

public Form1()
{
InitializeComponent();
readLabelMsg();
}

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

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

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;
RenameFile(_strTargetPath);
}

public void RenameFile(string targetDirectory)
{
//Get file regardless of specific extension.
_dropppedFiles = Directory.GetFiles(targetDirectory);
foreach(string file in _dropppedFiles)
{
if (!lstDragDrop.Items.Contains(_dropppedFiles.Length))
{
_strSourcePath = getDirectoryName(file);
_strfileName = getFileName(file);

//GET Creation Date and time from file.
_strfileName = File.GetCreationTime(file).ToString("yyyy'-'MM'-'dd hh'\u0589'mm'\u0589'ss tt", CultureInfo.InvariantCulture);
_strDestFile = Path.Combine(targetDirectory, _strfileName);
//Copy file with extension to output directory.
File.Copy(file, _strDestFile, true);
}
else
{
Debug.WriteLine("Source path does not exist!");
}
}
}
}

Continue reading...
 
Back
Top