LoginSignup
0
0

More than 5 years have passed since last update.

[PowerShell] Try to write a simple PowerShell script

Last updated at Posted at 2016-07-15

A sample

If you want to do something like processing a lot of files at Windows. Maybe powershell script is a alternative choice.

Here I wrote a simple powershell script.

foreach($file in (ls *.cpp)) {
    write-host $file
    $source = "$file"
    $target = $source.Replace(".cpp", ".cc")
    // Do some processing...
}

foreach .. in .. like the for in other languages.

ls *.cpp will list all the files in the current directory with suffix .cpp. Alternatively you can do something like this to count the number of files of the result ls.

(ls *.cpp).Count

write-host would like output some log in the console.

Replace can replace the string at first parameter with the second parameter.

Remove file

Remove-Item $path

Check if file exist

Test-Path $path
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0