2014-09-18 7 views
0

여러 번 복사해야하는 Excel 파일 (103 개)을 텍스트 파일을 기반으로 이름을 바꿔야합니다. 예를 들어, 63100_attachment.xls는 복사 할 파일이고 새 파일은 다음과 같은 이름을 갖습니다 (이미 별도의 Excel 파일에 나열되어 있으며이 파일을 텍스트 파일에 저장할 수도 있습니다).파일 복사 및 이름 바꾸기 일괄 파일

63126_attachment.xls 
63283_attachment.xls 
63284_attachment.xls 
63285_attachment.xls 
63299_attachment.xls 
63300_attachment.xls 
63301_attachment.xls 
63326_attachment.xls 
63327_attachment.xls 
63328_attachment.xls 
63348_attachment.xls 
63349_attachment.xls 
63350_attachment.xls 
63351_attachment.xls 
63352_attachment.xls 
63439_attachment.xls 
63440_attachment.xls 
63441_attachment.xls... 

'_attachment'문자열 앞의 숫자는 증분이 아니며 실제로 목록을 기반으로해야합니다. 누구나 도움을 주시면 대단히 감사하겠습니다.

답변

0
for /f "delims=" %%a in (listfile.txt) do copy "63100_attachment.xls" "%%a" 

즉, 배치 파일의 줄입니다. 프롬프트에서 %%a에서 %a까지 줄입니다. 메시지를 표시하지 않으려면 >nul을 추가하십시오. copyECHO copy으로 변경하여 제안 된 동작을 실행하지 말고 확인하십시오.

+0

고마워, 마구! 완벽하게 일했습니다 :) – dunkelme

+0

질문 옆에있는 큰 열린 진드기를 클릭하면 해결 된 것으로 표시되고 점수가 부여됩니다. – Magoo

0
Sub batch_rename() 

On Error GoTo errHndl 

Dim fso As New FileSystemObject 
Dim fld As Folder 
Dim sourcePath As String, destPath As String 
Dim sourceFile As String, destFile As String, sourceExtension As String 
Dim rng As Range, cell As Range, row As Range 

sourcePath = "\path to old files\" 
destPath = "\path to new files\" 
sourceFile = "" 
destFile = "" 
Set fso = CreateObject("Scripting.FileSystemObject") 
Set rng = ActiveSheet.Range("A2", "B10") 

For Each row In rng.Rows 
    sourceExtension = Split(Trim(row.Cells(, 2)), ".")(1) 
    sourceFile = sourcePath + Trim(row.Cells(, 2)) 
    destFile = destPath + Trim(row.Cells(, 1)) + "." + sourceExtension 
    fso.CopyFile sourceFile, destFile, False 
Next row 

MsgBox "Yay! Operation was successful.", vbOKOnly + vbInformation, "Done" 
Exit Sub 


errHndl: 
    MsgBox "Error happened while working on: " + vbCrLf + _ 
     sourceFile + vbCrLf + vbCrLf + "Error " + _ 
     Str(Err.Number) + ": " + Err.Description, vbCritical + vbOKOnly, "Error" 

End Sub 
관련 문제