For the dataset:
C:\DOCS> dir
Volume in drive C has no label.
Volume Serial Number is xxxx-xxxx
Directory of C:\DOCS
05/29/2007 11:12 AM .
05/29/2007 11:12 AM ..
06/07/2007 11:45 AM Business
06/07/2007 09:33 PM My Downloads
05/29/2007 11:12 AM 111 ping-subnet.txt
04/27/2000 04:36 PM 766 UserGuide.ico
08/05/2002 11:21 AM 3,877,898 userguide.pdf
Applying the /b switch provides:C:\DOCS> dir /b
Business
My Downloads
ping-subnet.txt
UserGuide.ico
userguide.pdf
Providing the following command at the command prompt [remember in a batch file the for statement replaceable variables must use double percent signs, e.g., %%g ]:C:\DOCS> for /f "usebackq tokens=1,2 delims=." %g in (`dir /b .\*.*`) do @echo %g %h
Will provide you with the following output:Business
My Downloads
ping-subnet txt
UserGuide ico
userguide pdf
Notice that the "." is missing. That is because the delims modifier has parsed the line using "." as the delimiter for tokens. On caveat for using this method is that a file name like:ping-subnet.txt.cmd
will break this. Not a hard break, but it will cause unexpected behavior. The output for that filename would be:
ping-subnet txt
As you can see, since we only specified that tokens one and two be parsed the third was dropped. So in conclusion, you would probably need a line like this:
for /f "usebackq tokens=1,2 delims=." %g in (`dir /b .\*.*`) do @ren %g.%h %g.sql
Additionally, when using the above command, make sure that you are in the directory where the files to be renamed are located. The rename [ren] command could be substituted with the move command.