How do I copy a .csv file from any specified folder to the working directory where matlab is run from?

I have been looking in your previous collections of Answers but have not found what I need for my situation. I will be creating an executable file of my script which can be run on any computure without the need of a Matlab license and will most likely reside on an aircraft where telemetry data collection occurs and multiple binary files are generated into multiple folders and subfolders which are named differently depending on flight and date. My script will convert these binary files into csv files but I don't know how to copy the csv files into the folder where my executable file will run from to read in data and perform data analysis. Can you please help with this question?

1 Kommentar

Why do you need to do this? Why not just provide the full filepath?
All MATLAB functions accept absolute/relative filepaths. Using the full filepath is much more efficient than duplicating your data files around the place or changing the current directory.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

copyfile(source, destination) where source and destination can be full path of the file.
pwd() will get you the current folder.

4 Kommentare

This will be an executable file generated from matlab script. I won't be able to specify source directory in the script and then create executable, because the source directory could be named differently than what is labeled in script. So I would need to have a command within the executable for user to select the folder and file to be copied and new location where copied file will reside.
"I won't be able to specify source directory in the script and then create executable, because the source directory could be named differently than what is labeled in script."
Sure. That is why I did not write that you should hard-code the directory (which is a very bad practice), I just wrote that it is not required to move files in order to process them with MATLAB. Inside the code you can simply use an absolute or relative filepath: the filepath could be generated or picked by the user...
"So I would need to have a command within the executable for user to select the folder and file to be copied and new location where copied file will reside":
Surely either way you will need to do something like this: how else do you intend to find where the files are, in order to copy them? If you can find where they are then why not just use that filepath when MATLAB processes them?
I have a folder which contains: .csv, .XLS , .xlsx files. Now I just want to copy .CSV files from that folder to a separate folder. How to do that using MATLAB
From the doc of copyfile()
File or folder to copy, specified as a character vector or string scalar. To copy multiple files or folders, use wildcards (*).
Or see uigetfile(), uiputfile()

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Kategorien

Mehr zu Startup and Shutdown finden Sie in Hilfe-Center und File Exchange

Produkte

Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by