[英]Winforms load files from folder in datagridview, edit name and save them
I have about 20.000 files I have to rename, unfortunately is nothing I can automate because I have to check the content of each of them and add the appropriate name. 我必须重命名大约20.000个文件,但是我无法自动执行任何操作,因为我必须检查每个文件的内容并添加适当的名称。
However I am planning to build a win forms solution that will help me with that. 但是,我计划构建一个胜利表格解决方案,以帮助我解决这一问题。
Plan is: 计划是:
Questions: 问题:
And one more thing. 还有一件事。 I won't edit 20.000 items in one day, so I'm thinking if I can add an attribute to the file that was edited already and mark it as true, or something like that, so the next day I can continue with the left ones.
我不会在一天内编辑20.000个项目,所以我在考虑是否可以向已编辑的文件中添加一个属性并将其标记为true或类似的东西,因此第二天我可以继续向左那些。
If you binded your DataGridView with an Object of your design, you can use the selectedRow.DataBoundItem, to modidy its properties. 如果将DataGridView与设计的对象绑定,则可以使用selectedRow.DataBoundItem修改其属性。
Now on the question to what event to use, there are some, I would suggest, RowEnter (to enter EditMode), and RowLeave (to validate/Save). 现在,关于使用什么事件的问题,我建议使用RowEnter(进入EditMode)和RowLeave(验证/保存)。
For your last question, again, if you have your own object, you can manage a property to do so (like a dirty bit set on any setter called). 同样,对于最后一个问题,如果您有自己的对象,则可以管理一个属性来执行此操作(就像在任何调用的setter上设置脏位一样)。
Maybe based on FileInfo lastModified, or matching a name pattern... 也许基于FileInfo lastModified,或匹配名称模式...
Hope this helps! 希望这可以帮助! :)
:)
If you have 2 properties, and you use the CellEndEdit and Cell BeginEdit actions in the DataGrid. 如果您有2个属性,并且在DataGrid中使用CellEndEdit和Cell BeginEdit操作。 I'm assuming you have the full file path in the cell with the below example.
我假设您具有以下示例的单元格中的完整文件路径。 There are options on the Datagrid on how to start editing, but it should be enabled by default.
Datagrid上有关于如何开始编辑的选项,但是默认情况下应启用它。
public string FileOriginal { get; set; }
public string FileNew { get; set; }
private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
FileNew = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
File.Move(FileOriginal, FileNew);
}
private void dataGridView1_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
{
FileOriginal = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
}
This will Move(rename) your file to the new name. 这会将您的文件移动(重命名)为新名称。 taking the old path and moving it to the new edited path.
采用旧路径并将其移至新的编辑路径。 If you just have the file name in the field, I would make another column with the path, then combine them to the name.
如果您仅在该字段中输入文件名,那么我将在路径中添加另一列,然后将其组合为名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.