SharePoint 파일 가져 오기에 대해 내 프로그램 목록에 "잘못된 문자"가있는 파일의 이름을 바꾸려고합니다. 내가 말한 불법 문자는 ~ # % & * {}/\ | : <>? - ""RegEx 및 재귀를 사용하여 FileNames 변경
드라이브를 통해 반복적으로 파일 이름 목록을 수집 한 다음 정규식을 통해 목록에서 파일 이름을 선택하고 실제 파일 이름에서 유효하지 않은 문자를 대체하려고합니다. 그들 자신.
아무도이 작업을 수행하는 방법을 알고 있습니까? 지금까지 나는이있다 : (i가이 물건에 대한 완전한 n00b 해요, 기억하시기 바랍니다)
class Program
{
static void Main(string[] args)
{
string[] files = Directory.GetFiles(@"C:\Documents and Settings\bob.smith\Desktop\~Test Folder for [SharePoint] %testing", "*.*", SearchOption.AllDirectories);
foreach (string file in files)
{
Console.Write(file + "\r\n");
}
Console.WriteLine("Press any key to continue...");
Console.ReadKey(true);
string pattern = " *[\\~#%&*{}/:<>?|\"-]+ *";
string replacement = " ";
Regex regEx = new Regex(pattern);
string[] fileDrive = Directory.GetFiles(@"C:\Documents and Settings\bob.smith\Desktop\~Test Folder for [SharePoint] %testing", "*.*", SearchOption.AllDirectories);
StreamWriter sw = new StreamWriter(@"C:\Documents and Settings\bob.smith\Desktop\~Test Folder for [SharePoint] %testing\File_Renames.txt");
foreach(string fileNames in fileDrive)
{
string sanitized = regEx.Replace(fileNames, replacement);
sw.Write(sanitized + "\r\n");
}
sw.Close();
}
}
을 내가 알아 내기 위해 필요한 반복적으로, 이러한 잘못된 문자를 검색 실제 파일 이름에 장착하는 방법입니다 그 자체. 아무도 아이디어가 없나요?
나는 그가 단지 그들을 찢어 버리는 것을 의미한다고 생각한다. – slf
정규 표현식은 당신이 원하는 것을한다? – slf