Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
Hugo
Hugo am 9 Mai 2022
Kommentiert: Jan am 9 Mai 2022
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 Kommentare
dpb
dpb am 9 Mai 2022
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 am 9 Mai 2022
@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.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange

Produkte


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by