Schlagwortarchiv für: Methods


PowerShell supports various operations on files. Prior to the operation, it is recommended to check the existence of the file. To do so, PowerShell offers various cmdlets and methods. This post analyzes and provides a detailed usage of the cmdlets/methods to check the existence of the file. To check whether a file exists or not we will use multiple methods to determine the existence of the file in the specific location. We will explain the four methods to check the existence of the file which will enable you to check the existence of the file in PowerShell

Method 1: Use the Test-path cmdlet to check the existence of the file

Test-Path cmdlet looks for the path and returns a Boolean value. Test-Path will return true if the path is correct, and if the path is not found then it returns false. The syntax followed by the Test-Path cmdlet is provided below:

Syntax

> Test-Path -Path <FilePath> <parameters>

In the above syntax

  • <FilePath>: it refers to the location of the file
  • Path: used to specify a path
  • <Parameters>: defines the parameters for additional functionality

Example
This program will check the existence of the file using the Test-Path method. It is recommended to provide the absolute path of the file as we did here.

> TestPath Path «C:/Docs/PS.txt» PathType Leaf

The output is True which means the file exists. It is observed that the “Test-Path” cmdlet has returned true which states that the file exists.

Method 2: Use Get-Item to check the existence of the file

The Get-Item cmdlet of PowerShell is used to get items in the specified location. The syntax of the Get-Item cmdlet is provided below:

Syntax

The syntax elements are described as:

  • Get-Item: uses the wildcard character (*) to get everything of the specified item.
  • <FilePath>: it refers to the location of the file

Example
This program will also check the existence of the file by using the Get-Item method.

> Get-Item C:/Docs/PS.txt

The Get-Item has printed the details of the file which states that the file exists at the specified path.

Method 3: Use the Get-ChildItem cmdlet to check the existence of the file

This method gets the item as well as child items from more than one specified path. If the file exists, it will show the file details and throw an error in case the file is not present.

The syntax of the Get-ChildItem cmdlet is provided below:

Syntax

> Get-ChildItem -Path <FilePath>

The syntax elements are explained a:

  • Get-ChildItem: gets the content of a folder or registry key
  • Path: used to specify a path
  • <FilePath>: it refers to the location of the file

Example
This program will check the existence of the file using the Get-Childitem method.

> Get-Childitem -Path C:/Docs/PS.txt

The output shows the file details which means the file exists.

Method 4: Use the System.IO.file method to check the existence of the file

The [System.IO.File]::Exists(File) method also checks the existence of the file. This method provides the result in a Boolean(true/false) value. The following syntax is followed to apply this method:

Syntax

> [System.IO.File]::Exists(<FilePath>)

The above syntax will be used to check the existence of a file by specifying the path of the file in the <FilePath> parameter.

Example
Here, the [System.IO.File]::Exists method is exercised to check the file is present at the given path or not.

> [System.IO.File]::Exists(«C:/Docs/PS.txt»)

The output is True which means the file exists.

Congrats! You have learned to check the existence of the file in PowerShell

Conclusion

PowerShell cmdlets such as Get-ChildItem, Get-Item, and Test-Path can be used to check the existence of the file. Moreover, PowerShell also provides a .NET supported method “[System.IO.file]::Exists” to check the existence of a file. In this post, we have demonstrated various possible methods to check the existence of the file. The usage of these three cmdlets as well as the method is explained with the help of examples.



Source link


When you buy a new Chromebook, you definitely change the look of your desktop. Changing the desktop wallpaper is one of the tasks that everyone wants to do because it gives your laptop a whole new look. Now if you have any queries in your mind about how to change the Chromebook’s wallpaper, check out this article.

How to change the wallpaper on Chromebook

The three ways to select and change a wallpaper on Chromebook:

  1. Applying pre-installed wallpaper
  2. Applying a custom wallpaper
  3. Applying the same wallpaper on multiple Chromebooks

1: Applying a pre-installed wallpaper

This is the easiest and fastest method to use a pre-downloaded wallpaper on your Chromebook. You can find these wallpapers through these steps:

Step 1: Right-click on the desktop and select the Set wallpaper option:

