How to delete a .csv in my directory

조회 수: 11 (최근 30일)
new2matlab
new2matlab 2020년 2월 19일
답변: Guillaume 2020년 2월 19일
I have a csv that is a subset of the original data (part of my script is to create it), and I am looking for a way to delete the file at the begining of my script each time since a new one is always created. Is there a way to do such a thing?
It isn't in my main directory, but is in a subfolder from it.

채택된 답변

Guillaume
Guillaume 2020년 2월 19일
delete subfolder\filename.csv %relative path to current directory
But you shouldn't rely on the main directory and instead use full paths everywhere in your script. This way the data can be located anywhere independently on where the code is.
datafolder = 'C:\somewhere\somefolder'
%importing some data with whichever function you normally use. Using readmatrix here for demo:
filename = 'somefile.csv';
data = readmatrix(fullfile(datafolder, filename));
%deleting a particular file in the data folder:
delete(fullfile(datafolder, 'somefile.txt'));
%saving an image
imwrite(img, fullfile(datafolder, 'fancyimage.png'))
%etc.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Audio and Video Data에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by