English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

2 answers

This command will not work,
ren dbo*.sql *.sql

using the global wildcard * in the rename command simply tells DOS to rename a dbo*.sql files to *.sql files and in this case since the * is all inclusive for everything before the dot, then the dbo files are just renamed as the same filename.

What you need is something better. You can do this from a single DOS commandline (start-run-cmd) using the 'for' command like this,

for /f "tokens=1,2 delims=." %i in ('dir *.sql /b') do ren %i.%j.sql %j.sql

(make sure the command is all on one line)

Notes:
delims=.
>>using the dot as a delimiter

tokens=1,2
>>getting the first two 'tokens' based on the delimiter, in this case %i will be the first token ('dbo') and %j will be the second token ('xxx')

for /f %i in ('dir *.sql /b')
>>using the output of the 'dir *.sql /b' command as the input for the rename command

ren %i.%j.sql %j.sql
>>rename dbo.xxx.sql xxx.sql

============
My test. Created 10 dbo.xxx.sql files
============
Directory of C:\temp

03/27/2007 09:14a

.
03/27/2007 09:14a ..
03/27/2007 09:13a dbo.0.sql
03/27/2007 09:13a dbo.1.sql
03/27/2007 09:13a dbo.2.sql
03/27/2007 09:13a dbo.3.sql
03/27/2007 09:13a dbo.4.sql
03/27/2007 09:13a dbo.5.sql
03/27/2007 09:13a dbo.6.sql
03/27/2007 09:13a dbo.7.sql
03/27/2007 09:13a dbo.8.sql
03/27/2007 09:13a dbo.9.sql
03/27/2007 09:14a hold
10 File(s) 10 bytes
3 Dir(s) 28,134,109,184 bytes free

============
ran my little script .. BUT .. added an "@echo" before the 'ren' command which only echoes the commands to the screen without actually performing them. This allows me to see how the command will look when it runs as a double check.

for /f "tokens=1,2 delims=." %i in ('dir *.sql /b') do @echo ren %i.%j.sql %j.sql
(all on one line again)

=========
This is what is put on the screen
=========
ren dbo.0.sql 0.sql
ren dbo.1.sql 1.sql
ren dbo.2.sql 2.sql
ren dbo.3.sql 3.sql
ren dbo.4.sql 4.sql
ren dbo.5.sql 5.sql
ren dbo.6.sql 6.sql
ren dbo.7.sql 7.sql
ren dbo.8.sql 8.sql
ren dbo.9.sql 9.sql

>> that looks just right, so removing the @echo and running
for /f "tokens=1,2 delims=." %i in ('dir *.sql /b') do ren %i.%j.sql %j.sql
(all on one line)

=========
the command runs
==========
C:\temp>ren dbo.0.sql 0.sql
C:\temp>ren dbo.1.sql 1.sql
C:\temp>ren dbo.2.sql 2.sql
C:\temp>ren dbo.3.sql 3.sql
C:\temp>ren dbo.4.sql 4.sql
C:\temp>ren dbo.5.sql 5.sql
C:\temp>ren dbo.6.sql 6.sql
C:\temp>ren dbo.7.sql 7.sql
C:\temp>ren dbo.8.sql 8.sql
C:\temp>ren dbo.9.sql 9.sql

===========
and now a 'dir' looks like this
===========
Directory of C:\temp

03/27/2007 09:29a .
03/27/2007 09:29a ..
03/27/2007 09:13a 0.sql
03/27/2007 09:13a 1.sql
03/27/2007 09:13a 2.sql
03/27/2007 09:13a 3.sql
03/27/2007 09:13a 4.sql
03/27/2007 09:13a 5.sql
03/27/2007 09:13a 6.sql
03/27/2007 09:13a 7.sql
03/27/2007 09:13a 8.sql
03/27/2007 09:13a 9.sql
03/27/2007 09:14a hold
10 File(s) 10 bytes
3 Dir(s) 28,134,109,184 bytes free

