This is very usefull code for me. This code I was needed when my solution was migrated from VS2008 to VS2010. In VS2008 we are using the naming convention for our function and SP's like this : dbo.<function_name>.sql and dbo.<SP_name>.sql but in VS2010 we are using <function_name>.function.sql and <SP_name>.proc.sql. I want to commit som 100+ files from VS2008 t0 VS2010 so I uses below code which changes the file names.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main()
{
//Path where all the files are stored.
string[] filePaths = Directory.GetFiles(@"E:\test\");
for(int i = 0;i<filePaths.Length;i++)
{
string oldFileName=filePaths[i].ToString();
//This will remove the prefix and suffix name of the file
string fileName = oldFileName.Substring(0,oldFileName.LastIndexOf("."));
//This will add the suffix name of the file
string NewFileName=@"E:\test\"+(fileName.Substring(fileName.LastIndexOf(".")+1))+".function.sql";
//It creates the copy of the file
File.Copy(oldFileName, NewFileName);
//It deletes the old file
File.Delete(oldFileName);
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main()
{
//Path where all the files are stored.
string[] filePaths = Directory.GetFiles(@"E:\test\");
for(int i = 0;i<filePaths.Length;i++)
{
string oldFileName=filePaths[i].ToString();
//This will remove the prefix and suffix name of the file
string fileName = oldFileName.Substring(0,oldFileName.LastIndexOf("."));
//This will add the suffix name of the file
string NewFileName=@"E:\test\"+(fileName.Substring(fileName.LastIndexOf(".")+1))+".function.sql";
//It creates the copy of the file
File.Copy(oldFileName, NewFileName);
//It deletes the old file
File.Delete(oldFileName);
}
}
}
}
No comments:
Post a Comment