1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366
| using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace ChangEnvXP7
{
public partial class FormMain : Form
{
public FormMain( )
{
InitializeComponent( );
}
int intTotal = 0;
int intCpt = 0;
/// <summary>
/// Récupération du nombre des comptes 'strPath' à transférer.
/// Renommage dossier "d:\utilisat\'strPath'\'aNomSsRep'\environnement" en "d:\utilisat\Modeles\'aNomSsRep'\Windows XP".
/// Création du repertoire "d:\utilisat\'strPath'\'aNomSsRep'\environnement".
/// Création du repertoire "d:\utilisat\'strPath'\'aNomSsRep'\environnement\Windows 7".
/// Déplacement du dossier "d:\utilisat\'strPath'\'aNomSsRep'\Windows XP" dans le dossier"d:\utilisat\Modeles\'aNomSsRep'\environnement".
/// bTraitSRep : raitement des sous dossier (Autres, elv).
/// </summary>
/// <param name="Path"></param>
private void fTransEnv( string strPath, bool bTraitSRep )
{
if ( Directory.Exists( strPath ) )
{
//Récupération nom répertoire.
string [ ] aNomSsRep = fUser( strPath );
string [ ] aNomSsRepSs;
//MessageBox.Show(this, "Nb compte compte administrateurs : " + aNomSsRep.Length, "Aidat Toulouse Sud Muret © Calista", MessageBoxButtons.OK, MessageBoxIcon.Information);
pgbTotal.PerformStep( );
//Initialisation de la barre de progression sous total.
pgbSTotal.Maximum = aNomSsRep.Length;
pgbSTotal.Minimum = 0;
pgbSTotal.Step = 1;
pgbSTotal.PerformStep( );
int i;
int j = 1;
for ( i = 1 ; i <= aNomSsRep.Length ; i++ )
{
if ( bTraitSRep )
{
//traitement des sous répertoires.
aNomSsRepSs = fUser( strPath + aNomSsRep [ i - 1 ] + @"\" );
for ( j = 1 ; j <= aNomSsRepSs.Length ; j++ )
{
intCpt = intCpt + 1;
this.lCompteurTotal.Text = intCpt + "/" + intTotal;
//Modification du label "lCompteurSTotal" qui prend la valeur i (index dossier contenue dans "d:\utilisat\ADMINS")/nb total de dossiers de "d:\utilisat\ADMINS".
this.lCompteurSTotal.Visible = true;
this.lCompteurSTotal.Text = i + "/" + aNomSsRep.Length;
//Les actions décrites sont effectués uniquement si il existe un dossier environnement.
//!Directory.Exists(@"d:\utilisat\&& !Directory.Exists(@"d:\utilisat\Autres\" + aNomSsRep[i - 1] + @"\" + aNomSsRepSs[j - 1] + @"\environnement\windows xp" capitale pour eviter la création d'un nouveau dossier "windows xp" dans le dossier \environnement\windows xp"
//Si le programme est relancé.
if ( Directory.Exists( strPath + aNomSsRep [ i - 1 ] + @"\" + aNomSsRepSs [ j - 1 ] + @"\environnement" ) && !Directory.Exists( strPath + aNomSsRep [ i - 1 ] + @"\" + aNomSsRepSs [ j - 1 ] + @"\environnement\windows xp" ) )
{
//Affichage du label "labelActions"
//Affichage text dans le label "labelActions"
this.labelActions.Visible = true;
this.labelActions.Text = "Le dossier : " + strPath + aNomSsRep [ i - 1 ] + @"\" + aNomSsRepSs [ j - 1 ] + @"\environnement" + "est renommé en : " + "\n" + strPath + aNomSsRep [ i - 1 ] + @"\" + aNomSsRepSs [ j - 1 ] + @"\Windows xp";
//Affichage profil concerné par les opérations dans le label lProfil.
this.labelProfil.Text = strPath + aNomSsRep [ i - 1 ] + @"\" + aNomSsRepSs [ j - 1 ];
//MessageBox.Show(this, @"Compte Autres\" + aNomSsRep[i - 1] +@"\"+ aNomSsRepSs[j - 1], "Aidat Toulouse Sud Muret © Calista", MessageBoxButtons.OK, MessageBoxIcon.Information);
//Le dossier "'strPath'+'aNomSsRep[i - 1]'\'aNomSsRepSs[j - 1]'\environnement" est renommé en "d:\utilisat\Autres\'aNomSsRep[i - 1]'\'aNomSsRepSs[j - 1]\Windows XP".
if ( Directory.Exists( strPath + aNomSsRep [ i - 1 ] + @"\" + aNomSsRepSs [ j - 1 ] + @"\environnement" ) )
{
fMoveDirectory( strPath + aNomSsRep [ i - 1 ] + @"\" + aNomSsRepSs [ j - 1 ] + @"\environnement", strPath + aNomSsRep [ i - 1 ] + @"\" + aNomSsRepSs [ j - 1 ] + @"\Windows xp" );
}
//Création du repertoire "'strPath'\'aNomSsRep[i - 1]'\'aNomSsRepSs[j - 1]'\environnement\windows 7".
if ( !Directory.Exists( strPath + aNomSsRep [ i - 1 ] + @"\" + aNomSsRepSs [ j - 1 ] + @"\environnement\windows 7" ) )
{
//Affichage du label "labelActions"
//Affichage text dans le label "labelActions"
this.labelActions.Visible = true;
this.labelActions.Text = "Le dossier : " + strPath + aNomSsRep [ i - 1 ] + @"\" + aNomSsRepSs [ j - 1 ] + @"\environnement\windows 7 est créé";
fCreateFolder( strPath + aNomSsRep [ i - 1 ] + @"\" + aNomSsRepSs [ j - 1 ] + @"\environnement\windows 7" );
}
//Copie du dossier "'strPath'" + aNomSsRep[i - 1] +@"\"+ aNomSsRepSs[j - 1]+@"\windows xp" dans le dossier "'strPath\"Autres\" + aNomSsRep[i - 1] +@"\"+ aNomSsRepSs[j - 1]+@"\environnement"
if ( Directory.Exists( strPath + aNomSsRep [ i - 1 ] + @"\" + aNomSsRepSs [ j - 1 ] + @"\windows xp" ) )
{
//Affichage du label "labelActions"
//Affichage text dans le label "labelActions"
this.labelActions.Visible = true;
this.labelActions.Text = "Le dossier : " + strPath + aNomSsRep [ i - 1 ] + @"\" + aNomSsRepSs [ j - 1 ] + @"\windows xp est copié dans le dossier " + "\n" + strPath + aNomSsRep [ i - 1 ] + @"\" + aNomSsRepSs [ j - 1 ] + @"\environnement";
fCreateFolder( strPath + aNomSsRep [ i - 1 ] + @"\" + aNomSsRepSs [ j - 1 ] + @"\environnement\windows 7" );
fMoveDirectory( strPath + aNomSsRep [ i - 1 ] + @"\" + aNomSsRepSs [ j - 1 ] + @"\windows xp", strPath + aNomSsRep [ i - 1 ] + @"\" + aNomSsRepSs [ j - 1 ] + @"\environnement\windows xp" );
}
//Incrémentation de la barre de progression.
this.pgbTotal.PerformStep( );
this.pgbSTotal.PerformStep( );
}
}
}
else
{
//Modification du label "lCompteurTotal" qui prend la valeur incpt(index cpt total)/nb total de dossier à traiter.
this.lCompteurTotal.Visible = true;
intCpt = intCpt + 1;
this.lCompteurTotal.Text = intCpt + "/" + intTotal;
//Modification du label "lCompteurSTotal" qui prend la valeur i (index dossier contenue dans "d:\utilisat\ADMINS")/nb total de dossiers de "d:\utilisat\ADMINS".
this.lCompteurSTotal.Visible = true;
this.lCompteurSTotal.Text = i + "/" + aNomSsRep.Length;
//Les actions décrites sont effectués uniquement si il existe un dossier environnement.
//!Directory.Exists(@"d:\utilisat\'strPath'\" + aNomSsRep[i - 1] + @"\environnement\windows xp" capitale pour eviter la création d'un nouveau dossier "windows xp" dans le dossier \environnement\windows xp"
//Si le programme est relancé.
if ( Directory.Exists( strPath + aNomSsRep [ i - 1 ] + @"\environnement" ) && !Directory.Exists( strPath + aNomSsRep [ i - 1 ] + @"\environnement\windows xp" ) )
{
//Affichage du label "labelActions"
//Affichage text dans le label "labelActions"
this.labelActions.Visible = true;
this.labelActions.Text = "Le dossier : " + strPath + aNomSsRep [ i - 1 ] + @"\environnement" + " est renommé en : " + "\n" + strPath + aNomSsRep [ i - 1 ] + @"\Windows xp";
//Affichage profil concerné par les opérations dans le label lProfil.
this.labelProfil.Visible = true;
this.labelProfil.Text = strPath + aNomSsRep [ i - 1 ];
//MessageBox.Show(this, @"Compte Administrateur : " + aNomSsRep[i], "Aidat Toulouse Sud Muret © Calista", MessageBoxButtons.OK, MessageBoxIcon.Information);
//Renommage dossier "d:\utilisat\'strPath'\'aNomSsRep'\environnement" en "'strPath'\'aNomSsRep'\Windows XP".
if ( Directory.Exists( strPath + aNomSsRep [ i - 1 ] + @"\environnement" ) )
{
fMoveDirectory( strPath + aNomSsRep [ i - 1 ] + @"\environnement", strPath + aNomSsRep [ i - 1 ] + @"\Windows xp" );
}
else //compte ne possedant pas de dossier environnemnt (Compte non MAJ avec Magret, compte AD inexisant ???).
{
//Ajout du nom du dossier dan le fichier ErreurChgEnvXP7.txt.
//Ouverture du fichier.
//Ecriture dans le fichier.
//Fermeture du fichier
}
//Création du repertoire "'strPath'\'aNomSsRep'\environnement\windows 7".
if ( !Directory.Exists( strPath + aNomSsRep [ i - 1 ] + @"\environnement\windows 7" ) )
{
//Affichage du label "labelActions"
//Affichage text dans le label "labelActions"
this.labelActions.Visible = true;
this.labelActions.Text = strPath + aNomSsRep [ i - 1 ] + @"\environnement\windows 7 est créé";
fCreateFolder( strPath + aNomSsRep [ i - 1 ] + @"\environnement\windows 7" );
}
//Copie du dossier "d:\utilisat\'strPath'\" + aNomSsRep[i-1] + @"\windows xp" dans le dossier "d:\utilisat\'strPath'\" + aNomSsRep[i-1] + @"\environnement"
if ( Directory.Exists( strPath + aNomSsRep [ i - 1 ] + @"\windows xp" ) )
{
//Affichage du label "labelActions"
//Affichage text dans le label "labelActions"
this.labelActions.Visible = true;
this.labelActions.Text = "Le dossier : " + strPath + aNomSsRep [ i - 1 ] + @"\windows xp est copié dans le dossier" + "\n" + strPath + aNomSsRep [ i - 1 ] + @"\environnement";
fCreateFolder( strPath + aNomSsRep [ i - 1 ] + @"\environnement\windows 7" );
fMoveDirectory( strPath + aNomSsRep [ i - 1 ] + @"\windows xp", strPath + aNomSsRep [ i - 1 ] + @"\environnement\windows xp" );
}
}
//Incrémentation des barres de progression.
this.pgbSTotal.PerformStep( );
this.pgbTotal.PerformStep( );
}
}
//this.EndInvoke(iarSTotal);
}
else
{
MessageBox.Show( this, @"Le repertoire d:\utilisat\" + strPath + " n'existe Pas", "Aidat Toulouse Sud Muret © Calista", MessageBoxButtons.OK, MessageBoxIcon.Information );
}
}
/// <summary>
/// Fonction qui retourne un tableau contenant l'ensembe des dossiers du "ParentFolder"
/// </summary>
/// <param name="Parentfolder"></param>
/// <returns></returns>
private string [ ] fSTDossier( string Parentfolder )
{
string [ ] aNomSsRep = fUser( Parentfolder );
return aNomSsRep;
}
/// <summary>
/// Copie le contenu du répertoire SourceDir dans destDir
/// </summary>
/// <param name="sourceDir"></param>
/// <param name="destDir"></param>
public static void fCopyDir( string sourceDir, string destDir )
{
DirectoryInfo dir = new DirectoryInfo( sourceDir );
if ( dir.Exists )
{
string realDestDir;
if ( dir.Root.Name != dir.Name )
{
realDestDir = Path.Combine( destDir, dir.Name );
if ( !Directory.Exists( realDestDir ) )
Directory.CreateDirectory( realDestDir );
}
else
realDestDir = destDir;
foreach ( string d in Directory.GetDirectories( sourceDir ) )
fCopyDir( d, realDestDir );
foreach ( string file in Directory.GetFiles( sourceDir ) )
{
string fileNameDest = Path.Combine( realDestDir, Path.GetFileName( file ) );
//if (!File.Exists(fileNameDest))
File.Copy( file, fileNameDest, true );
}
}
}
/// <summary>
/// Récupération du nombre de répertoire et des noms se trouvant dans le répertoire strDir.
/// </summary>
/// <param name="strDir"></param>
/// <returns></returns>
public string [ ] fUser( string strDir )
{
int i = 0;
DirectoryInfo diRacine = new DirectoryInfo( strDir );
//MessageBox.Show(this, "DirectoryInfo diRacine = new DirectoryInfo(strDir) ", "Aidat Toulouse Sud Muret © Calista", MessageBoxButtons.OK, MessageBoxIcon.Information);
//Récupération des noms des répertoires contenue dans strDir.
DirectoryInfo [ ] diArr = diRacine.GetDirectories( );
// MessageBox.Show(this, "DirectoryInfo[] diArr = diRacine.GetDirectories(); ", "Aidat Toulouse Sud Muret © Calista", MessageBoxButtons.OK, MessageBoxIcon.Information);
//Rangement des noms des répertoires dans un tableau.
string [ ] aNameDirectory = new string [ diArr.Length ];
//MessageBox.Show(this, "diArr.Length : " + diArr.Length, "Aidat Toulouse Sud Muret © Calista", MessageBoxButtons.OK, MessageBoxIcon.Information);
foreach ( DirectoryInfo dri in diArr )
{
aNameDirectory [ i ] = dri.Name;
//MessageBox.Show(this, "Nom : " + aNameDirectory[i], "Aidat Toulouse Sud Muret © Calista", MessageBoxButtons.OK, MessageBoxIcon.Information);
i++;
}
return aNameDirectory;
}
/// <summary>
/// Fonction qui crée si necessaire le répertoire "strPath".
/// </summary>
/// <param name="strPath"></param>
public void fCreateFolder( string strPath )
{
Directory.CreateDirectory( strPath );
}
/// <summary>
/// Fonction qui renomme un dossier.
/// </summary>
/// <param name="strPath"></param>
public void fMoveDirectory( string strPathInit, string strPathFinal )
{
Directory.Move( strPathInit, strPathFinal );
}
/// <summary>
/// Fonction qui permet de stopper le programme.
/// </summary>
public static void Kill( )
{
System.Diagnostics.Process proc = System.Diagnostics.Process.GetProcessById( System.Diagnostics.Process.GetCurrentProcess( ).Id );
proc.Kill( );
}
/// <summary>
/// Arrêt et sortie du programme.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonQuit_Click( object sender, EventArgs e )
{
Kill( );
}
private void buttonTransfert_Click( object sender, EventArgs e )
{
//Récupération du nombre de dossier contenue dans "d:\utilisat\admins".
intTotal = intTotal + fSTDossier( @"D:\utilisat\admins" ).Length;
//Récupération du nombre de dossier contenue dans "d:\utilisat\Modeles".
intTotal = intTotal + fSTDossier( @"D:\utilisat\Modeles" ).Length;
//Récupération du nombre de dossier contenue dans "d:\utilisat\Profs".
intTotal = intTotal + fSTDossier( @"D:\utilisat\Profs" ).Length;
//Récupération du nombre de dossier contenue dans "d:\utilisat\Autres".
string [ ] strSubFolderAutres = fSTDossier( @"D:\utilisat\Autres" );
int i = 0;
for ( i = 1 ; i <= strSubFolderAutres.Length ; i++ )
{
intTotal = intTotal + fSTDossier( @"d:\utilisat\Autres\" + strSubFolderAutres [ i - 1 ] + @"\" ).Length;
}
//Récupération du nombre de dossier contenue dans "d:\utilisat\Autres".
string [ ] strSubFolderElv = fSTDossier( @"D:\utilisat\Eleves" );
for ( i = 1 ; i <= strSubFolderElv.Length ; i++ )
{
intTotal = intTotal + fSTDossier( @"d:\utilisat\Eleves\" + strSubFolderElv [ i - 1 ] + @"\" ).Length;
}
//Initialisation de la barre de progression Total.
pgbTotal.Maximum = intTotal;
pgbTotal.Minimum = 0;
pgbTotal.Step = 1;
this.lCompteurTotal.Visible = true;
//Transfert Admins.
fTransEnv( @"d:\utilisat\admins\", false );
MessageBox.Show( "Le traitement des environnements des Administrateurs est terminé", "Aidat Toulouse Sud Muret © Calista", MessageBoxButtons.OK, MessageBoxIcon.Information );
//Transfert Modeles.
fTransEnv( @"d:\utilisat\Modeles\", false );
MessageBox.Show( "Le traitement des environnements des Modeles est terminé", "Aidat Toulouse Sud Muret © Calista", MessageBoxButtons.OK, MessageBoxIcon.Information );
//Transfert Profs.
fTransEnv( @"d:\utilisat\Profs\", false );
MessageBox.Show( "Le traitement des environnements des Profs est terminé", "Aidat Toulouse Sud Muret © Calista", MessageBoxButtons.OK, MessageBoxIcon.Information );
//Transfert Autres.
fTransEnv( @"d:\utilisat\Autres\", true );
MessageBox.Show( "Le traitement des environnements des Autres est terminé", "Aidat Toulouse Sud Muret © Calista", MessageBoxButtons.OK, MessageBoxIcon.Information );
//Transfert Eleves.
fTransEnv( @"d:\utilisat\Eleves\", true );
MessageBox.Show( "Le traitement des environnements des Eleves est terminé", "Aidat Toulouse Sud Muret © Calista", MessageBoxButtons.OK, MessageBoxIcon.Information );
}
}
} |
Partager