Skip to content

Instantly share code, notes, and snippets.

@tps2015gh
Last active August 2, 2023 10:40
Show Gist options
  • Save tps2015gh/bf382ecc0cdacbc1ebff02a53cfea14d to your computer and use it in GitHub Desktop.
Save tps2015gh/bf382ecc0cdacbc1ebff02a53cfea14d to your computer and use it in GitHub Desktop.
# Export file names to CSV File (recursive) , PowerShell Script ( Tested in Windows10 )
# Export file names to CSV File (recursive)
# Microsoft Power Shell script
# For Compare 2 Folder
# Run command in Console line by line
$s1 = dir -r ./Folder1/
$s1 |ForEach-Object {
>> $files += [pscustomobject]@{
>> Name = $_.Name
>> Length = $_.Length
>> }
>> }
$files | Export-Csv -Path "files1.csv" -Encoding UTF8
cat files1.csv
# Version2
# Export file names to CSV File (recursive)
# Microsoft Power Shell script
# For Compare 2 Folder
$rootpath = ".\SM-J610F_20190830123118\"
$s1 = dir -r $rootpath
$files = @()
$s1 |ForEach-Object {
$files += [pscustomobject]@{
Name = $_.Name
Length = $_.Length
Type = $_.GetType().Name
FullName = $_.FullName
}
}
$files
$files | Export-Csv -Path "files1.csv" -Encoding UTF8
# Version3 , with hash
# Export file names to CSV File (recursive)
# Microsoft Power Shell script
# For Compare 2 Folder
$rootpath = ".\SM-J610F_20190830123118\"
$s1 = dir -r $rootpath
$files = @()
$s1 |ForEach-Object {
$files += [pscustomobject]@{
Hash = (Get-FileHash ($_.FullName)).Hash
Name = $_.Name
Length = $_.Length
Type = $_.GetType().Name
FullName = $_.FullName
}
}
$files
$files | Export-Csv -Path "files1.csv" -Encoding UTF8
# Version4 , with hash
# Export file names to CSV File (recursive)
# Microsoft Power Shell script
# For Compare 2 Folder
$rootpath = ".\SM-J610F_20190830123118\"
$s1 = dir -r $rootpath
$files = @()
$s1 |ForEach-Object {
Echo "Compute file " ($_.FullName)
$files += [pscustomobject]@{
Hash = (Get-FileHash ($_.FullName)).Hash
Name = $_.Name
Length = $_.Length
Type = $_.GetType().Name
FullName = $_.FullName
}
}
$files
$files | Export-Csv -Path "files1.csv" -Encoding UTF8
# Version5 , with hash as MD5 (faster) , and display one line per file .
# Export file names to CSV File (recursive)
# Microsoft Power Shell script
# For Compare 2 Folder
#$rootpath = ".\SM-J610F_20190830123118\"
$rootpath = "."
$s1 = dir -r $rootpath
$files = @()
$s1 |ForEach-Object {
Echo ( "check MD5 ... {0} " -f ($_.FullName))
$files += [pscustomobject]@{
Hash = (Get-FileHash ($_.FullName) -Algorithm MD5 ).Hash
Name = $_.Name
Length = $_.Length
Type = $_.GetType().Name
FullName = $_.FullName
}
}
$files
$files | Export-Csv -Path "files1.csv" -Encoding UTF8
cat files1.csv
echo ""
#REF HASH
# https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/get-filehash?view=powershell-7.1
# Version6 , with hash as MD5 (faster) , and display one line per file . add ProgressBar, add display Size for current file
# Export file names to CSV File (recursive)
# Microsoft Power Shell script
# For Compare 2 Folder
#$rootpath = ".\SM-J610F_20190830123118\"
$rootpath = "."
$s1 = dir -r $rootpath
$files = @()
$i = 0
$s1len = $s1.Length
$s1 |ForEach-Object {
$i++
Echo ( "{0}/{1}. check MD5...({2}){3} " -f $i,$s1len,($_.Length),($_.FullName))
$files += [pscustomobject]@{
Hash = (Get-FileHash ($_.FullName) -Algorithm MD5 ).Hash
Name = $_.Name
Length = $_.Length
Type = $_.GetType().Name
FullName = $_.FullName
}
}
$files
$files | Export-Csv -Path "files1.csv" -Encoding UTF8
cat files1.csv
echo ""
#REF HASH
# https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/get-filehash?view=powershell-7.1
# Version7 , same as version6 + get directory full name
# Export file names to CSV File (recursive)
# Microsoft Power Shell script
# For Compare 2 Folder
# Source code update at https://gist.github.com/tps2015gh/bf382ecc0cdacbc1ebff02a53cfea14d#file-export_csv1_version7-ps1
#$rootpath = ".\SM-J610F_20190830123118\"
$rootpath = "."
$s1 = dir -r $rootpath
$files = @()
$i = 0
$s1len = $s1.Length
$s1 |ForEach-Object {
$i++
Echo ( "{0}/{1}. check MD5...({2}){3} " -f $i,$s1len,($_.Length),($_.FullName))
$files += [pscustomobject]@{
Hash = (Get-FileHash ($_.FullName) -Algorithm MD5 ).Hash
Name = $_.Name
Length = $_.Length
Type = $_.GetType().Name
DirectoryFullName = $_.Directory.FullName
FullName = $_.FullName
}
}
$files
$files | Export-Csv -Path "files1.csv" -Encoding UTF8
cat files1.csv
echo ""
#REF HASH
# https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/get-filehash?view=powershell-7.1
# Version8 , same as version7 with ...
# + Filename with with format year month day hour minute
# "file1-{0}.csv" -f (Get-Date -Format "yyyy-m-d-H-m")
# Export file names to CSV File (recursive)
# Microsoft Power Shell script
# For Compare 2 Folder
# Source code update at https://gist.github.com/tps2015gh/bf382ecc0cdacbc1ebff02a53cfea14d#file-export_csv1_version7-ps1
#$rootpath = ".\SM-J610F_20190830123118\"
$rootpath = "."
$s1 = dir -r $rootpath
$files = @()
$i = 0
$s1len = $s1.Length
$s1 |ForEach-Object {
$i++
Echo ( "{0}/{1}. check MD5...({2}){3} " -f $i,$s1len,($_.Length),($_.FullName))
$files += [pscustomobject]@{
Hash = (Get-FileHash ($_.FullName) -Algorithm MD5 ).Hash
Name = $_.Name
Length = $_.Length
Type = $_.GetType().Name
DirectoryFullName = $_.Directory.FullName
FullName = $_.FullName
}
}
#$files
$fnameout = "files1-{0}.csv" -f (Get-Date -Format "yyyy-MM-dd-HH-mm") # fixed 2
$files | Export-Csv -Path $fnameout -Encoding UTF8
$files | Export-Csv -Path "files1.csv" -Encoding UTF8
#cat files1.csv
#echo ""
ls files1*.csv
#REF HASH
# https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/get-filehash?view=powershell-7.1
# Version9 , same as version8 with ...
# + Field {hash}_{FileLength}
#
# Export file names to CSV File (recursive)
# Microsoft Power Shell script
# For Compare 2 Folder
# Source code update at https://gist.github.com/tps2015gh/bf382ecc0cdacbc1ebff02a53cfea14d#file-export_csv1_version7-ps1
#$rootpath = ".\SM-J610F_20190830123118\"
$rootpath = "."
$s1 = dir -r $rootpath
$files = @()
$i = 0
$s1len = $s1.Length
$s1 |ForEach-Object {
$i++
Echo ( "{0}/{1}. check MD5...({2}){3} " -f $i,$s1len,($_.Length),($_.FullName))
$hash = (Get-FileHash ($_.FullName) -Algorithm MD5 ).Hash
$files += [pscustomobject]@{
Hash = $hash
Name = $_.Name
Length = $_.Length
Type = $_.GetType().Name
Hash_Length = $hash + "_" + $_.Length
DirectoryFullName = $_.Directory.FullName
FullName = $_.FullName
}
}
#$files
$fnameout = "files1-{0}.csv" -f (Get-Date -Format "yyyy-MM-dd-HH-mm") # fixed 2
$files | Export-Csv -Path $fnameout -Encoding UTF8
$files | Export-Csv -Path "files1.csv" -Encoding UTF8
#cat files1.csv
#echo ""
ls files1*.csv
#REF HASH
# https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/get-filehash?view=powershell-7.1
# Version10 , same as version9 with ...
# add beep sound when finish , End with Ctrl-Z
# (1..10000) | foreach{ [console]::beep()}
#
# Export file names to CSV File (recursive)
# Microsoft Power Shell script
# For Compare 2 Folder
# Source code update at https://gist.github.com/tps2015gh/bf382ecc0cdacbc1ebff02a53cfea14d#file-export_csv1_version7-ps1
#$rootpath = ".\SM-J610F_20190830123118\"
$rootpath = "."
$s1 = dir -r $rootpath
$files = @()
$i = 0
$s1len = $s1.Length
$s1 |ForEach-Object {
$i++
Echo ( "{0}/{1}. check MD5...({2}){3} " -f $i,$s1len,($_.Length),($_.FullName))
$hash = (Get-FileHash ($_.FullName) -Algorithm MD5 ).Hash
$files += [pscustomobject]@{
Hash = $hash
Name = $_.Name
Length = $_.Length
Type = $_.GetType().Name
Hash_Length = $hash + "_" + $_.Length
DirectoryFullName = $_.Directory.FullName
FullName = $_.FullName
}
}
#$files
$fnameout = "files1-{0}.csv" -f (Get-Date -Format "yyyy-MM-dd-HH-mm") # fixed 2
$files | Export-Csv -Path $fnameout -Encoding UTF8
$files | Export-Csv -Path "files1.csv" -Encoding UTF8
#cat files1.csv
#echo ""
ls files1*.csv
#REF HASH
# https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/get-filehash?view=powershell-7.1
function beep1{
[console]::beep()
Start-Sleep -m 500
[console]::beep()
(1..10000) | foreach{
Echo "Press Ctrl-C to Exit / Stop Sound beep . "
Start-Sleep -m 5000
[console]::beep()
}
}
beep1
# end of script powershell
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment