dateirenamer

This commit is contained in:
Manuel Kamper 2021-04-02 22:34:04 +02:00
parent 0c09fdd085
commit 7b4e4cb555
6 changed files with 472 additions and 2 deletions

View File

@ -0,0 +1,242 @@

namespace Mk0.Software.ImageSorter
{
partial class Dateirenamer
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (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.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.textBoxSuche = new System.Windows.Forms.TextBox();
this.textBoxErsetze = new System.Windows.Forms.TextBox();
this.buttonAusfuehren = new System.Windows.Forms.Button();
this.buttonSpeichern = new System.Windows.Forms.Button();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.button5 = new System.Windows.Forms.Button();
this.button4 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.textBoxLog = new System.Windows.Forms.TextBox();
this.checkBoxRekursiv = new System.Windows.Forms.CheckBox();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.groupBox3.SuspendLayout();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(6, 16);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(71, 13);
this.label1.TabIndex = 0;
this.label1.Text = "Suchen nach";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(6, 69);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(64, 13);
this.label2.TabIndex = 1;
this.label2.Text = "Ersetzen mit";
//
// textBoxSuche
//
this.textBoxSuche.Location = new System.Drawing.Point(6, 35);
this.textBoxSuche.Name = "textBoxSuche";
this.textBoxSuche.Size = new System.Drawing.Size(182, 20);
this.textBoxSuche.TabIndex = 2;
//
// textBoxErsetze
//
this.textBoxErsetze.Location = new System.Drawing.Point(6, 88);
this.textBoxErsetze.Name = "textBoxErsetze";
this.textBoxErsetze.Size = new System.Drawing.Size(182, 20);
this.textBoxErsetze.TabIndex = 3;
//
// buttonAusfuehren
//
this.buttonAusfuehren.Location = new System.Drawing.Point(6, 155);
this.buttonAusfuehren.Name = "buttonAusfuehren";
this.buttonAusfuehren.Size = new System.Drawing.Size(75, 23);
this.buttonAusfuehren.TabIndex = 4;
this.buttonAusfuehren.Text = "Ausführen";
this.buttonAusfuehren.UseVisualStyleBackColor = true;
this.buttonAusfuehren.Click += new System.EventHandler(this.ButtonAusfuehren_Click);
//
// buttonSpeichern
//
this.buttonSpeichern.Location = new System.Drawing.Point(113, 155);
this.buttonSpeichern.Name = "buttonSpeichern";
this.buttonSpeichern.Size = new System.Drawing.Size(75, 23);
this.buttonSpeichern.TabIndex = 5;
this.buttonSpeichern.Text = "Speichern";
this.buttonSpeichern.UseVisualStyleBackColor = true;
this.buttonSpeichern.Click += new System.EventHandler(this.ButtonSpeichern_Click);
//
// groupBox1
//
this.groupBox1.Controls.Add(this.checkBoxRekursiv);
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Controls.Add(this.buttonSpeichern);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Controls.Add(this.buttonAusfuehren);
this.groupBox1.Controls.Add(this.textBoxSuche);
this.groupBox1.Controls.Add(this.textBoxErsetze);
this.groupBox1.Location = new System.Drawing.Point(12, 12);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(196, 190);
this.groupBox1.TabIndex = 6;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Operation";
//
// groupBox2
//
this.groupBox2.Controls.Add(this.button5);
this.groupBox2.Controls.Add(this.button4);
this.groupBox2.Controls.Add(this.button3);
this.groupBox2.Location = new System.Drawing.Point(269, 28);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(178, 106);
this.groupBox2.TabIndex = 7;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "Gespeicherte Operationen";
this.groupBox2.Visible = false;
//
// button5
//
this.button5.Location = new System.Drawing.Point(8, 60);
this.button5.Name = "button5";
this.button5.Size = new System.Drawing.Size(156, 23);
this.button5.TabIndex = 2;
this.button5.Text = "Alle Ausführen";
this.button5.UseVisualStyleBackColor = true;
//
// button4
//
this.button4.Location = new System.Drawing.Point(89, 31);
this.button4.Name = "button4";
this.button4.Size = new System.Drawing.Size(75, 23);
this.button4.TabIndex = 1;
this.button4.Text = "Ausführen";
this.button4.UseVisualStyleBackColor = true;
//
// button3
//
this.button3.Location = new System.Drawing.Point(8, 31);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(75, 23);
this.button3.TabIndex = 0;
this.button3.Text = "Löschen";
this.button3.UseVisualStyleBackColor = true;
//
// groupBox3
//
this.groupBox3.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.groupBox3.Controls.Add(this.textBoxLog);
this.groupBox3.Location = new System.Drawing.Point(12, 214);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(618, 188);
this.groupBox3.TabIndex = 8;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "Logs";
//
// textBoxLog
//
this.textBoxLog.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.textBoxLog.BackColor = System.Drawing.SystemColors.Window;
this.textBoxLog.Location = new System.Drawing.Point(6, 19);
this.textBoxLog.Multiline = true;
this.textBoxLog.Name = "textBoxLog";
this.textBoxLog.ReadOnly = true;
this.textBoxLog.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.textBoxLog.Size = new System.Drawing.Size(606, 163);
this.textBoxLog.TabIndex = 0;
//
// checkBoxRekursiv
//
this.checkBoxRekursiv.AutoSize = true;
this.checkBoxRekursiv.Checked = true;
this.checkBoxRekursiv.CheckState = System.Windows.Forms.CheckState.Checked;
this.checkBoxRekursiv.Location = new System.Drawing.Point(6, 123);
this.checkBoxRekursiv.Name = "checkBoxRekursiv";
this.checkBoxRekursiv.Size = new System.Drawing.Size(68, 17);
this.checkBoxRekursiv.TabIndex = 6;
this.checkBoxRekursiv.Text = "Rekursiv";
this.checkBoxRekursiv.UseVisualStyleBackColor = true;
//
// Dateirenamer
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(638, 410);
this.Controls.Add(this.groupBox3);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.MinimumSize = new System.Drawing.Size(654, 397);
this.Name = "Dateirenamer";
this.ShowIcon = false;
this.ShowInTaskbar = false;
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Dateirenamer";
this.TopMost = true;
this.Shown += new System.EventHandler(this.Dateirenamer_Shown);
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.groupBox2.ResumeLayout(false);
this.groupBox3.ResumeLayout(false);
this.groupBox3.PerformLayout();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox textBoxSuche;
private System.Windows.Forms.TextBox textBoxErsetze;
private System.Windows.Forms.Button buttonAusfuehren;
private System.Windows.Forms.Button buttonSpeichern;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.Button button5;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.GroupBox groupBox3;
private System.Windows.Forms.TextBox textBoxLog;
private System.Windows.Forms.CheckBox checkBoxRekursiv;
}
}

