Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a list of files generated from SSMS in XP like this:

dbo.mysproc1.StoredProcedure.sql
dbo.mysproc2.StoredProcedure.sql
dbo.mySproc3.StoredProcedure.sql
... you get the drift

I want to rename them to:

proc.dbo.mysproc1.sql
proc.dbo.mysproc2.sql
proc.dbo.mySproc3.sql
... you get the drift

I'm open to powershell, plain old batch, or whatever. If you can do it with a regex that would be fascinating, but whatever works there too. I want the ends, not the means, yeah? Just not sure what command to use. I do not, however, want to download a tool to do this. Native XP SP3 please.

This is a one-off job, not something to be scripted, if that matters. But I may repeat it in the future, so scriptable is not a bad thing.

share|improve this question

migrated from stackoverflow.com Dec 14 '10 at 21:34

This question came from our site for professional and enthusiast programmers.

up vote 4 down vote accepted

Put this in a batch file that's in the same directory and run:

for /f "delims=. tokens=1,2,3,4" %%A IN ('dir /b *.sql') DO RENAME %%A.%%B.%%C.%%D proc.%%A.%%B.%%D

That'll split the filename up by the "." character using the %%A through %%D variables, and then rename using the rearranged filename.

share|improve this answer
1  
holy crap that's awesome. – jcolebrand Dec 14 '10 at 21:23
1  
Ha thanks. As long as the file names are pretty consistent this'll do the trick. – Ryan Dec 14 '10 at 21:27

A crude PS script for kicks:

gci | foreach { $f = $_; $split = $f.Name.Split("."); $n = [string]::join(".", "proc", $split[0], $split[1], "sql")); ren $f $n;}
share|improve this answer
    
oooh, what does GCI do? "Get-ChildItem" nice – jcolebrand Dec 14 '10 at 21:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .