How do I convert a file name into a string

조회 수: 89 (최근 30일)
Matthew Isaman
Matthew Isaman 2019년 1월 28일
답변: Matthew Isaman 2019년 1월 28일
How do I convert a file name into a string?
I have a file named MyFile_12-25-2018.xls
Im using the command copyfile to bring the file into my local folder in matlab but no sure how to now convert the file named I just copied into a string. I am really after just the date . I want to create it into a string and then truncate it down to just 12-25-2018 and then name it to a variable. Like date.
  댓글 수: 2
Walter Roberson
Walter Roberson 2019년 1월 28일
What copyfile command are you using ?
Stephen23
Stephen23 2019년 1월 28일
Matthew Isaman's "Answer" moved here:
copyfile('C:\Documents\MyFile_12-25-2018.xls')
The previous comment is not valid since I am not calling out the file directly. I'm using
copyfile('C:\Dcouments\')
This will copyfile the .xls file into my matlab local folder

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

채택된 답변

Omer Yasin Birey
Omer Yasin Birey 2019년 1월 28일
Filename = 'MyFile_12-25-2018.xls'
name = strsplit(Filename, '_');
name = string(name{1,2});
  댓글 수: 1
Walter Roberson
Walter Roberson 2019년 1월 28일
And before that use
dinfo = dir('*.xls')
filenames = {dinfo.name}
to get a cell array of file names.

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

추가 답변 (1개)

Matthew Isaman
Matthew Isaman 2019년 1월 28일
Great! Thanks, it works now!!

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by