I have two separate programs from each other here, one of them creates folders named with the current date whenever I run it, so I made a schedule for it and daily it runs alone, and the other is to capture images from webCam, the of webCam is to open the directory where the one that creates folders is configured, however the user must select the most recent folder to save the necessary photos of that day, what I wanted to do was to unify both, taking the operator's hand the need to select the folder.
Example: The webCam Program creates whenever you press save as a latest folder according to the day and if the folder already exists apples opens it to enter the name and save.
I have already looked in several places, some say it is not possible and others claim that it is possible to do it, I would like to know if someone has already done something like this or knows at least one way for me to start, I will leave the current webCam program to save the images and the code that creates folders.
private void btnSalvar_Click(object sender, System.EventArgs e)
{
try
{
//abre a opção de salvar como, para selecionar a pasta
SaveFileDialog saveFileDialog1 = new SaveFileDialog
{
Filter = "JPeg Image|*.jpg|Bitmap Image|*.bmp|Gif Image|*.gif",
Title = "Salvar o arquivo de imagem",
InitialDirectory = @"\MI7627\Imagens"
};
saveFileDialog1.ShowDialog();
// se o nome do arquivo não for vazio, abre para salvar
if (saveFileDialog1.FileName != "")
{
// salva a imagem por fileStream
System.IO.FileStream fs =
(System.IO.FileStream)saveFileDialog1.OpenFile();
// Salva a imagem no formato certo
switch (saveFileDialog1.FilterIndex)
{
case 1:
this.picImagem.Image.Save(fs,
System.Drawing.Imaging.ImageFormat.Jpeg);
break;
case 2:
this.picImagem.Image.Save(fs,
System.Drawing.Imaging.ImageFormat.Bmp);
break;
case 3:
this.picImagem.Image.Save(fs,
System.Drawing.Imaging.ImageFormat.Gif);
break;
}
fs.Close();
}
}
Folder Creator:
using System;
using static System.Console;
using System.IO;
public class CreateFileOrFolder
{
public static void Main()
{
Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData); // C:\ProgramData no Win7
var activeDir = (@"\MI7627\Imagens"); //caminho onde salva as fotos
string newPath = Path.Combine(activeDir, DateTime.Now.ToString("yyyy-MM-dd")); //subpasta onde cria de acordo com a data
Directory.CreateDirectory(newPath); // cria o diretório
newPath = Path.Combine(newPath, Path.GetRandomFileName());
if (!File.Exists(newPath));
}
void CriarPasta(string Path)//Cria a função/void
{
if (Directory.Exists(Path))//Verifica se já existe uma pasta com o mesmo *path*
{
for (int i = 0; !Directory.Exists((Path + "(" + i + ")")); i++)//Verifica se exste uma pasta com o nome + (i)
{
Directory.CreateDirectory(Path + "(" + i + ")");//Cria a pasta
}
}
else// se não
Directory.CreateDirectory(Path);//Cria a pasta
}
}