- 1 year ago
Compare filename only for files 2 folder using FC
The FC
command in Windows is used to compare two files or sets of files to see if they are the same or different. However, the FC
command compares the content of the files, not just the filenames.
If you want to compare only the filenames of files in two folders without considering their content, you can use a simple script or command in PowerShell or Command Prompt. Here's an example using PowerShell:
powershell$folder1 = "C:\path\to\folder1"
$folder2 = "C:\path\to\folder2"
# Get the filenames in each folder
$files1 = Get-ChildItem -Path $folder1 | ForEach-Object { $_.Name }
$files2 = Get-ChildItem -Path $folder2 | ForEach-Object { $_.Name }
# Compare the filenames
Compare-Object $files1 $files2 -IncludeEqual
This PowerShell script gets the list of filenames in each folder using the Get-ChildItem
cmdlet and then compares the filenames using Compare-Object
. The -IncludeEqual
parameter ensures that files with the same name in both folders are included in the output.
If you prefer to use Command Prompt, you can use the dir
command to list the filenames and then use the fc
command to compare the lists:
cmddir /b "C:\path\to\folder1" > folder1_files.txt
dir /b "C:\path\to\folder2" > folder2_files.txt
fc folder1_files.txt folder2_files.txt
The above commands will save the list of filenames from each folder into separate text files (folder1_files.txt
and folder2_files.txt
) and then use the fc
command to compare the contents of these text files, which effectively compares the filenames.
Keep in mind that these approaches only compare the filenames, not the file content. If you want to compare both filenames and file content, the FC
command or other file comparison tools are more appropriate.