Saturday, April 6, 2013

Rename multiple files at once

rename with wildcards only works on files, to rename a directory, use move;
C:\Temp>echo "test" > olle12  
C:\Temp>mkdir olle13
C:\Temp>rename "*12" 12
C:\Temp>rename "*13" 13
The syntax of the command is incorrect.
C:\Temp>move "*13" 13
C:\Temp\olle13
    1 dir(s) moved.
C:\Temp>dir
 Directory of C:\Temp

2013-04-03  10:01                 9 12
2013-04-03  10:01    <DIR>          13 
 
Rename also works on folders properly:

ren "the god of high school 12" 12
.. or you use a for loop:
for /d %i in (*12) do ren "%~i" 12
 

Trim leading slashes using only a batch file

CMD (replace %m with %%m for running this in a batch file):

for /f "delims=\ tokens=*" %m in ('net view ^| findstr /r "^\\\\"') do (
  echo %m
) >out.txt
 
 
PowerShell:

net view | select-string '^\\\\' -AllMatches `
  | % { $_ -replace '^\\\\', '' } >out.txt