필터 지우기
필터 지우기

Can't copy files using the DOS() command in MATLAB

조회 수: 1 (최근 30일)
Hugo
Hugo 2022년 5월 9일
댓글: Jan 2022년 5월 9일
I am trying to copy an external file a.txt to a new file, named b.txt, by using the following code:
command='COPY C:\text\a.txt C:\text\b.txt '
dos(command)
However, this code does not create the expected file b.txt. I already setup all the folders of the C: drive to be owned by my account (administrator), but that does not seem to work. Any suggestions on these would be appreciated.
Thank you,
  댓글 수: 3
dpb
dpb 2022년 5월 9일
Use system instead of dos altho that's probably not the real problem.
Use
[status,cmdout]=system(cmd)
to see what actually happened. Quite possibly the file and/or folder don't exist.
Jan
Jan 2022년 5월 9일
@Hugo: Do you get an error message? E.g. using dpb's suggestion should show one.
Using copyfile as suggested by Fangjun Jiang is smart also.
What happens if you run this in a command windows of the operating system?
"I already setup all the folders of the C: drive to be owned by my account (administrator), but that does not seem to work." - Really? This would be a really bad idea. On one hand working as admin has severe drawbacks: you can e.g. destroy Matlab toolbox files, which is impossible without admin privilegs. On the other hand many folders on C:\Windows should not even have Admin access for security reasons. Only the the System account should be able to access these folders.
Finally working on the root level of the C disk is a bad programming habit also. This was ugly in Windos 3.1 booted from a disk already and is not smarter in Windows 11.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by