开发者

Attaching the foldername to all the all files in that particular folder

There are 100s of folders in a directory and inside each of the folder there is a (filename).ini file.

All I need to do is to attach the parent folder name to the .ini file so that it becomes (foldername)-(filename).txt file. 开发者_JAVA技巧

Is there a batch script which could do this? i am new to batch files. So, any help is greatly appreciated!


setlocal enabledelayedexpansion

for /R %%a in (*.ini) do (
  set relativepath=%%a
  set relativepath=!relativepath:%cd%\=!
  set newname=!relativepath:\=-!
  set newname=!newname:.ini=.txt!
  ren !relativepath! !newname!
)

endlocal


This works for any folder and any folder structure.

@echo off
setlocal enabledelayedexpansion
for /R %%a in (*.ini) do (
  set foldername=%%~pa
  set foldername=!foldername:\=_!
  echo ren "%%~fa" "(!foldername!)-%%~na.txt"
)

For all the ini files in the current directory: extract the path from the filename, using the ~p modifier; change all backslash occurrencies to underscores, using the := modifier; finally rename the original ini file.

After testing, remove the ECHO

See HELP FOR and HELP SET for more information.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