====================
As a further test, I made sure it would work with two and three digits and leading 0's
====================
Directory of C:\temp

03/27/2007 09:33a .
03/27/2007 09:33a ..
03/27/2007 09:13a dbo.0.sql
03/27/2007 09:13a dbo.00.sql
03/27/2007 09:13a dbo.000.sql
03/27/2007 09:13a dbo.001.sql
03/27/2007 09:13a dbo.002.sql
03/27/2007 09:13a dbo.003.sql
03/27/2007 09:13a dbo.004.sql
03/27/2007 09:13a dbo.005.sql
03/27/2007 09:13a dbo.006.sql
03/27/2007 09:13a dbo.007.sql
03/27/2007 09:13a dbo.008.sql
03/27/2007 09:13a dbo.009.sql
03/27/2007 09:13a dbo.01.sql
03/27/2007 09:13a dbo.02.sql
03/27/2007 09:13a dbo.03.sql
03/27/2007 09:13a dbo.04.sql
03/27/2007 09:13a dbo.05.sql
03/27/2007 09:13a dbo.06.sql
03/27/2007 09:13a dbo.07.sql
03/27/2007 09:13a dbo.08.sql
03/27/2007 09:13a dbo.09.sql
03/27/2007 09:13a dbo.1.sql
03/27/2007 09:13a dbo.2.sql
03/27/2007 09:13a dbo.3.sql
03/27/2007 09:13a dbo.4.sql
03/27/2007 09:13a dbo.5.sql
03/27/2007 09:13a dbo.6.sql
03/27/2007 09:13a dbo.7.sql
03/27/2007 09:13a dbo.8.sql
03/27/2007 09:13a dbo.9.sql
03/27/2007 09:14a hold
30 File(s) 30 bytes
3 Dir(s) 28,133,994,496 bytes free

===========
run,
for /f "tokens=1,2 delims=." %i in ('dir *.sql /b') do ren %i.%j.sql %j.sql
(all on one line)
================================
C:\temp>dir
Volume in drive C has no label.
Volume Serial Number is E09D-F253

Directory of C:\temp

03/27/2007 09:33a .
03/27/2007 09:33a ..
03/27/2007 09:13a 0.sql
03/27/2007 09:13a 00.sql
03/27/2007 09:13a 000.sql
03/27/2007 09:13a 001.sql
03/27/2007 09:13a 002.sql
03/27/2007 09:13a 003.sql
03/27/2007 09:13a 004.sql
03/27/2007 09:13a 005.sql
03/27/2007 09:13a 006.sql
03/27/2007 09:13a 007.sql
03/27/2007 09:13a 008.sql
03/27/2007 09:13a 009.sql
03/27/2007 09:13a 01.sql
03/27/2007 09:13a 02.sql
03/27/2007 09:13a 03.sql
03/27/2007 09:13a 04.sql
03/27/2007 09:13a 05.sql
03/27/2007 09:13a 06.sql
03/27/2007 09:13a 07.sql
03/27/2007 09:13a 08.sql
03/27/2007 09:13a 09.sql
03/27/2007 09:13a 1.sql
03/27/2007 09:13a 2.sql
03/27/2007 09:13a 3.sql
03/27/2007 09:13a 4.sql
03/27/2007 09:13a 5.sql
03/27/2007 09:13a 6.sql
03/27/2007 09:13a 7.sql
03/27/2007 09:13a 8.sql
03/27/2007 09:13a 9.sql
03/27/2007 09:14a hold
30 File(s) 30 bytes
3 Dir(s) 28,134,023,168 bytes free

=====================
Perfect
=====================

That should do it.

2007-03-27 02:38:26 · answer #1 · answered by Kevin 7 · 3 0

ren dbo*.sql *.sql


take a back up :-)

2007-03-26 02:16:47 · answer #2 · answered by srihari_reddy_s 6 · 0 2

fedest.com, questions and answers