Apply functions or m to a folder(multiple files)
3 views (last 30 days)
Show older comments
I got a folder with say 100 file with the random names of haah.xls,kiij.xls etc. I have a function(say QQQ.m) I want to apply to them which would eventually convert the file to csv. I want to do two things: 1)How to apply QQQ.m to the folder 2)I want to rename the converted file according to its original name.Now the function does this, convert haah.xls to 1.csv. I want it to automatically rename to haah.csv Thanks in advance!!!
1 Comment
Jan
on 14 Sep 2011
If you post yozur code, it would be easy to explain which single line has to be changed. Without seeing your code, we could only reply a theoretical description of what muist be changed.
So please show us, what you have done already.
Answers (1)
Jan
on 14 Sep 2011
- Use DIR to get a list of files.
- Then use a FOR loop to get one file after the other.
- Read the file. It is impossible to get a more specific instruction, because you did not explain the format of the files.
- Write the converted file using the same file name, but the different file extension. This is smarter than writing "1.csv" and using MOVEFILE to rename the file afterwards.
If you include more details in your question, a more specific answer is possible.
[EDITED]: You must have the original file name to read the file. So why do you use "1.csv" and not something like:
[fPath, fName] = fileparts(OriginalFileName);
newfileName = fullfile(fPath, [fName, '.csv']);
cell2csv(newFileName, W);
2 Comments
See Also
Categories
Find more on File Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!