我必須將整個目錄結構(成千上萬的目錄和文件)從Mac移動到PC,但現在在PC上出於某種原因,某些文件夾名稱上有一個字符值的二進制零結束(有一些在中間)。我需要清理它,因爲它會崩潰試圖讀取這些目錄的宏。
我已經嘗試了使用Replace函數(作爲遍歷目錄樹的更大程序的一部分)的vba-word宏中的以下代碼,但Replace函數似乎沒有捕獲到chr(0)。從字符串中刪除二進制零
Set current_folder = fso.GetFolder(source_folder.Path)
current_folder_name = current_folder.Name
cleaned_folder_name = Replace(current_folder_name, Chr(0), " ")
Selection.TypeText "Old directory name: " & current_folder_name
Selection.TypeParagraph
Selection.TypeText "New directory name: " & cleaned_folder_name
Selection.TypeParagraph
If current_folder_name <> cleaned_folder_name Then
current_folder.Name = cleaned_folder_name
End If
我也試過: cleaned_folder_name =替換(current_folder_name,CHR(0), 「」,1,-1,vbBinaryCompare)
如何,我可以得到替換功能,以取代二進制0在一個空白字符串中。
還是有人知道一個不同的方法來清理這些目錄和文件名將工作。
感謝, 哈利
首先,您是否希望將'Chr(0)'替換爲'Space'或'Nothing'?因爲你現在在你的'replace()'函數中有一個空格。 – Chrismas007
我可能會在我的程序中進行測試,如果Chr(0)在結束時沒有其他空間。我會嘗試你的解決方案並回復你。謝謝。 –