EDN Admin
Well-known member
I tried to add that check in the catch area but now when the file isnt exist its just stop i want it to do two things:
1. Show a message "Error: Cannot create the filehere will be the file name) when that file already exists in the directory" Or to write some other message that will explain the user that the file is already exist in the directory somehow. Also
i want that it will show this message in every file format if there were 5 *.avi files and one was exist so it will message in the *.avi section that 4 files processed and 1 file already exist. And in the end before the DONE messaqe it will say that in the
Avi format area 4 files processed and 1 files already exists and also it will calculate the countAll so in the end it will say "Overall files processed was 4" and wont count the file wich was already exist.
2. Continue for other files cuz now its stopping when a file is already exist and dosent continue.
This is the code:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; using System;
<span style="color:Blue; using System.Collections.Generic;
<span style="color:Blue; using System.Text;
<span style="color:Blue; using System.IO;
<span style="color:Blue; using DannyGeneral;
<span style="color:Blue; namespace ConsoleApplication1
{
<span style="color:Blue; class Program
{
<span style="color:Blue; static <span style="color:Blue; void Main(<span style="color:Blue; string[] args)
{
<span style="color:Blue; try
{
<span style="color:Blue; int countAll = 0;
<span style="color:Blue; string new_string_format;
<span style="color:Blue; int index = -1 ;
<span style="color:Blue; int y;
FileInfo fi;
<span style="color:Blue; string[] newDest_files;
<span style="color:Blue; string[] lines = global::EachFileDirectory.MyResource.video_formats.Split(<span style="color:Blue; new Char[] { <span style="color:#A31515; r, <span style="color:#A31515; n }, StringSplitOptions.RemoveEmptyEntries);
<span style="color:Blue; foreach (<span style="color:Blue; string line <span style="color:Blue; in lines)
{
newDest_files = Directory.GetFiles(Environment.CurrentDirectory, line); <span style="color:Green; //strFilter );
<span style="color:Blue; for (y = 0; y < newDest_files.Length; y++)
{
fi = <span style="color:Blue; new FileInfo(newDest_files[y]);
<span style="color:Blue; string newFolder = Path.Combine(fi.DirectoryName, fi.Name + <span style="color:#A31515; "_Directory");
<span style="color:Blue; if (!Directory.Exists(newFolder))
Directory.CreateDirectory(newFolder);
File.Move(fi.FullName, Path.Combine(newFolder, fi.Name));
}
<span style="color:Blue; if (newDest_files.Length == 0)
{
Console.WriteLine(line + <span style="color:#A31515; " No files found in the current directory!");
}
<span style="color:Blue; else
{
index = line.IndexOf(<span style="color:#A31515; "*.");
Logger.Write(<span style="color:#A31515; "Index: " + index);
new_string_format = line.Substring(2, line.Length - 2);
Logger.Write(<span style="color:#A31515; "new_string_format: " + new_string_format.ToString());
Console.WriteLine(<span style="color:#A31515; "processed: " + newDest_files.Length + <span style="color:#A31515; " " + new_string_format + <span style="color:#A31515; " files");
Logger.Write(<span style="color:#A31515; "processed: " + newDest_files.Length + <span style="color:#A31515; " " + line + <span style="color:#A31515; " files");
countAll += newDest_files.Length;
}
}
Console.WriteLine(<span style="color:#A31515; "n Overall files processed: " + countAll);
Console.WriteLine(<span style="color:#A31515; "n Process done! Press any key to exit...");
Console.ReadKey();
}
<span style="color:Blue; catch(Exception err)
{
<span style="color:Blue; if (err.Message.Contains(<span style="color:#A31515; "file already exists"))
{
Console.WriteLine(<span style="color:#A31515; "n Error: Cannot create a file when that file already exists in the directory");
Logger.Write(<span style="color:#A31515; "Error: Cannot create a file when that file already exists in the directory");
Console.ReadKey();
}
<span style="color:Blue; else
{
Logger.Write(<span style="color:#A31515; "Error: " + err);
Console.ReadKey();
}
}
}
}
}
[/code]
Thanks. <hr class="sig danieli
View the full article
1. Show a message "Error: Cannot create the filehere will be the file name) when that file already exists in the directory" Or to write some other message that will explain the user that the file is already exist in the directory somehow. Also
i want that it will show this message in every file format if there were 5 *.avi files and one was exist so it will message in the *.avi section that 4 files processed and 1 file already exist. And in the end before the DONE messaqe it will say that in the
Avi format area 4 files processed and 1 files already exists and also it will calculate the countAll so in the end it will say "Overall files processed was 4" and wont count the file wich was already exist.
2. Continue for other files cuz now its stopping when a file is already exist and dosent continue.
This is the code:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; using System;
<span style="color:Blue; using System.Collections.Generic;
<span style="color:Blue; using System.Text;
<span style="color:Blue; using System.IO;
<span style="color:Blue; using DannyGeneral;
<span style="color:Blue; namespace ConsoleApplication1
{
<span style="color:Blue; class Program
{
<span style="color:Blue; static <span style="color:Blue; void Main(<span style="color:Blue; string[] args)
{
<span style="color:Blue; try
{
<span style="color:Blue; int countAll = 0;
<span style="color:Blue; string new_string_format;
<span style="color:Blue; int index = -1 ;
<span style="color:Blue; int y;
FileInfo fi;
<span style="color:Blue; string[] newDest_files;
<span style="color:Blue; string[] lines = global::EachFileDirectory.MyResource.video_formats.Split(<span style="color:Blue; new Char[] { <span style="color:#A31515; r, <span style="color:#A31515; n }, StringSplitOptions.RemoveEmptyEntries);
<span style="color:Blue; foreach (<span style="color:Blue; string line <span style="color:Blue; in lines)
{
newDest_files = Directory.GetFiles(Environment.CurrentDirectory, line); <span style="color:Green; //strFilter );
<span style="color:Blue; for (y = 0; y < newDest_files.Length; y++)
{
fi = <span style="color:Blue; new FileInfo(newDest_files[y]);
<span style="color:Blue; string newFolder = Path.Combine(fi.DirectoryName, fi.Name + <span style="color:#A31515; "_Directory");
<span style="color:Blue; if (!Directory.Exists(newFolder))
Directory.CreateDirectory(newFolder);
File.Move(fi.FullName, Path.Combine(newFolder, fi.Name));
}
<span style="color:Blue; if (newDest_files.Length == 0)
{
Console.WriteLine(line + <span style="color:#A31515; " No files found in the current directory!");
}
<span style="color:Blue; else
{
index = line.IndexOf(<span style="color:#A31515; "*.");
Logger.Write(<span style="color:#A31515; "Index: " + index);
new_string_format = line.Substring(2, line.Length - 2);
Logger.Write(<span style="color:#A31515; "new_string_format: " + new_string_format.ToString());
Console.WriteLine(<span style="color:#A31515; "processed: " + newDest_files.Length + <span style="color:#A31515; " " + new_string_format + <span style="color:#A31515; " files");
Logger.Write(<span style="color:#A31515; "processed: " + newDest_files.Length + <span style="color:#A31515; " " + line + <span style="color:#A31515; " files");
countAll += newDest_files.Length;
}
}
Console.WriteLine(<span style="color:#A31515; "n Overall files processed: " + countAll);
Console.WriteLine(<span style="color:#A31515; "n Process done! Press any key to exit...");
Console.ReadKey();
}
<span style="color:Blue; catch(Exception err)
{
<span style="color:Blue; if (err.Message.Contains(<span style="color:#A31515; "file already exists"))
{
Console.WriteLine(<span style="color:#A31515; "n Error: Cannot create a file when that file already exists in the directory");
Logger.Write(<span style="color:#A31515; "Error: Cannot create a file when that file already exists in the directory");
Console.ReadKey();
}
<span style="color:Blue; else
{
Logger.Write(<span style="color:#A31515; "Error: " + err);
Console.ReadKey();
}
}
}
}
}
[/code]
Thanks. <hr class="sig danieli
View the full article