Duplicate file name when using textscan

1 view (last 30 days)
Oliver Goldsmith
Oliver Goldsmith on 13 Mar 2017
Answered: dpb on 13 Mar 2017
Hey, I've got a for loop set up reading files ending .txt it runs fine and does everything i want however it also pops up with duplicates of the file names with "._" before them and no data heres a picture of what i mean.
From row 10 is the data i want however rows 1-9 are just duplicate filenames and empty cells i don't want. Any reason for this? cheers Ollie

Answers (1)

dpb
dpb on 13 Mar 2017
There's always a reason, yes... :)
However, we can't tell what that reason might be for certain but the crystal seems fairly clear this morning and it says a likely possibility is that the file exists and is empty owing to a previous coding error have created the file but never wrote anything into it. A likely cause of having created the file would be having coded a loop trying to automate the creation of an output file based on the input file base name but with an extension and the logic in that loop, while not failing to run, created a name of the above pattern which looks like the original name with the two characters "._" having been prepended.
This could easily have occurred if there were an error in the input in building the intended filename that ended up with an empty string that was supposed to have been tacked onto the front of the name.
The solution I would guess would be to simply
delete '._Af*.txt'
to clean up the directory listing of the empty files. Of course, do some double-checking to make sure the above doesn't inadvertently include a file you do want first; use the pattern in dir and inspect the results first or similar.

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!