문제
지정된 파일 트리를 거쳐 모든 자식 파일을 이름 바꾸는 스크립트 (Perl, Python 또는 Batch가 괜찮을 것입니다)를 찾고 있습니다.
예를 들어, Folder1>File1.anytype
becomes Folder1>Folder1File1.anytype
.
감사
해결책
배치 파일을 언급하는데, 이는 아마도 Windows에 있다는 것을 의미합니다 (.BAT 파일을 참조한다고 가정합니다). UNIX 시스템을 사용하는 경우 다음에 촬영하십시오.
find . -mindepth 2 -type f -exec sh -c "mv {} \`dirname {}\`/\`dirname {} | sed 's/^\.//' | sed 's/\///g'\`\`basename {}\`" \;
또는이 Python 3 프로그램은 트릭을 수행 할 수 있습니다 (Windows에서도 작동해야합니다 ...) :
#!/usr/bin/env python3.0
import os
import sys
def raise_error(e):
raise e
def full_split(path):
head, tail = os.path.split(path)
if head:
return full_split(head) + [tail]
return [tail]
def main(args):
if len(args) != 1:
print("Please specify one target directory", file=sys.stderr)
sys.exit(1)
os.chdir(args[0])
for dirpath, _, filenames in os.walk('.', onerror=raise_error):
for f in filenames:
old = os.path.join(dirpath, f)
new = os.path.join(dirpath, ''.join(full_split(dirpath[2:]) + [f]))
os.rename(old, new)
if __name__ == '__main__':
main(sys.argv[1:])
이전 디렉토리 레이아웃 :
.: Abc Def ./Abc: Foo2.bar Foo.bar ./Def: Baz2.quux Baz.quux Ghi ./Def/Ghi: Bar2.foo Bar.foo
이후 디렉토리 레이아웃 :
.: Abc Def ./Abc: AbcFoo2.bar AbcFoo.bar ./Def: DefBaz2.quux DefBaz.quux Ghi ./Def/Ghi: DefGhiBar2.foo DefGhiBar.foo
다른 팁
최고의 배치 르네마는입니다 MMV.
그리고 또한 참조하십시오 대량 이름 변경 방법은 무엇입니까?
당신은 배치 이름을 시도 할 수 있습니다 : http://batchrename.foryoursoft.com/
명령 줄에서 루프 용 중첩을 사용하여 이러한 이름을 달성 할 수 있습니다.
for /D %d in (*) do for %f in ("%d\*.*") do move "%f" "%d\%~nd%~nf"
위의 명령을 배치 스크립트에 넣으려면 각 % 문자를 한 번 반복하십시오.
for /D %%d in (*) do for %%f in ("%%d\*.*") do move "%%f" "%%d\%%~nd%%~nf"
위의 명령이 무엇을하는지 이해하려면 문의하십시오 FOR /?
명령 줄에서.
나는 요즘 배치가 너무 무기한 것 같은 느낌이 든다. 나는 어떻게 든 방망이 지혜를 보존해야한다 ... :-)
농담 :-) ..하지만 명령이 작동합니다. 시도해 보았습니다.
제휴하지 않습니다 StackOverflow