2014-12-16 4 views
0

이름에서 일부 텍스트를 제거하여 단일 파일의 이름을 바꾸려고합니다.일부 텍스트 바꾸기/바꾸기로 단일 파일 이름 바꾸기

PS> rni .\SomeFileName.todo.asc { $_ -replace ".todo" } 

Rename-Item : Cannot evaluate parameter 'NewName' because its argument is specified 
as a script block and there is no input. A script block cannot be evaluated without 
input. 

나는 또한 다음과 같은 접근 방식을 시도하며 오류이기도 : 다음 오류가 나에게 발생

PS> SomeFileName.todo.asc | rni -newname { $_ -replace ".todo" } 

SomeFileName.todo.asc : The term 'SomeFileName.todo.asc' is not recognized as the name 
of a cmdlet, function, script file, or operable program. Check the spelling of the 
name, or if a path was included, verify that the path is correct and try again. 

답변

1

당신은 여러 줄이 작업을 수행 할 수 있습니다

$filename = ".\SomeFileName.todo.asc"; 
$newname = $filename -replace "\.todo", ""; 
rni $filename $newname; 

에게 당신을 또한 한 줄로이 작업을 수행 할 수 있습니다.

gi SomeFileName.todo.asc | rni -newname { $_ -replace "\.todo" } 

이 두 가지 결과는 다음과 같습니다.

SomeFileName.asc 
+0

감사합니다. 이후에 단일 라인 솔루션을 찾아서 추가했습니다. –

+0

좋은 찾으십시오. 한 줄짜리 솔루션을 찾으려고했는데 그 이유는 당신이 디렉토리의 루프를 가지고 그것을 할 수 있다는 것을 알기 때문입니다. – Robbert

+1

'-match'와'-replace'는 match 패턴에 regex를 사용합니다. 'SomeFileName-todo.asc'라고 불리는 파일을 엉망이 없도록 기간을 벗어나야합니다.'$ _ -replace '\ .todo ''와 같습니다. –