Documentation

This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

라이선스가 부여된 사용자만 번역 문서를 볼 수 있습니다. 번역 문서를 보려면 로그인하십시오.

copyfile

Copy file or folder

Syntax

copyfile('source','destination')
copyfile('source','destination','f')
status = copyfile(___)
[status,message] = copyfile(___)
[status,message,messageid] = copyfile(___)

Description

copyfile('source','destination') copies the file or folder named source to the file or folder destination. The values for source and destination are specified as character vectors. Use full path names or path names relative to the current folder. To copy multiple files or folders, use one or more wildcard characters (*) after the last file separator in source. You cannot use a wildcard character in destination.

copyfile('source','destination','f') copies source to destination, even when destination is not writable. The state of the read-write attribute for destination does not change. You can use f with any syntax for copyfile.

status = copyfile(___) reports the outcome as a logical scalar, status. The value is 1 for success and 0 for failure.

[status,message] = copyfile(___) returns any warning or error message as a character vector to message. When copyfile succeeds, message is empty.

[status,message,messageid] = copyfile(___) returns any warning or error identifier as a character vector to messageId. When copyfile succeeds, messageId is empty.

Examples

collapse all

Copy myFun.m from the current folder to d:/work/Projects/.

copyfile('myFun.m','d:/work/Projects/')

Copy myFun.m in the current folder, assigning it the name myFun2.m.

copyfile('myFun.m','myFun2.m')

Copy files and subfolders whose names begin with my, from the Projects subfolder within the current folder to the folder newProjects, which is at the same level as the current folder:

copyfile('Projects/my*','../newProjects/')

Copy the contents of the Projects subfolder within the current folder to the I:/work/newProjects folder, where newProjects does not exist.

copyfile('Projects','I:/work/newProjects')

Copy the contents of myFun.m from the current folder to d:/work/restricted/myFun2.m, where myFun2.m is read-only.

[status,message,messageId] = copyfile('myFun.m', ...
'd:/work/restricted/myFun2.m','f')
status =
     1

message =
     ''

messageId =
     ''

A status of 1 and an empty message and messageId confirms the copy was successful.

More About

collapse all

Tips

  • The timestamp for destination is the same as the timestamp for source.

  • When source is a folder, destination must be a folder.

    • When source is a folder and destination does not exist, copyfile creates destination and copies the contents of source into destination.

    • When source is a folder and destination is an existing folder, copyfile copies the contents of source into destination.

    • When source is multiple files and destination does not exist, copyfile creates destination.

Introduced before R2006a

Was this topic helpful?