Rename all files in a folder using batch

て烟熏妆下的殇ゞ 提交于 2019-12-20 07:37:09

问题


I would like to create a batch file to rename all the files with extension ".log" in a folder to append with today's date.

For example :

App.log will be appended to App.log06112010 where date is 06112010.

Please suggest


回答1:


forfiles /m *.log /c "cmd /c ren @file @file06112010"



回答2:


#!/usr/bin/ksh
export TODAYSDATE=`date "+%m%d%Y"`

umask 000
for filename in $1
do
  if [ ! -f $1 ]; then
    echo "$filename doesn't exist!"
  else
    if [ -d $1 ]; then
      echo "Skipping directory $filename..."
    else
      mv $filename $filename$TODAYSDATE
    fi
  fi
done

Usage: move.sh "*.log"



来源:https://stackoverflow.com/questions/3026007/rename-all-files-in-a-folder-using-batch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!