Tips that make life of a software engineer easier. Well, not exactly. Some posts are open questions that I haven't found an answer ... yet
Friday, March 07, 2014
Mutli-line String Literal in Java
Eclipse Preferences: Java > Editor > Typing, check "Escape text when pasting into a string literal". Once turned on, it automatically add "\r\n" when I am pasting multi-line string into a string literal. Very nice.
Wednesday, March 05, 2014
Windows PowerShell Script to Delete Old Files
Just starting to dab into PowerShell script after it has been in the wild for 8 years. Turns out to be surprisingly good. First you have a nice editor (PowerShell ISE), second is the vast amount of cmdlets that make coding go fast.
Here is a script to delete old files that are 30 days or older. It used to take at least 40 lines of VBS to achieve.
Before you get too excited, a few things to be aware of:
Here is a script to delete old files that are 30 days or older. It used to take at least 40 lines of VBS to achieve.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$nDays = 30 | |
$path = "C:\temp" | |
$threshold = (Get-Date).AddDays(-$nDays) | |
Get-ChildItem -Path $path -Recurse | Where-Object { | |
-not $_.PSIsContainer -and $_.LastWriteTime -lt $threshold | |
} | Remove-Item -Force |
Before you get too excited, a few things to be aware of:
- Availability of PowerShell: WindowsXP may not have it, and Windows 7 may only have it up to version 2. So, if you found some exciting cmdlets, chances are they are not available on your OS by default
- Executing a PowerShell file takes extra effort. It's forbidden by default. So you have to do either of the following:
- Open PowerShell, and execute this command:
- Or, when running a file use this command line (notice full path to the ps1 file has to be provided here):
PowerShell.exe -ExecutionPolicy ByPass c:\scripts\myScript.ps1
Subscribe to:
Posts (Atom)