在Windows 7中根据文件路径更改文件名和移动文件

时间:2013-06-20 19:19:12

标签: windows file command-line scripting

我有一堆分布在文件夹和子文件夹中的图像文件。我想要做的是将它们全部移动到一个文件夹,并根据它们之前的路径重命名它们。

为了说明,文件src / a / b / file1.png

应该成为src / a_b_file1.png

在Linux中可能有一种聪明的方法可以做到这一点,但我目前使用的是Windows 7计算机。

任何提示都不错,gui或命令行工具或某些脚本无关紧要。感谢名单。

3 个答案:

答案 0 :(得分:3)

试试这个:然后检查记事本中的renfile.bat,看看它是否适合你。 如果需要,可以添加更多文件类型。

@echo off
echo.@echo off> renfile.bat
for /f "delims=" %%a in ('dir *.jpg *.png *.gif /b /s /a-d ') do call :next "%%a"
echo renfile.bat created
pause
goto :eof
:next
set "var=%~1"
call set "var=%%var:%cd%=%%"
set "var=%var:\=_%"
>>renfile.bat echo ren "%~1" "%var:~1%"

和另一个批处理文件,一旦重命名就移动所有文件:

@echo off
md "c:\target folder\"
for /f "delims=" %%a in ('dir *.jpg *.png *.gif /b /s /a-d ') do (
move "%%a" "c:\target folder\"
)

答案 1 :(得分:2)

你可以使用advanced renamer,该工具提供了大量的重命名标签,例如。

[DirName:X] Inserts the last directory name. eg. "c:\windows\notepad.exe" will give "windows" as result.

If X is a numeric value that value will be used to select a folder name in the sequence from the right part of the path.

[Dirname:3] for "c:\programs\games\new\mine sweeper\highscore\file.txt" will yield "new"
[Dirname:4] for "c:\programs\games\new\mine sweeper\highscore\file.txt" will yield "games"

答案 2 :(得分:1)

我最终使用了this程序。乍看之下易于安装且易于使用。