Step 2: Select an image of your choice to set as wallpaper. You can also set your wallpaper to change daily by enabling the Daily Refresh option:

2: Applying a custom wallpaper

If the picture you are going to use as wallpaper is downloaded to your system, then it can be easily used as wallpaper. When the picture is downloaded, follow this method to change the Chromebook’s wallpaper.

Step 1: Click the launcher option on the left corner of the screen and click My Files:

Step 2: Select the folder with your image:

Step 3: Right-click on the image and select set wallpaper:

Note: Keep in mind that the low-quality images won’t look great, so always download the high-quality wallpapers.

3: Applying same wallpaper on multiple Chromebooks

You can sync wallpaper across multiple Chromebook by following the steps given below:

Step 1: Click on the display time at the left corner of the screen:

Step 2: Select Settings:

Step 3: Click on Sync and Google services in Accounts:

Step 4: Click on Manage what you sync:

Step 5: To use the same wallpaper on every device you have to turn on Sync everything:

Conclusion

Changing the wallpaper on your Chromebook is very easy as it enables you to change the look of your desktop. There are always some default wallpapers present in the Chromebook, you can apply them to get a new look. You can also get the same look on multiple Chromebooks by applying the same wallpaper on other Chromebooks. If you ever face any issue in changing the wallpaper on your Chromebook, don’t worry and simply abide by the above-mentioned steps to change the wallpaper.



Source link


JavaScript has many useful methods that can work easily with the arrays. Some of these are map(), pop(), filter() and push(). JavaScript also has some() und every() methods. The main difference between the mentioned methods is that the some() method is used for finding at least one or more than one value in the array according to the passed condition, whereas the every() method checks whether all elements of an array are satisfying the given condition or not.

This post will practically demonstrate the difference between every() und some() method using appropriate examples. So, let’s start!

every() Method in JavaScript

every() method in JavaScript is used to check whether all elements of an array are satisfying the given condition or not. If even a single value does not satisfy the element the output will be false otherwise it will return true. It is opposed to some() method.

Syntax

The universal syntax of every() method is:

array.every(callback(currentvalue, index, arr), thisArg)

In JavaScript, every() method returns a Boolean value (true/false) as output.

Parameters

  • callback” is a function that will test the condition.
  • currentvalue” shows the current element of the array and it is required.
  • index” represents the index of the current element of the array and it is optional.
  • arr” is an optional parameter and demonstrates the array where the current element belongs.
  • thisArg” is an optional parameter and its value is used while executing the callback function.

Now, let’s check out an example for understanding the usage of every() method in JavaScript.

How to use every() method in JavaScript

In this section, we will demonstrate the usage of every() method in JavaScript. For this purpose, consider the following array of integer values:

let arr = [1, 2, 3, 4, 5, 6, 7, 8 ];

We will now use every() method to check whether the given array has a positive value or not:

arr.every((value)=> {

return (value > 0);

});

The given array that we passed to the every() method has positive values so the condition is satisfied and the output will be true otherwise it will return false as an output if the given condition is not satisfied:

some() Method in JavaScript

The some() method is used with arrays in JavaScript. It accepts the Boolean expression (true/false) and is used to check if at least one or more than one element in the array satisfies the passed condition or not.

Syntax

The universal syntax of some() method is:

array.some(function(value, index, arr), this)

In JavaScript, some() method also returns a Boolean value (true/false) as output.

Parameters

  • function” executes for every element of the array.
  • value” shows the current element of the array and it is required.
  • index” refers to the index of the current array element and is an optional parameter.
  • arr” refers to the array where the current element belongs and it is also an optional parameter.

These parameters are optional and the boolean expression that it accepts is as follows:

The “element” denotes the current element in the array that is being checked. The “boolean” returns the Boolean value either true or false.

How to use some() method in JavaScript

Now, consider the following array of integer values:

let arr =[ 2, 3, 4, 5, 6, 7, 8];

Next, we will check if there is at least or more than one even element is in the array by using the some() method:

arr.some((value) => { return (value%2 == 0); });

The some() method will find at least or more than one even element from a given array and the output will be true because the given list has four even elements that are divisible by 2:

