How to delete a .csv in my directory

21 vues (au cours des 30 derniers jours)
new2matlab
new2matlab le 19 Fév 2020
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.

Réponse acceptée

Guillaume
Guillaume le 19 Fév 2020
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.

Plus de réponses (0)

Catégories

En savoir plus sur File Operations dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by