-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathProgram.cs
More file actions
51 lines (41 loc) · 1.55 KB
/
Copy pathProgram.cs
File metadata and controls
51 lines (41 loc) · 1.55 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace FileNameChanger
{
internal class Program
{
private static void Main(string[] args)
{
string diretoryPath = @"D:\Rovia\20130207\AirLogs\";
List<string> files = Directory.GetFiles(diretoryPath).ToList();
int i = 0;
foreach (var file in files)
{
string filedata = File.ReadAllText(file);
filedata = filedata.Replace("<?xml version=\"1.0\" encoding=\"utf-16\"?>", "").Trim();
if (!string.IsNullOrWhiteSpace(filedata) && filedata != "\0")
{
string newName = filedata.Substring(0, filedata.IndexOf(" "));
Console.WriteLine("Newfile name");
newName = newName.Replace('<', ' ').Trim();
string checkName = newName + ".xml";
i++;
File.Move(file, diretoryPath + i + "." + newName + ".xml");
Console.WriteLine("Renamed file{0}",newName);
//if (File.Exists(diretoryPath + checkName))
//{
// i++;
// File.Move(file, diretoryPath+newName + i + ".xml");
//}
//else
//{
// File.Move(file,diretoryPath+newName + ".xml");
//}
}
}
}
}
}