开发者

Windows Rename Sub Folders Command

Firstly not sure if this is the right place for a question like this, but here goes.

I have a folder structure of

parentfolder/folder1/10-31-2010/file1.pdf

        /folder2/10-31-2010/filey.pdf
        /folder3/10-31-2010/filex.pdf
        /foldern/10-31-2010/filen.pdf

I need to rename the date to 2010-10-31.

This is a once off thing that will only every happen on one the one parentfolder. But well over 10000 folders to apply this to.

From googling I see there are many file renaming tools, but I am not allowed to install any software on the server, nor am I allowe开发者_开发百科d to move the folders off the server.

Any help would be appreciated.


If you want to do that from a .bat file, you can use the DOS ren command.

ren C:\folder2\10-31-2010 C:\folder2\2010-10-31

This answer has an script in it that might help you.


Your best bet is using shell scripts.

!/bin/bash
FOLDER=/path/to/*/
FILES=$(find $FOLDER -name '*-*-*')
for f in $FILES
do
    o=${f%/*}
    p=${f##*/}
    mv $f $o/$(echo $p | awk -F"-" '{ print $3"-"$1"-"$2 }')
done

That still uses mv and awk, hope your server have both on it.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