フィルターのクリア

How to delete a .csv in my directory

27 ビュー (過去 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 Center および File ExchangeFile Operations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by