F-name = filename
Hello guys,
I know that most of you are familiar with Java, however C# look like it.
I've stored in a "String []", the ID of the files that I need to move to another folder. All Files has different Prefix, and there are hundreds of files.
For exemple :
What I want to do is get the Full Path of the files containing the "ID" in order to be able to move it in another folder.
What's the problem ?
I'm not able to get the Full Path of the file with only a piece of the name files. Any kind of help, would be much appreciated.
Code :
Code:
string ID = File.ReadAllText(@"C:\Users\Desktop\Script\zig.txt");
Console.WriteLine(ID);
Console.ReadLine();
String root = @"C:\Users\Desktop\Script\tiptop\";
String[] lines = System.IO.File.ReadAllLines(@"C:\Users\Desktop\Script\zig.txt");
for (int i = 0; i <= lines.Length; i++)
{
string fullPath = System.IO.Path.Combine(root,(lines[i-1]));
if (System.IO.File.Exists(fullPath))
{
Console.WriteLine("" + fullPath);
}
}
for (int i = 0; i <= lines.Length;i++)
{
//Console.WriteLine("" + lines[i]);
string fullPath = Path.GetFullPath(@"C:\Users\Desktop\Script\tiptop\");
Console.WriteLine(System.IO.Directory.EnumerateFiles(@"C:\Users\Desktop\Script\tiptop\", lines[i]));
Finally, I was able to fix it.
The code isn't clear at all, but it works.
That's how I've done :
Code:
/**
* @author Naïm Gallouj
* 2/04/2019
* */
using System;
using System.IO;
using System.Text;
using System.Resources;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
namespace Netty
{
class Program
{
static void Main(string[] args)
{
//Utilisation d'un autre programme pour savoir si l'ID apparait 4 fois
// Stockage des ID qui aparaissent 4 fois dans un Tableau de chaîne de caractère.
string ID = File.ReadAllText(@"C:\Users\ngallouj\Desktop\Script\zig.txt");
//Console.WriteLine(ID);
//Console.ReadLine();
//Declaration de toutes les Préfixes de BEXT
string prefix1 = "exp_vente_ent_";
string prefix2 = "ctl_";
string prefix3 = "exp_vente_lig_";
string prefix4 = "mvt_";
string prefix5 = "rcp_achat_ent_";
string prefix6 = "rcp_achat_lig_";
string prefix7 = "rec_vente_lig_";
string prefix8 = "rec_vente_ent_";
//Declaration extenstion fichiers possible
string a = ".txt";
string b = ".top";
String root = @"C:\Users\ngallouj\Desktop\Script\tiptop\";
String[] lines = System.IO.File.ReadAllLines(@"C:\Users\ngallouj\Desktop\Script\zig.txt");
for (int i = 0; i <= lines.Length; i++)
{
//string fullPath = System.IO.Path.Combine(root,prefix1,lines[i-1]);
//=========================================
//DECLARATION DES CHEMINS D'ACCEES PÖSSIBLE
//=========================================
//concaténation et lecture dans le tableau des ID pour obtenir des chemins d'accées Plausible.
string fullPath0 = System.IO.Path.Combine(root, prefix1 + lines[i] + a);
string fullPath0a = System.IO.Path.Combine(root, prefix1 + lines[i] + b);
string fullPath1 = System.IO.Path.Combine(root, prefix2 + lines[i]) + a;
string fullPath1a = System.IO.Path.Combine(root, prefix2 + lines[i] + b);
string fullPath2 = System.IO.Path.Combine(root, prefix3 + lines[i] + a);
string fullPath2a = System.IO.Path.Combine(root, prefix3 + lines[i] + b);
string fullPath3 = System.IO.Path.Combine(root, prefix4 + lines[i] + a);
string fullPath3a = System.IO.Path.Combine(root, prefix4 + lines[i] + b);
string fullPath4 = System.IO.Path.Combine(root, prefix5 + lines[i] + a);
string fullPath4a = System.IO.Path.Combine(root, prefix5 + lines[i] + b);
string fullPath5 = System.IO.Path.Combine(root, prefix6 + lines[i] + a);
string fullPath5a = System.IO.Path.Combine(root, prefix6 + lines[i] + b);
string fullPath6 = System.IO.Path.Combine(root, prefix7 + lines[i] + a);
string fullPath6a = System.IO.Path.Combine(root, prefix7 + lines[i] + b);
string fullPath7 = System.IO.Path.Combine(root, prefix8 + lines[i] + a);
string fullPath7a = System.IO.Path.Combine(root, prefix8 + lines[i] + b);
string name0 = System.IO.Path.Combine(root, prefix1 + lines[i] + a);
string name0a = System.IO.Path.Combine(root, prefix1 + lines[i] + b);
string name1 = System.IO.Path.Combine(root, prefix2 + lines[i]) + a;
string name1a = System.IO.Path.Combine(root, prefix2 + lines[i] + b);
string name2 = System.IO.Path.Combine(root, prefix3 + lines[i] + a);
string name2a = System.IO.Path.Combine(root, prefix3 + lines[i] + b);
string name3 = System.IO.Path.Combine(root, prefix4 + lines[i] + a);
string name3a = System.IO.Path.Combine(root, prefix4 + lines[i] + b);
string name4 = System.IO.Path.Combine(root, prefix5 + lines[i] + a);
string name4a = System.IO.Path.Combine(prefix5 + lines[i] + b);
string name5 = System.IO.Path.Combine(prefix6 + lines[i] + a);
string name5a = System.IO.Path.Combine(prefix6 + lines[i] + b);
string name6 = System.IO.Path.Combine(prefix7 + lines[i] + a);
string name6a = System.IO.Path.Combine(prefix7 + lines[i] + b);
string name7 = System.IO.Path.Combine(prefix8 + lines[i] + a);
string name7a = System.IO.Path.Combine(prefix8 + lines[i] + b);
//Cette partie sert à vérifier si le chemin d'accées existe pour ensuite bouger tout les fichiers sur un serveur tierce.
//Console.WriteLine(fullPath1);
//Console.WriteLine(fullPath1a);
//Console.WriteLine(fullPath2);
//Console.WriteLine(fullPath2);
//File.Move(fullPath2, @"C:\Users\ngallouj\Desktop\Script\ark");
//File.Move(fullPath1, @"C:\Users\ngallouj\Desktop\Script\ark\");
//File.Move(fullPath1a, @"C:\Users\ngallouj\Desktop\Script\ark\");
if (File.Exists(fullPath0)) {
File.Copy(fullPath0, @"C:\Users\ngallouj\Desktop\Script\ark\"+ prefix1 + lines[i] + a);
}
if (File.Exists(fullPath0a))
{
File.Copy(fullPath0a, @"C:\Users\ngallouj\Desktop\Script\ark\"+ prefix2 + lines[i] + a);
}
if (File.Exists(fullPath1))
{
File.Copy(fullPath1, @"C:\Users\ngallouj\Desktop\Script\ark\"+ prefix3 + lines[i] + a);
}
if (File.Exists(fullPath1a))
{
File.Copy(fullPath1a, @"C:\Users\ngallouj\Desktop\Script\ark\" + prefix4 + lines[i] + a);
}
if (File.Exists(fullPath2))
{
File.Copy(fullPath2, @"C:\Users\ngallouj\Desktop\Script\ark\" + prefix5 + lines[i] + a);
}
if (File.Exists(fullPath2a))
{
File.Copy(fullPath2a, @"C:\Users\ngallouj\Desktop\Script\ark\" + prefix6 + lines[i] + a);
}
if (File.Exists(fullPath3))
{
File.Copy(fullPath3, @"C:\Users\ngallouj\Desktop\Script\ark\" + prefix7 + lines[i] + a);
}
if (File.Exists(fullPath3a))
{
File.Copy(fullPath3a, @"C:\Users\ngallouj\Desktop\Script\ark\" + prefix8 + lines[i] + a);
}
if (File.Exists(fullPath4))
{
File.Copy(fullPath4a, @"C:\Users\ngallouj\Desktop\Script\ark\" + prefix1 + lines[i] + a);
}
if (File.Exists(fullPath4a))
{
File.Copy(fullPath4a, @"C:\Users\ngallouj\Desktop\Script\ark\" + prefix2 + lines[i] + a);
}
if (File.Exists(fullPath5))
{
File.Copy(fullPath5, @"C:\Users\ngallouj\Desktop\Script\ark\" + prefix3 + lines[i] + a);
}
if (File.Exists(fullPath5a))
{
File.Copy(fullPath5a, @"C:\Users\ngallouj\Desktop\Script\ark\" + prefix4 + lines[i] + a);
}
if (File.Exists(fullPath6))
{
File.Copy(fullPath6, @"C:\Users\ngallouj\Desktop\Script\ark\" + prefix5 + lines[i] + a);
}
if (File.Exists(fullPath6a))
{
File.Copy(fullPath6a, @"C:\Users\ngallouj\Desktop\Script\ark\" + prefix6 + lines[i] + a);
}
if (File.Exists(fullPath7))
{
File.Copy(fullPath7, @"C:\Users\ngallouj\Desktop\Script\ark\" + prefix7 + lines[i] + a);
}
if (File.Exists(fullPath7a))
{
File.Copy(fullPath7a, @"C:\Users\ngallouj\Desktop\Script\ark\" + prefix8 + lines[i] + a);
}
}
//File.Move(fullPath2, @"C:\Users\ngallouj\Desktop\Script\ark");
}
//for (int i = 0; i <= lines.Length;i++)
//{
//Console.WriteLine("" + lines[i]);
// string fullPath = Path.GetFullPath(@"C:\Users\Desktop\Script\tiptop\");
//Console.WriteLine(System.IO.Directory.EnumerateFiles(@"C:\Users\Desktop\Script\tiptop\", lines[i]));
//}
}
}