Accueil > > > APPLICATION SIMPLE POUR MODIFIER LES ATTRIBUTS D'UN FICHIER (DATE DE CRÉATION, DE MODIFICATION, D'ACCÈS)
APPLICATION SIMPLE POUR MODIFIER LES ATTRIBUTS D'UN FICHIER (DATE DE CRÉATION, DE MODIFICATION, D'ACCÈS)
Information sur la source
Description
Tout est dit dans le titre, c'est une première version donc surement incomplète et à améliorer.
Source
- using System;
- using System.Drawing;
- using System.Collections;
- using System.ComponentModel;
- using System.Windows.Forms;
- using System.Data;
-
- namespace FilesManager
- {
- /* Available actions : modify created, last modified and last accessed dates */
- public enum ACTION : int
- {
- CREATED = 1,
- MODIFIED = 2,
- ACCESSED = 3
- }
- /// <summary>
- /// A simple windows form application to update file attributes
- /// </summary>
- public class FilesManagerUI : System.Windows.Forms.Form
- {
- /* date format used */
- private const string FORMATDATE = "dddd dd MMMM yyyy, hh:mm:ss";
-
- /* all dates used */
- private DateTime dCreated = DateTime.Now;
- private DateTime dAccessed = DateTime.Now;
- private DateTime dModified = DateTime.Now;
-
- /* file path */
- private string sPath;
-
- /* action selected by the user */
- private ACTION action;
-
- private System.Windows.Forms.Label lblAccessed;
- private System.Windows.Forms.Label lblModified;
- private System.Windows.Forms.Label lblCreated;
- private System.Windows.Forms.GroupBox groupBox1;
- private System.Windows.Forms.Label lblModifiedDate;
- private System.Windows.Forms.Label lblAccessedDate;
- private System.Windows.Forms.Label lblCreatedDate;
- private System.Windows.Forms.NumericUpDown Date;
- private System.Windows.Forms.NumericUpDown Month;
- private System.Windows.Forms.NumericUpDown Year;
- private System.Windows.Forms.RadioButton Modified;
- private System.Windows.Forms.RadioButton Accessed;
- private System.Windows.Forms.RadioButton FCreated;
- private System.Windows.Forms.Button bModify;
- private System.Windows.Forms.Button bQuit;
- private System.Windows.Forms.Button bBrowse;
- private System.Windows.Forms.StatusBar statusBar;
-
- /// <summary>
- /// Required designer variable.
- /// </summary>
- private System.ComponentModel.Container components = null;
-
- public FilesManagerUI()
- {
- //
- // Required for Windows Form Designer support
- //
- InitializeComponent();
-
- //
- // TODO: Add any constructor code after InitializeComponent call
- //
- }
-
- /// <summary>
- /// Clean up any resources being used.
- /// </summary>
- protected override void Dispose( bool disposing )
- {
- if( disposing )
- {
- if (components != null)
- {
- components.Dispose();
- }
- }
- base.Dispose( disposing );
- }
-
- #region Windows Form Designer generated code
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- private void InitializeComponent()
- {
- this.bBrowse = new System.Windows.Forms.Button();
- this.lblAccessed = new System.Windows.Forms.Label();
- this.lblModified = new System.Windows.Forms.Label();
- this.lblCreated = new System.Windows.Forms.Label();
- this.groupBox1 = new System.Windows.Forms.GroupBox();
- this.lblCreatedDate = new System.Windows.Forms.Label();
- this.lblModifiedDate = new System.Windows.Forms.Label();
- this.lblAccessedDate = new System.Windows.Forms.Label();
- this.Date = new System.Windows.Forms.NumericUpDown();
- this.Month = new System.Windows.Forms.NumericUpDown();
- this.Year = new System.Windows.Forms.NumericUpDown();
- this.Modified = new System.Windows.Forms.RadioButton();
- this.Accessed = new System.Windows.Forms.RadioButton();
- this.FCreated = new System.Windows.Forms.RadioButton();
- this.bModify = new System.Windows.Forms.Button();
- this.bQuit = new System.Windows.Forms.Button();
- this.statusBar = new System.Windows.Forms.StatusBar();
- this.groupBox1.SuspendLayout();
- ((System.ComponentModel.ISupportInitialize)(this.Date)).BeginInit();
- ((System.ComponentModel.ISupportInitialize)(this.Month)).BeginInit();
- ((System.ComponentModel.ISupportInitialize)(this.Year)).BeginInit();
- this.SuspendLayout();
- //
- // bBrowse
- //
- this.bBrowse.Location = new System.Drawing.Point(16, 216);
- this.bBrowse.Name = "bBrowse";
- this.bBrowse.TabIndex = 0;
- this.bBrowse.Text = "&Browse";
- this.bBrowse.Click += new System.EventHandler(this.bBrowse_Click);
- //
- // lblAccessed
- //
- this.lblAccessed.Location = new System.Drawing.Point(16, 24);
- this.lblAccessed.Name = "lblAccessed";
- this.lblAccessed.Size = new System.Drawing.Size(64, 23);
- this.lblAccessed.TabIndex = 1;
- this.lblAccessed.Text = "Accessed :";
- //
- // lblModified
- //
- this.lblModified.Location = new System.Drawing.Point(16, 56);
- this.lblModified.Name = "lblModified";
- this.lblModified.Size = new System.Drawing.Size(64, 23);
- this.lblModified.TabIndex = 2;
- this.lblModified.Text = "Modified :";
- //
- // lblCreated
- //
- this.lblCreated.Location = new System.Drawing.Point(16, 88);
- this.lblCreated.Name = "lblCreated";
- this.lblCreated.Size = new System.Drawing.Size(64, 23);
- this.lblCreated.TabIndex = 3;
- this.lblCreated.Text = "Created :";
- //
- // groupBox1
- //
- this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.groupBox1.Controls.Add(this.lblCreatedDate);
- this.groupBox1.Controls.Add(this.lblModifiedDate);
- this.groupBox1.Controls.Add(this.lblAccessedDate);
- this.groupBox1.Controls.Add(this.lblAccessed);
- this.groupBox1.Controls.Add(this.lblCreated);
- this.groupBox1.Controls.Add(this.lblModified);
- this.groupBox1.Location = new System.Drawing.Point(16, 48);
- this.groupBox1.Name = "groupBox1";
- this.groupBox1.Size = new System.Drawing.Size(368, 128);
- this.groupBox1.TabIndex = 4;
- this.groupBox1.TabStop = false;
- this.groupBox1.Text = "Files Attributes";
- //
- // lblCreatedDate
- //
- this.lblCreatedDate.Location = new System.Drawing.Point(96, 88);
- this.lblCreatedDate.Name = "lblCreatedDate";
- this.lblCreatedDate.Size = new System.Drawing.Size(264, 23);
- this.lblCreatedDate.TabIndex = 6;
- //
- // lblModifiedDate
- //
- this.lblModifiedDate.Location = new System.Drawing.Point(96, 56);
- this.lblModifiedDate.Name = "lblModifiedDate";
- this.lblModifiedDate.Size = new System.Drawing.Size(264, 23);
- this.lblModifiedDate.TabIndex = 5;
- //
- // lblAccessedDate
- //
- this.lblAccessedDate.Location = new System.Drawing.Point(96, 24);
- this.lblAccessedDate.Name = "lblAccessedDate";
- this.lblAccessedDate.Size = new System.Drawing.Size(264, 23);
- this.lblAccessedDate.TabIndex = 4;
- //
- // Date
- //
- this.Date.Location = new System.Drawing.Point(16, 184);
- this.Date.Maximum = new System.Decimal(new int[] {
- 31,
- 0,
- 0,
- 0});
- this.Date.Name = "Date";
- this.Date.Size = new System.Drawing.Size(48, 20);
- this.Date.TabIndex = 5;
- //
- // Month
- //
- this.Month.Location = new System.Drawing.Point(80, 184);
- this.Month.Maximum = new System.Decimal(new int[] {
- 31,
- 0,
- 0,
- 0});
- this.Month.Name = "Month";
- this.Month.Size = new System.Drawing.Size(48, 20);
- this.Month.TabIndex = 6;
- this.Month.ValueChanged += new System.EventHandler(this.Month_ValueChanged);
- //
- // Year
- //
- this.Year.Location = new System.Drawing.Point(144, 184);
- this.Year.Maximum = new System.Decimal(new int[] {
- 2500,
- 0,
- 0,
- 0});
- this.Year.Minimum = new System.Decimal(new int[] {
- 1900,
- 0,
- 0,
- 0});
- this.Year.Name = "Year";
- this.Year.Size = new System.Drawing.Size(48, 20);
- this.Year.TabIndex = 7;
- this.Year.Value = new System.Decimal(new int[] {
- 1900,
- 0,
- 0,
- 0});
- //
- // Modified
- //
- this.Modified.Appearance = System.Windows.Forms.Appearance.Button;
- this.Modified.Location = new System.Drawing.Point(128, 8);
- this.Modified.Name = "Modified";
- this.Modified.TabIndex = 9;
- this.Modified.Text = "Modified";
- this.Modified.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
- this.Modified.CheckedChanged += new System.EventHandler(this.Type_CheckedChanged);
- //
- // Accessed
- //
- this.Accessed.Appearance = System.Windows.Forms.Appearance.Button;
- this.Accessed.Location = new System.Drawing.Point(16, 8);
- this.Accessed.Name = "Accessed";
- this.Accessed.TabIndex = 10;
- this.Accessed.Text = "Accessed";
- this.Accessed.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
- this.Accessed.CheckedChanged += new System.EventHandler(this.Type_CheckedChanged);
- //
- // FCreated
- //
- this.FCreated.Appearance = System.Windows.Forms.Appearance.Button;
- this.FCreated.Location = new System.Drawing.Point(240, 8);
- this.FCreated.Name = "FCreated";
- this.FCreated.TabIndex = 11;
- this.FCreated.Text = "&Created";
- this.FCreated.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
- this.FCreated.CheckedChanged += new System.EventHandler(this.Type_CheckedChanged);
- //
- // bModify
- //
- this.bModify.Location = new System.Drawing.Point(104, 216);
- this.bModify.Name = "bModify";
- this.bModify.TabIndex = 12;
- this.bModify.Text = "&Update";
- this.bModify.Click += new System.EventHandler(this.bModify_Click);
- //
- // bQuit
- //
- this.bQuit.Location = new System.Drawing.Point(192, 216);
- this.bQuit.Name = "bQuit";
- this.bQuit.TabIndex = 13;
- this.bQuit.Text = "&Quit";
- this.bQuit.Click += new System.EventHandler(this.bQuit_Click);
- //
- // statusBar
- //
- this.statusBar.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
- this.statusBar.Location = new System.Drawing.Point(0, 252);
- this.statusBar.Name = "statusBar";
- this.statusBar.Size = new System.Drawing.Size(392, 22);
- this.statusBar.TabIndex = 14;
- //
- // FilesManagerUI
- //
- this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
- this.ClientSize = new System.Drawing.Size(392, 274);
- this.Controls.Add(this.statusBar);
- this.Controls.Add(this.bQuit);
- this.Controls.Add(this.bModify);
- this.Controls.Add(this.FCreated);
- this.Controls.Add(this.Accessed);
- this.Controls.Add(this.Modified);
- this.Controls.Add(this.Year);
- this.Controls.Add(this.Month);
- this.Controls.Add(this.Date);
- this.Controls.Add(this.groupBox1);
- this.Controls.Add(this.bBrowse);
- this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
- this.Name = "FilesManagerUI";
- this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
- this.Text = "Files Manager";
- this.Load += new System.EventHandler(this.FilesManagerUI_Load);
- this.groupBox1.ResumeLayout(false);
- ((System.ComponentModel.ISupportInitialize)(this.Date)).EndInit();
- ((System.ComponentModel.ISupportInitialize)(this.Month)).EndInit();
- ((System.ComponentModel.ISupportInitialize)(this.Year)).EndInit();
- this.ResumeLayout(false);
-
- }
- #endregion
-
- /// <summary>
- /// The main entry point for the application.
- /// </summary>
- [STAThread]
- static void Main()
- {
- Application.Run(new FilesManagerUI());
- }
-
- private void bBrowse_Click(object sender, System.EventArgs e)
- {
- /* clear all information for the new selected file */
- lblAccessedDate.Text = null;
- lblCreatedDate.Text = null;
- lblModifiedDate.Text = null;
-
- OpenFileDialog oFileDialog = new OpenFileDialog();
-
- oFileDialog.InitialDirectory = @"C:\";
- oFileDialog.Filter = "All Files (*.*)|*.*";
- oFileDialog.RestoreDirectory = true;
-
- if(oFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
- {
- sPath = oFileDialog.FileName;
-
- statusBar.Text = sPath;
-
- /* only after the very first file has been choosen */
- Accessed.Enabled = true;
- Modified.Enabled = true;
- FCreated.Enabled = true;
-
- /* return all attributes information */
- GetAllDates();
-
- if(FCreated.Checked == false)
- {
- FCreated.Checked = true;
- }
- else
- {
- Date.Value = dCreated.Day;
- Month.Value = dCreated.Month;
- Year.Value = dCreated.Year;
- }
- }
- }
-
- private void FilesManagerUI_Load(object sender, System.EventArgs e)
- {
- FCreated.Checked = true;
-
- if(sPath == "" || sPath == null)
- {
- FCreated.Enabled = false;
- Accessed.Enabled = false;
- Modified.Enabled = false;
- }
- }
-
- private void Type_CheckedChanged(object sender, System.EventArgs e)
- {
- RadioButton button = (RadioButton)sender;
-
- if(button.Checked)
- {
- switch(button.Name)
- {
- case "FCreated" :
- action = ACTION.CREATED ;
- Date.Value = dCreated.Day;
- Month.Value = dCreated.Month;
- Year.Value = dCreated.Year;
- break;
- case "Modified" :
- action = ACTION.MODIFIED;
- Date.Value = dModified.Day;
- Month.Value = dModified.Month;
- Year.Value = dModified.Year;
- break;
- case "Accessed" :
- action = ACTION.ACCESSED;
- Date.Value = dAccessed.Day;
- Month.Value = dAccessed.Month;
- Year.Value = dAccessed.Year;
- break;
- }
- }
- }
-
- /* As soon as the month is selected, the max number of days is updated based on the month and year */
- private void Month_ValueChanged(object sender, System.EventArgs e)
- {
- Date.Maximum = DateTime.DaysInMonth(Convert.ToInt32(Year.Value), Convert.ToInt32(Month.Value));
- }
-
- private void bModify_Click(object sender, System.EventArgs e)
- {
- if(sPath == "" || sPath == null)
- {
- MessageBox.Show("You must choose a file first please.","Failure",MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
-
- DateTime dNewDate = DateTime.Now;
-
- switch(action)
- {
- case ACTION.CREATED :
- dNewDate = new DateTime(Convert.ToInt32(Year.Value),Convert.ToInt32(Month.Value),Convert.ToInt32(Date.Value),dCreated.Hour,dCreated.Minute,dCreated.Second,dCreated.Millisecond);
- break;
- case ACTION.MODIFIED :
- dNewDate = new DateTime(Convert.ToInt32(Year.Value),Convert.ToInt32(Month.Value),Convert.ToInt32(Date.Value),dModified.Hour,dModified.Minute,dModified.Second,dModified.Millisecond);
- break;
- case ACTION.ACCESSED :
- dNewDate = new DateTime(Convert.ToInt32(Year.Value),Convert.ToInt32(Month.Value),Convert.ToInt32(Date.Value),dAccessed.Hour,dAccessed.Minute,dAccessed.Second,dAccessed.Millisecond);
- break;
- }
-
- /* we can set any date we want for the creation but we can't
- * set a date older than the creation date for the other cases */
- if(action != ACTION.CREATED)
- {
- if(DateTime.Compare(dNewDate, dCreated) < 0)
- {
- MessageBox.Show("You can't set this attribute" + ((action == ACTION.ACCESSED)? " Accessed" : " Modified ") +
- " to an earlier datetime than the Created datetime!",
- "Failure",MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- }
- else
- {
- if((DateTime.Compare(dNewDate, dModified) > 0)||(DateTime.Compare(dNewDate, dAccessed) > 0))
- {
- MessageBox.Show("You can't set this attribute Created " +
- " to an later datetime than the other datetimes!",
- "Failure",MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
-
- }
- /* Attributes update */
- switch(action)
- {
- case ACTION.CREATED :
- System.IO.File.SetCreationTime(sPath, dNewDate);
- break;
- case ACTION.MODIFIED :
- System.IO.File.SetLastWriteTime(sPath, dNewDate);
- break;
- case ACTION.ACCESSED :
- System.IO.File.SetLastAccessTime(sPath, dNewDate);
- break;
- }
-
- lblAccessedDate.Text = null;
- lblCreatedDate.Text = null;
- lblModifiedDate.Text = null;
-
- GetAllDates();
- }
-
- private void bQuit_Click(object sender, System.EventArgs e)
- {
- this.Close();
- }
-
- private void GetAllDates()
- {
- /* string used to display the date */
- string sDate = "";
-
- /* return all information about the file attributes */
-
- dAccessed = System.IO.File.GetLastAccessTime(sPath);
- sDate = dAccessed.ToString(FORMATDATE);
- lblAccessedDate.Text = lblAccessedDate.Text + sDate;
-
- dModified = System.IO.File.GetLastWriteTime(sPath);
- sDate = dModified.ToString(FORMATDATE);
- lblModifiedDate.Text = lblModifiedDate.Text + sDate;
-
- dCreated = System.IO.File.GetCreationTime(sPath);
- sDate = dCreated.ToString(FORMATDATE);
- lblCreatedDate.Text = lblCreatedDate.Text + sDate;
- }
- }
- }
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace FilesManager
{
/* Available actions : modify created, last modified and last accessed dates */
public enum ACTION : int
{
CREATED = 1,
MODIFIED = 2,
ACCESSED = 3
}
/// <summary>
/// A simple windows form application to update file attributes
/// </summary>
public class FilesManagerUI : System.Windows.Forms.Form
{
/* date format used */
private const string FORMATDATE = "dddd dd MMMM yyyy, hh:mm:ss";
/* all dates used */
private DateTime dCreated = DateTime.Now;
private DateTime dAccessed = DateTime.Now;
private DateTime dModified = DateTime.Now;
/* file path */
private string sPath;
/* action selected by the user */
private ACTION action;
private System.Windows.Forms.Label lblAccessed;
private System.Windows.Forms.Label lblModified;
private System.Windows.Forms.Label lblCreated;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Label lblModifiedDate;
private System.Windows.Forms.Label lblAccessedDate;
private System.Windows.Forms.Label lblCreatedDate;
private System.Windows.Forms.NumericUpDown Date;
private System.Windows.Forms.NumericUpDown Month;
private System.Windows.Forms.NumericUpDown Year;
private System.Windows.Forms.RadioButton Modified;
private System.Windows.Forms.RadioButton Accessed;
private System.Windows.Forms.RadioButton FCreated;
private System.Windows.Forms.Button bModify;
private System.Windows.Forms.Button bQuit;
private System.Windows.Forms.Button bBrowse;
private System.Windows.Forms.StatusBar statusBar;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public FilesManagerUI()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.bBrowse = new System.Windows.Forms.Button();
this.lblAccessed = new System.Windows.Forms.Label();
this.lblModified = new System.Windows.Forms.Label();
this.lblCreated = new System.Windows.Forms.Label();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.lblCreatedDate = new System.Windows.Forms.Label();
this.lblModifiedDate = new System.Windows.Forms.Label();
this.lblAccessedDate = new System.Windows.Forms.Label();
this.Date = new System.Windows.Forms.NumericUpDown();
this.Month = new System.Windows.Forms.NumericUpDown();
this.Year = new System.Windows.Forms.NumericUpDown();
this.Modified = new System.Windows.Forms.RadioButton();
this.Accessed = new System.Windows.Forms.RadioButton();
this.FCreated = new System.Windows.Forms.RadioButton();
this.bModify = new System.Windows.Forms.Button();
this.bQuit = new System.Windows.Forms.Button();
this.statusBar = new System.Windows.Forms.StatusBar();
this.groupBox1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.Date)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.Month)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.Year)).BeginInit();
this.SuspendLayout();
//
// bBrowse
//
this.bBrowse.Location = new System.Drawing.Point(16, 216);
this.bBrowse.Name = "bBrowse";
this.bBrowse.TabIndex = 0;
this.bBrowse.Text = "&Browse";
this.bBrowse.Click += new System.EventHandler(this.bBrowse_Click);
//
// lblAccessed
//
this.lblAccessed.Location = new System.Drawing.Point(16, 24);
this.lblAccessed.Name = "lblAccessed";
this.lblAccessed.Size = new System.Drawing.Size(64, 23);
this.lblAccessed.TabIndex = 1;
this.lblAccessed.Text = "Accessed :";
//
// lblModified
//
this.lblModified.Location = new System.Drawing.Point(16, 56);
this.lblModified.Name = "lblModified";
this.lblModified.Size = new System.Drawing.Size(64, 23);
this.lblModified.TabIndex = 2;
this.lblModified.Text = "Modified :";
//
// lblCreated
//
this.lblCreated.Location = new System.Drawing.Point(16, 88);
this.lblCreated.Name = "lblCreated";
this.lblCreated.Size = new System.Drawing.Size(64, 23);
this.lblCreated.TabIndex = 3;
this.lblCreated.Text = "Created :";
//
// groupBox1
//
this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.groupBox1.Controls.Add(this.lblCreatedDate);
this.groupBox1.Controls.Add(this.lblModifiedDate);
this.groupBox1.Controls.Add(this.lblAccessedDate);
this.groupBox1.Controls.Add(this.lblAccessed);
this.groupBox1.Controls.Add(this.lblCreated);
this.groupBox1.Controls.Add(this.lblModified);
this.groupBox1.Location = new System.Drawing.Point(16, 48);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(368, 128);
this.groupBox1.TabIndex = 4;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Files Attributes";
//
// lblCreatedDate
//
this.lblCreatedDate.Location = new System.Drawing.Point(96, 88);
this.lblCreatedDate.Name = "lblCreatedDate";
this.lblCreatedDate.Size = new System.Drawing.Size(264, 23);
this.lblCreatedDate.TabIndex = 6;
//
// lblModifiedDate
//
this.lblModifiedDate.Location = new System.Drawing.Point(96, 56);
this.lblModifiedDate.Name = "lblModifiedDate";
this.lblModifiedDate.Size = new System.Drawing.Size(264, 23);
this.lblModifiedDate.TabIndex = 5;
//
// lblAccessedDate
//
this.lblAccessedDate.Location = new System.Drawing.Point(96, 24);
this.lblAccessedDate.Name = "lblAccessedDate";
this.lblAccessedDate.Size = new System.Drawing.Size(264, 23);
this.lblAccessedDate.TabIndex = 4;
//
// Date
//
this.Date.Location = new System.Drawing.Point(16, 184);
this.Date.Maximum = new System.Decimal(new int[] {
31,
0,
0,
0});
this.Date.Name = "Date";
this.Date.Size = new System.Drawing.Size(48, 20);
this.Date.TabIndex = 5;
//
// Month
//
this.Month.Location = new System.Drawing.Point(80, 184);
this.Month.Maximum = new System.Decimal(new int[] {
31,
0,
0,
0});
this.Month.Name = "Month";
this.Month.Size = new System.Drawing.Size(48, 20);
this.Month.TabIndex = 6;
this.Month.ValueChanged += new System.EventHandler(this.Month_ValueChanged);
//
// Year
//
this.Year.Location = new System.Drawing.Point(144, 184);
this.Year.Maximum = new System.Decimal(new int[] {
2500,
0,
0,
0});
this.Year.Minimum = new System.Decimal(new int[] {
1900,
0,
0,
0});
this.Year.Name = "Year";
this.Year.Size = new System.Drawing.Size(48, 20);
this.Year.TabIndex = 7;
this.Year.Value = new System.Decimal(new int[] {
1900,
0,
0,
0});
//
// Modified
//
this.Modified.Appearance = System.Windows.Forms.Appearance.Button;
this.Modified.Location = new System.Drawing.Point(128, 8);
this.Modified.Name = "Modified";
this.Modified.TabIndex = 9;
this.Modified.Text = "Modified";
this.Modified.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.Modified.CheckedChanged += new System.EventHandler(this.Type_CheckedChanged);
//
// Accessed
//
this.Accessed.Appearance = System.Windows.Forms.Appearance.Button;
this.Accessed.Location = new System.Drawing.Point(16, 8);
this.Accessed.Name = "Accessed";
this.Accessed.TabIndex = 10;
this.Accessed.Text = "Accessed";
this.Accessed.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.Accessed.CheckedChanged += new System.EventHandler(this.Type_CheckedChanged);
//
// FCreated
//
this.FCreated.Appearance = System.Windows.Forms.Appearance.Button;
this.FCreated.Location = new System.Drawing.Point(240, 8);
this.FCreated.Name = "FCreated";
this.FCreated.TabIndex = 11;
this.FCreated.Text = "&Created";
this.FCreated.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.FCreated.CheckedChanged += new System.EventHandler(this.Type_CheckedChanged);
//
// bModify
//
this.bModify.Location = new System.Drawing.Point(104, 216);
this.bModify.Name = "bModify";
this.bModify.TabIndex = 12;
this.bModify.Text = "&Update";
this.bModify.Click += new System.EventHandler(this.bModify_Click);
//
// bQuit
//
this.bQuit.Location = new System.Drawing.Point(192, 216);
this.bQuit.Name = "bQuit";
this.bQuit.TabIndex = 13;
this.bQuit.Text = "&Quit";
this.bQuit.Click += new System.EventHandler(this.bQuit_Click);
//
// statusBar
//
this.statusBar.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.statusBar.Location = new System.Drawing.Point(0, 252);
this.statusBar.Name = "statusBar";
this.statusBar.Size = new System.Drawing.Size(392, 22);
this.statusBar.TabIndex = 14;
//
// FilesManagerUI
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(392, 274);
this.Controls.Add(this.statusBar);
this.Controls.Add(this.bQuit);
this.Controls.Add(this.bModify);
this.Controls.Add(this.FCreated);
this.Controls.Add(this.Accessed);
this.Controls.Add(this.Modified);
this.Controls.Add(this.Year);
this.Controls.Add(this.Month);
this.Controls.Add(this.Date);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.bBrowse);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
this.Name = "FilesManagerUI";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Files Manager";
this.Load += new System.EventHandler(this.FilesManagerUI_Load);
this.groupBox1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.Date)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.Month)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.Year)).EndInit();
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new FilesManagerUI());
}
private void bBrowse_Click(object sender, System.EventArgs e)
{
/* clear all information for the new selected file */
lblAccessedDate.Text = null;
lblCreatedDate.Text = null;
lblModifiedDate.Text = null;
OpenFileDialog oFileDialog = new OpenFileDialog();
oFileDialog.InitialDirectory = @"C:\";
oFileDialog.Filter = "All Files (*.*)|*.*";
oFileDialog.RestoreDirectory = true;
if(oFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
sPath = oFileDialog.FileName;
statusBar.Text = sPath;
/* only after the very first file has been choosen */
Accessed.Enabled = true;
Modified.Enabled = true;
FCreated.Enabled = true;
/* return all attributes information */
GetAllDates();
if(FCreated.Checked == false)
{
FCreated.Checked = true;
}
else
{
Date.Value = dCreated.Day;
Month.Value = dCreated.Month;
Year.Value = dCreated.Year;
}
}
}
private void FilesManagerUI_Load(object sender, System.EventArgs e)
{
FCreated.Checked = true;
if(sPath == "" || sPath == null)
{
FCreated.Enabled = false;
Accessed.Enabled = false;
Modified.Enabled = false;
}
}
private void Type_CheckedChanged(object sender, System.EventArgs e)
{
RadioButton button = (RadioButton)sender;
if(button.Checked)
{
switch(button.Name)
{
case "FCreated" :
action = ACTION.CREATED ;
Date.Value = dCreated.Day;
Month.Value = dCreated.Month;
Year.Value = dCreated.Year;
break;
case "Modified" :
action = ACTION.MODIFIED;
Date.Value = dModified.Day;
Month.Value = dModified.Month;
Year.Value = dModified.Year;
break;
case "Accessed" :
action = ACTION.ACCESSED;
Date.Value = dAccessed.Day;
Month.Value = dAccessed.Month;
Year.Value = dAccessed.Year;
break;
}
}
}
/* As soon as the month is selected, the max number of days is updated based on the month and year */
private void Month_ValueChanged(object sender, System.EventArgs e)
{
Date.Maximum = DateTime.DaysInMonth(Convert.ToInt32(Year.Value), Convert.ToInt32(Month.Value));
}
private void bModify_Click(object sender, System.EventArgs e)
{
if(sPath == "" || sPath == null)
{
MessageBox.Show("You must choose a file first please.","Failure",MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
DateTime dNewDate = DateTime.Now;
switch(action)
{
case ACTION.CREATED :
dNewDate = new DateTime(Convert.ToInt32(Year.Value),Convert.ToInt32(Month.Value),Convert.ToInt32(Date.Value),dCreated.Hour,dCreated.Minute,dCreated.Second,dCreated.Millisecond);
break;
case ACTION.MODIFIED :
dNewDate = new DateTime(Convert.ToInt32(Year.Value),Convert.ToInt32(Month.Value),Convert.ToInt32(Date.Value),dModified.Hour,dModified.Minute,dModified.Second,dModified.Millisecond);
break;
case ACTION.ACCESSED :
dNewDate = new DateTime(Convert.ToInt32(Year.Value),Convert.ToInt32(Month.Value),Convert.ToInt32(Date.Value),dAccessed.Hour,dAccessed.Minute,dAccessed.Second,dAccessed.Millisecond);
break;
}
/* we can set any date we want for the creation but we can't
* set a date older than the creation date for the other cases */
if(action != ACTION.CREATED)
{
if(DateTime.Compare(dNewDate, dCreated) < 0)
{
MessageBox.Show("You can't set this attribute" + ((action == ACTION.ACCESSED)? " Accessed" : " Modified ") +
" to an earlier datetime than the Created datetime!",
"Failure",MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
}
else
{
if((DateTime.Compare(dNewDate, dModified) > 0)||(DateTime.Compare(dNewDate, dAccessed) > 0))
{
MessageBox.Show("You can't set this attribute Created " +
" to an later datetime than the other datetimes!",
"Failure",MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
}
/* Attributes update */
switch(action)
{
case ACTION.CREATED :
System.IO.File.SetCreationTime(sPath, dNewDate);
break;
case ACTION.MODIFIED :
System.IO.File.SetLastWriteTime(sPath, dNewDate);
break;
case ACTION.ACCESSED :
System.IO.File.SetLastAccessTime(sPath, dNewDate);
break;
}
lblAccessedDate.Text = null;
lblCreatedDate.Text = null;
lblModifiedDate.Text = null;
GetAllDates();
}
private void bQuit_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void GetAllDates()
{
/* string used to display the date */
string sDate = "";
/* return all information about the file attributes */
dAccessed = System.IO.File.GetLastAccessTime(sPath);
sDate = dAccessed.ToString(FORMATDATE);
lblAccessedDate.Text = lblAccessedDate.Text + sDate;
dModified = System.IO.File.GetLastWriteTime(sPath);
sDate = dModified.ToString(FORMATDATE);
lblModifiedDate.Text = lblModifiedDate.Text + sDate;
dCreated = System.IO.File.GetCreationTime(sPath);
sDate = dCreated.ToString(FORMATDATE);
lblCreatedDate.Text = lblCreatedDate.Text + sDate;
}
}
}
Conclusion
Je ferais une mise à jour lors de ma prochaine pause entre deux projets au boulot :) c'est pour passer le temps et apprendre des nouvelles choses !
Historique
- 22 avril 2007 01:48:29 :
- Mise à jour du code
Sources de la même categorie
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
DE l'aide SVP Attributs Xml [ par rintchu ]
Bonjour,je rencontre des problemes lorsque je veux inserer un attribut dans un node, mais je veux que celui ci depende d'un namespace et j'y arrive pa
Modifier un fichier [ par gillescpp ]
Voila, j'aimerais savoir si il est possible de modifier un fichier (binaire dans mon cas) ou plus precisément de supprimer ou ajouter des octets a l'i
Gérer du xml à travers un datagrid [ par Januka ]
Bonjour,j'ai un pb avec un fichier xml que j'aimerais gérer au travers d'une interface, au lieu d'éditer le fichier et le compléter dans un fichier te
récupération du résumé d'un fichier image [ par LeGnuff ]
Bonjour j'aurai aimé savoir s'il y a un moyen en C# de récupérer les informations stockées dans un fichier image sous Windows XP (dans Propriétés =>
Date de création d'un fichier [ par thebigboss ]
Je voudrais savoir s'il existe une façon de modifier la date de création d'un fichier???Merci d'avance.
ajouter, modifier un fichier xml [ par tmcuh ]
bonjour, je débute un peu dans le xml et j'aurais aimé modifier des données présentes dans un clé (avec paramètres), raj
Date de creation d'un fichier [ par 24 ans ]
mon besoin c'est que je veux savoire la date de creation d'un fichier qui se trouve dans un compte ftp .comment faire c'est trop Urgentmerci d'avance
Modifier heure et date du PC [ par hetneo ]
Bonjour,Je voudrais savoir si il est possible de modifier l'heure et la date du PC en lancant un programme C# ?Par exemple, on charge un fichier qui c
[c# /xml] comment modifier un fichier xml par programmation c# [ par moha_yougo ]
comment modifier un document xml ,suppréssion des element,ajout des elements a des en droit bien précis
Modifier le contenu d un fichier [ par titou0809 ]
Salut,Je suis un GROS debutant en C# alors please soyez cool :)J aimerais modifier des chaines de caracteres par d autres dans un fichier.Seulement je
|
Derniers Blogs
UNE JOLIE-HORLOGE ET PAS QU'UN PEU !UNE JOLIE-HORLOGE ET PAS QU'UN PEU ! par neodante
Pour les possesseurs d'iPhone, ça y est Bijin Tokei - qui se traduit littéralement en Français par " Jolie Horloge " - est arrivé et GRATUITEMENT s'il vous plaît ! Après la version Tokyo, Hokkaido, night club, racing, Gal, "pour les mademoiselles'", . voi...
Cliquez pour lire la suite de l'article par neodante TECHDAYS PARIS 2010 : CONNECTEZ VOS DONNéES à SHAREPOINT 2010 AVEC LES BUSINESS CONNECTIVITY SERVICESTECHDAYS PARIS 2010 : CONNECTEZ VOS DONNéES à SHAREPOINT 2010 AVEC LES BUSINESS CONNECTIVITY SERVICES par ROMELARD Fabrice
Animé par: Gaetan Bouveret et Julien Chomarat Business Connectivity Services (BCS) est dans SharePoint 2010 la version 2 de Business Data Catalog (BDC dans SharePoint 2007). Il s'agit de la solution permettant de visualiser des données provenan...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice [DIVERS] SUIVRE VOS SéRIES PRéFéRéS SUR LA TOILE[DIVERS] SUIVRE VOS SéRIES PRéFéRéS SUR LA TOILE par orion
Comme de nombreux geek, je suis un grand amateur de série TV et je rate régulièrement des épisodes de mes séries préférés. Une solution s'offre à vous avec ce merveilleux site : Tv Gorge - www.tvgorge.com Moteur de recherche à l'appui, vous pouvez ...
Cliquez pour lire la suite de l'article par orion TECHDAYS PARIS 2010 : LA BI DANS SHAREPOINT 2010TECHDAYS PARIS 2010 : LA BI DANS SHAREPOINT 2010 par ROMELARD Fabrice
Animé par: Vincent Bellet et Baptiste Giraudier La BI dans SharePoint 2010, Les nouveaux services d'application dans SP2010 et SQL Server Reporting services 2008 R2. La BI dans SharePoint est généralisée pour tous afin de permettre à tous les coll...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Logiciels
DB-MAIN (9.1.0)DB-MAIN (9.1.0)DB-MAIN is a data-modeling and data-architecture tool. It is designed to help developers and anal... Cliquez pour télécharger DB-MAIN Xilisoft DPG Convertisseur (5.1.37.0120)XILISOFT DPG CONVERTISSEUR (5.1.37.0120)Xilisoft DPG Convertisseur offre aux fans de Nintendo DS une bonne solution leur permettant de dé... Cliquez pour télécharger Xilisoft DPG Convertisseur GraphicsGale (2.01.01)GRAPHICSGALE (2.01.01)GraphicsGale est un logiciel de PixelArt avec de nombreuse fonctionnalités permettant de réalisé ... Cliquez pour télécharger GraphicsGale Architecte 3D (Platinum 2010)ARCHITECTE 3D (PLATINUM 2010)Architecte 3D Platinium vous permet de concevoir facilement les plans votre future maison, de l'é... Cliquez pour télécharger Architecte 3D TeamViewer 5 (TeamViewer 5)TEAMVIEWER 5 (TEAMVIEWER 5)Dépanner un ami,expliquer une manipulation devient un jeu d'enfant.
Prise en main d'un autre ord... Cliquez pour télécharger TeamViewer 5
Comparez les prix

HTC Hero
Entre 550€ et 550€
|