Can't copy files using the DOS() command in MATLAB
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
dpb
le 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
le 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.
Réponses (0)
Voir également
Catégories
En savoir plus sur Startup and Shutdown dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!