Compare two text files from MATLAB Command Window using FC Windows 10 file comparison command

조회 수: 18 (최근 30일)
Currently, I am using visdiff to compare two text files. I do not want the GUI popup, nor do I want to get the full visdiff output. I would like to use the Windows 10 FC command instead. In MATLAB Command Window, I can compare two text files successfully if I manually type in the two filenames:
>> !fc "ABC-BASELINE.txt" "ABC.txt"
Comparing files 0114 After power up initial re-pair.mat-bits-BASELINE.txt and 0114 AFTER POWER UP INITIAL RE-PAIR.MAT-BITS.TXT
FC: no differences encountered
I would like to do this using variables that are set to the two filenames. Something like:
>> !fc fn_baseline_str fn_str
I have not figured out how to define the two fn strings, and then how to run the ! command.
If the file does not exist, I would like to rename the file, fn_str, to fn_baseline_str.
Thank you in advance.
~Paul

채택된 답변

Steven Lord
Steven Lord 2020년 9월 28일
Use the system function instead of the ! (bang) operator.

추가 답변 (1개)

Paul Hoffrichter
Paul Hoffrichter 2020년 9월 28일
To handle spaces in filenames, I did the following:
>> fn_baseline_str =
'A BC BASELINE.txt'
>> fn_str =
'A BC.txt'
>> fc = ['fc "' fn_baseline_str '" "' fn_str '"']
fc =
'fc "A BC BASELINE.txt" "A BC.txt"'
>>
>> system( fc )
Comparing files A BC BASELINE.txt and A BC.TXT
FC: no differences encountered
ans =
0

카테고리

Help CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by