Author: Java2blog
01 JanuaryPowerShell – Count Files in Folders
Count Files in Folders in PowerShell We can use the Measure-Object cmdlet in different ways to meet our project requirements. However, before moving forward, it is essential to know how many files and folders we have on the different paths that we will use in this article. E:\Test contains three folders (FolderA, FolderB and FolderC) […]
31 DecemberCheck if Object has Property in PowerShell
Using the -match Parameter Use the -match parameter to check if an object has a property in PowerShell. $greetings = "Hi" $name = "Java2blog" $props = $([ordered]@{ greetings=$greetings name=$name }) $results = New-Object psobject -Property $props [bool] ($results.PSobject.Properties.name -match "greetings") True Here, we used the -match parameter to check if the given object, which is […]
28 DecemberCreate Empty File in PowerShell
Using New-Item Cmdlet Use the New-Item cmdlet to create an empty .txt file in PowerShell. New-Item -Path "E:\NewFolder" -Name "File1.txt" -ItemType File Directory: E:\ Mode LastWriteTime Length Name ---- ------------- ------ ---- -a---- 12/27/2022 10:51 PM 0 EmptyFile.txt We used the New-Item cmdlet with -Path, -Name, and -ItemType parameters to create an empty .txt file […]
27 DecemberRun PowerShell as Another User
Using the runas Command The runas command in PowerShell launches programs using credentials different from the current user. It provides users with limited privileges to execute commands or access resources available only to more privileged accounts. The command’s syntax is runas /user:UserName ProgramName where UserName is an account with permission and ProgramName is the name […]
27 DecemberCreate Array of All NaN Values in Python
Using numpy.empty() Function To create an array of all NaN values in Python: Use numpy.empty() to get an array of the given shape. Assign numpy.nan to every array element using the assignment operator (=). import numpy array = numpy.empty((3,3)) array[:] = numpy.nan print(array) [[nan nan nan] [nan nan nan] [nan nan nan]] We used numpy.empty() […]
27 DecemberCall Function from Another Function in Python
1. Introduction In Python, calling a function from another function is a common practice that enhances modularity and reusability. We’ll explore various ways to do this, with complete examples and detailed explanations. Our focus will be on understanding how these methods work, their use cases. As an example, let’s look at a scenario where we […]
27 DecemberReturn Boolean from Function in JavaScript
Using the Boolean() Function To get a Boolean from a function in JavaScript: Create a function which returns a Boolean value. Use the Boolean() function to get a Boolean value from the function created in the previous step. function func(){ return Boolean(10>5); } console.log(func()); true We used the Boolean(), a built-in function in JavaScript, to […]
27 December[Fixed] NameError Name ‘unicode’ is Not Defined in Python
Use str() Method To resolve the NameError: name 'unicode' is not defined, replace the occurrence of unicode() with str(). This issue occurs because unicode() was renamed to str() in Python 3. my_string = str('This program resolves \u0061 "NameError" in PythØn!') print(my_string) This program resolves a "NameError" in PythØn! Unicode is a computing industry standard that […]
26 DecemberConcatenate String in PowerShell
Using Operators To concatenate string in PowerShell: Declare and initialize variables which contain string-type values. Use +, -f, and -join operators to concatenate values of all variables we created in the first step. $greetings = "Hi" $first_name = "Mehvish" $last_name = "Ashiq" $plus_without_separator = $greetings + $first_name + $last_name $plus_with_separator = $greetings +" "+ $first_name […]