开发者

Rename all files in a folder using batch

开发者 https://www.devze.com 2023-01-03 00:12 出处:网络
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.

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


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


#!/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"

0

精彩评论

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