We have disscussed the difference between some() and every() method, their syntax and example.

Conclusion

In JavaScript, main difference between the every() und some() methods is that the some() method is used for finding at least one or more than one value in the array according to the passed condition, whereas, the every() method check whether all elements of an array are satisfying the given condition or not. This post illustrates the difference between every() und some() methods in JavaScript, its syntax with examples.



Source link


Set Objects in JavaScript are very much similar to the arrays the major difference between these two is that the set objects can’t hold the duplicate values however arrays can. In JavaScript, the set objects allow us to store only unique values in them. These unique values can be of any type like primitive data types(int, strings, etc), object references, complex object/data types such as object, arrays, literals, etc. In JavaScript several set object methods can be used to achieve different functionalities, for example, add(), delete(), forEach(), etc.

In this article, we will cover the below listed aspects of set object methods in JavaScript:

So, let’s begin!

How to use new Set() to create a set in JavaScript

To work with any of the Set object methods, firstly, we have to create a set. To do so, we can use the “new Set()” constructor.

Example

The below given piece of code will explain how to create a Set in JavaScript using the “new Set()” constructor:

<script>
let employeeNames = new Set();

console.log(employeeNames);
</script>

The above code will create an empty set as shown in the following output:

The output shows that an empty Set is created, now we can perform any functionality on that set using different set object methods such as append elements, remove elements, etc.

How to use add() method to add elements in a set

JavaScript provides a method named add() that is used to append the elements in a set.

Example

Now, we will extend the above example a little bit more to add/append the elements to the Set:

employeeNames.add(«Steve»);
employeeNames.add(«Michael»);
employeeNames.add(«Smith»);
employeeNames.add(«Paul»);
employeeNames.add(«Ambrose»);
console.log(employeeNames);

In this example, we added five elements in the set named “employeeNames” using the add() method. Afterward, we utilized the console.log() method to print all the elements stored in the “employeeNames” set on the browser’s console:

The output verifies the working of the add() method.

How to use delete() method to remove elements from a set

In JavaScript, the delete() method can be used to remove some specific elements from the set object.

Example

Let’s suppose we want to remove “Smith”, and “Paul” from the set “employeeNames”. To do so, we can utilize the delete() method:

employeeNames.delete(«Smith»);
employeeNames.delete(«Paul»);
console.log(employeeNames);

The above code block will generate the following output:

The above snippet shows that the delete() method has removed “Smith” and “Paul” from the Set successfully.

How to use clear() method to delete all elements from a set

In JavaScript, the clear() method can be used to remove all the elements of a set object.

Example

In this example, we will utilize the clear() method to delete all the items from the set “employeeNames”:

employeeNames.clear();
console.log(employeeNames);

The above code snippet will produce the following results:

The output shows the Set’s size equal to zero; it authenticates the working of the clear() method.

How to check the existence of some specific value in a set using has() method

In JavaScript, the has() method can be used to check whether a specific element exists in the set or not.

Example

In this example, we will check the existence of two elements i.e. “Smith”, and “Bryn” using the has() method:

console.log(employeeNames.has(«Smith»));
console.log(employeeNames.has(«bryn»));

The piece of code will return true if the specified value exists in the set and it will return false if the specified value doesn’t exist in the targeted set:

The output shows that the has() method returns true for the element “smith” as it exists in the set while “Bryn” doesn’t exist in the targeted set therefore the has() method returns false for it.

How to find the size of a set

In JavaScript, the size property can be used to check the size/length of some specific set.

Example

In this example we will utilize the size property to check the size of the set “employeeNames”:

Following will be the corresponding output for the above-given code:

The output shows the appropriate size of the specified set i.e “employeeNames” set.

Conclusion

In JavaScript, the set objects allow us to store only unique values in them. These unique values can be of any type like primitive data types(int, strings, etc), object references, complex object/data types such as objects, arrays, literals, etc. In JavaScript, there is a wide range of set object methods that can be used to perform different functionalities. For example, Add(), delete(), and clear(), methods are used to append and remove elements, the has() method is used to check the existence of an element in a specific set, etc. This write-up explained the working of various set object methods with the help of suitable examples.



Source link