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

2 次查看(过去 30 天)
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