我有大约20.000个文件我必须重命名,遗憾的是我无法自动化,因为我必须检查每个文件的内容并添加相应的名称。
但是我打算建立一个能够帮助我的胜利形式解决方案。
计划是:
问题:
还有一件事。我不会在一天内编辑20.000个项目,所以我想我是否可以为已编辑的文件添加属性并将其标记为true,或类似的东西,所以第二天我可以继续左边的那些。
答案 0 :(得分:0)
If you binded your DataGridView with an Object of your design, you can use the selectedRow.DataBoundItem, to modidy its properties.
Now on the question to what event to use, there are some, I would suggest, RowEnter (to enter EditMode), and RowLeave (to validate/Save).
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).
Maybe based on FileInfo lastModified, or matching a name pattern...
Hope this helps! :)
答案 1 :(得分:0)
If you have 2 properties, and you use the CellEndEdit and Cell BeginEdit actions in the DataGrid. 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.
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.