简体   繁体   中英

Change file name and move files based on file path in Windows 7

I have a bunch of image files distributed in folders and sub folders. What I would like to do is move them all to one one folder and rename them them based on their previous path.

To illustrate, the file src/a/b/file1.png

should become src/a_b_file1.png

There is probably a smart way to do this in Linux, but I am currently on a Windows 7 machine.

Any tips would be nice, gui or commandline tools or some script, doesn't matter. Thanx.

Try this: and then examine renfile.bat in notepad to see if it is right for you. Add more filetypes if you need them.

@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%"

and another batch file to move all the files once they are renamed:

@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\"
)

you can use advanced renamer , the tool offers a great number of renaming tags, eg.

[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"

I ended up using this program. Easy to install and easier to use that it appears at first glance.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM