File Exchange

image thumbnail

Making a new .txt or .xlsx file automatically

version 1.0.0.1 (2.24 KB) by Joseph Wilson
This function auto generates a new file for data collection to prevent the overwriting of data without the need for manual file name changes

26 Downloads

Updated 03 Jul 2019

View License

This function auto generates a new file for data collection
The baseFileName can be changed to whatever you would like your new .txt
file name to be. Originally it is 'data'.

This function returns 'data1.txt' to your main script which can then be opened and written in using fopen and fprintf provided data1.txt does not already exist.
If data#.txt exists this function generates data(#+n).txt until a nonexisting file name is found. i.e. data20.txt if data1.txt-data19.txt already exists in the current folder.

This is useful for continuous data collection without having to rename the .txt file manually prior to each run to avoid overwriting data.
This function can also generate new .xlsx .xls .csv files by changing the value of extension_ to the desired extension

Cite As

Joseph Wilson (2021). Making a new .txt or .xlsx file automatically (https://www.mathworks.com/matlabcentral/fileexchange/72021-making-a-new-txt-or-xlsx-file-automatically), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2019a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Acknowledgements

Inspired by: Next Available Filename, Avoid file overwrite

Community Treasure Hunt

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

Start Hunting!