中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-12 03:17
47,811 topics / 349,897 posts / today 0 new / 48,256 members
DOS批处理 & 脚本技术(批处理室) » How to batch rename files
Printable Version  1,095 / 13
Floor1 chinesechrist Posted 2010-08-03 22:07
新手上路 Posts 7 Credits 5
I took photos with a digital camera, and all the photo names are SAM_00**.JPG. How can I make a batch file to remove the SAM_ from all the photo names and turn them into 00**.JPG
Floor2 chinesechrist Posted 2010-08-03 22:34
新手上路 Posts 7 Credits 5
Has everyone gone to sleep?
Floor3 lovelymorning Posted 2010-08-03 23:42
初级用户 Posts 72 Credits 131


Give it a try, not guaranteed to work...
Floor4 chinesechrist Posted 2010-08-04 00:11
新手上路 Posts 7 Credits 5
It doesn't work. After running it, it created a file called SAM_, and the batch file window shows "A duplicate file exists, or the file cannot be found"
Floor5 WANKOILZ Posted 2010-08-04 00:35
初级用户 Posts 89 Credits 198 From 重庆
Floor6 chinesechrist Posted 2010-08-04 07:45
新手上路 Posts 7 Credits 5
OK.
set "str=%%i"
ren "%%i" "!str:SAM_=!"
)
Can you explain this piece of code in detail? I've been learning batch files for a while, but I mainly can't figure out FOR and SET
Floor7 freeants001 Posted 2010-08-04 08:31
中级用户 Posts 244 Credits 330 From 湖北
Originally posted by chinesechrist at 2010-8-3 22:07:
I took photos with a digital camera, and all the photo names are SAM_00**.JPG. How can I make a batch file to remove the SAM_ from all the photo names and turn them into 00**.JPG


This is very simple


Tested and works on Windows XP sp3
Floor8 freeants001 Posted 2010-08-04 08:40
中级用户 Posts 244 Credits 330 From 湖北
Found that the poster above still didn't pass either , it actually created files whose names begin with half-width spaces.
Floor9 WANKOILZ Posted 2010-08-04 09:19
初级用户 Posts 89 Credits 198 From 重庆
Ignore this post!

[ Last edited by WANKOILZ on 2010-8-4 at 09:32 ]
Floor10 chinesechrist Posted 2010-08-04 17:59
新手上路 Posts 7 Credits 5
ren sam_*.jpg " *.jpg"
Tested and works on Windows XP sp3
---------but the filename has four extra spaces
Floor11 freeants001 Posted 2010-08-04 20:40
中级用户 Posts 244 Credits 330 From 湖北
Originally posted by chinesechrist at 2010-8-4 17:59:
ren sam_*.jpg " *.jpg"
Tested and works on Windows XP sp3
---------but the filename has four extra spaces


Mm, yes, reply #8 already pointed that out. Inspired by this thread, I wrote a small tool for renaming files. I've temporarily named it xren.exe, using Jscript regex.

   Usage: 
      xren file type filename-matching regex  replacement filename

For example: 
1. Replace all half-width spaces in the names of all jpg files in the current directory with _





2. Add www.cn-dos.net to the beginning of the filenames of all TXT files in the current directory





3. Remove the website address from all filenames of the form Story_www.example.com.txt



...

That's enough examples for now. By the way, xren jpg "/^SAM_/" can solve the OP's problem ;)

[ Last edited by freeants001 on 2010-8-4 at 21:56 ]
Floor12 chinesechrist Posted 2010-08-05 06:55
新手上路 Posts 7 Credits 5
Thanks for your XREN, it's very good software
Floor13 chinesechrist Posted 2010-08-05 07:02
新手上路 Posts 7 Credits 5
I still don't understand the specific usage rules, and xren /? doesn't show any help information,
Floor14 freeants001 Posted 2010-08-05 08:37
中级用户 Posts 244 Credits 330 From 湖北
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023