Using powershell to batch rename some files

Now that powershell comes pre-installed on all copies of Win7, we can use it to perform day-to-day tasks.
Here is the first tip: to batch rename a bunch of files, such that the first 3 characters are deleted from the filename, issue the command:
dir | foreach -process {mv $_.Name $_.Name.Substring(3)}

Update: I will be updating this post with more snippets as I come across them

1. Here is how to create a graphics object in powershell, and draw a bunch of lines on it.
$bmp = new-object System.Drawing.Bitmap(264, 264)
$graphics = [System.Drawing.Graphics]::FromImage($bmp)
for($i=1; $i -lt 9; $i+=1) { $graphics.DrawLine($pen, 33*$i, 0, 33*$i, 264); }

2. Here is how to set the current directory so that .NET objects know it
[Environment]::CurrentDirectory = $pwd

3. Here is how to download a file
$c = new-object System.Net.WebClient
$c.DownloadFile( url, filename )

4. Concatenate a bunch of files together
cat misc*.txt | Out-File allmisc.txt -Encoding ASCII
cat misc1.txt,misc2.txt,misc3.txt > allmisc.txt

5. Delete all (possibly hidden) subfolders that are called CVS
dir -Force -Include *CVS -R . | % { $_.FullName } | % {rmdir -Recurse -Force $_}


Popular posts from this blog

Dark Fonts and Colors for light theme in VS 11

Laptop Surprises: Lenovo Yoga Slim 7i

Setting coordinates in Phaser where the body and the sprite are offset from each other