View File

@ -0,0 +1,91 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Mk0.Software.ImageSorter
{
public partial class Dateirenamer : Form
{
private string quellPath;
public Dateirenamer(string quellPath)
{
InitializeComponent();
this.quellPath = quellPath;
}
private void Dateirenamer_Shown(object sender, EventArgs e)
{
if (!Directory.Exists(quellPath))
{
MessageBox.Show("Es wurde kein gültiger Quellpfad definiert. Bitte zuerst definieren, dann erneut versuchen.", "Kein Quellpfad definiert", MessageBoxButtons.OK, MessageBoxIcon.Error);
this.Close();
}
}
private void ButtonAusfuehren_Click(object sender, EventArgs e)
{
if (CheckInput())
{
textBoxLog.Clear();
Scanner(quellPath, textBoxSuche.Text, textBoxErsetze.Text, checkBoxRekursiv.Checked);
}
}
private void ButtonSpeichern_Click(object sender, EventArgs e)
{
if (CheckInput())
{
MessageBox.Show("ok");
//todo
}
}
private bool CheckInput()
{
if (string.IsNullOrEmpty(textBoxSuche.Text))
{
return false;
}
return true;
}
public void Scanner(string pfad, string suchen, string ersetzen, bool rekursiv = false)
{
DirectoryInfo dir = new DirectoryInfo(pfad);
foreach (FileInfo file in dir.GetFiles("*.*"))
{
if (file.Name.Contains(suchen))
{
try
{
string newName = file.Name.Replace(suchen, ersetzen);
textBoxLog.AppendText("RENAME: " + dir.Name + "| " + file.Name + " -> " + newName + Environment.NewLine);
File.Move(Path.Combine(dir.FullName, file.Name), Path.Combine(dir.FullName, newName));
}
catch (Exception)
{
textBoxLog.AppendText("DELETE: " + dir.Name + "| " + file.Name + Environment.NewLine);
File.Delete(Path.Combine(dir.FullName, file.Name));
}
}
}
if (rekursiv)
{
foreach (DirectoryInfo dir2 in dir.GetDirectories())
{
Scanner(dir2.FullName, suchen, ersetzen, true);
}
}
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -51,7 +51,9 @@
this.MinimizeBox = false;
this.Name = "EXIF";
this.ShowIcon = false;
this.ShowInTaskbar = false;
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "EXIF";
this.Shown += new System.EventHandler(this.EXIF_Shown);
this.ResumeLayout(false);

View File

@ -703,6 +703,11 @@ namespace Mk0.Software.ImageSorter
}
}
/// <summary>
/// Removes the marks from cropping and cutting in filename
/// </summary>
/// <param name="filename"></param>
/// <returns></returns>
private string CleanFileName(string filename)
{
string fn = filename;
@ -1154,7 +1159,7 @@ namespace Mk0.Software.ImageSorter
using (Image img = Image.FromFile(pictureBoxImage.ImageLocation))
{
EXIF exif = new EXIF(img.PropertyItems);
exif.ShowDialog();
exif.ShowDialog(this);
}
}
@ -1613,7 +1618,8 @@ namespace Mk0.Software.ImageSorter
/// <param name="e"></param>
private void ButtonDateirenamer_Click(object sender, EventArgs e)
{
Dateirenamer dr = new Dateirenamer(quellPath);
dr.ShowDialog(this);
}
}
}

View File

@ -110,6 +110,12 @@
<Compile Include="Cropper.Designer.cs">
<DependentUpon>Cropper.cs</DependentUpon>
</Compile>
<Compile Include="Dateirenamer.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Dateirenamer.Designer.cs">
<DependentUpon>Dateirenamer.cs</DependentUpon>
</Compile>
<Compile Include="EXIF.cs">
<SubType>Form</SubType>
</Compile>
@ -140,6 +146,9 @@
<EmbeddedResource Include="Cropper.resx">
<DependentUpon>Cropper.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Dateirenamer.resx">
<DependentUpon>Dateirenamer.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="EXIF.resx">
<DependentUpon>EXIF.cs</DependentUpon>
</EmbeddedResource>