Wednesday, 30 December 2015

How to Recursively List All Files and Subfolders Using PowerShell

Here is a simple recursive function to display all file-names with full path in folders and sub-folders. You can only run this command in Windows PowerShell available since the release of Windows 7.
$folder = "c:\\MyDirectory\\"

 Function Upload($item) {
    foreach ($i in Get-ChildItem $item)
    {
        Try
        {
            if((Get-Item $i.FullName) -is [System.IO.DirectoryInfo]){
                  Write-Output $i.FullName
                  Upload($i.FullName)

            }else{
              Write-Output $i.FullName
            }
        }catch{
            Write-Output $i.FullName
        }
    }   
}
 
Upload($folder)

Copy the above code and save in .ps1 file.

December 30, 2015

How to Batch Rename All Files in a Folder Using PowerShell

If you are not interested in external programs to renames all files in a folder to lowercase, there is a simple command for you.

- Open Command Prompt (cmd.exe) in Windows
- Go to the directory and run the following command

for /f "Tokens=*" %f in ('dir /l/b/a-d') do (rename "%f" "%f")

Note: This is not a recursive function, it will rename files to lowercase only on the directory where you will run the command.

December 30, 2015