2

I tried to move multiple files into a folder, but there was a mistake in my matlab code that I didn't create the folder. Now all the files were moved to a single file which cannot be opened or edited. How to recover these files?

Example of the mistake:

a=strcat('C:\Users\foldername'); % name and directory of the folder
fname=a; 
% mkdir(fname); % so this command wasn't executed...        
movefile('file1',fname);
movefile('file2',fname);

So now file1 and file2 were merged in file 'fname', instead of in the folder named 'fname'. How to get file1 and file2 back?

Thanks in advance!

open0121
  • 105
  • 2
  • 15
  • it depends what kind of files they were, if they were codes only, or some sort of codes, then add or change the extension of fname to txt and open it with a text editor such as word, notepad, notepad++ etc and salvage the initial files – Ibo Sep 12 '17 at 00:09
  • Thanks, but they were not all codes. I tried to add extension of fname to txt and open in notepad. It gave me only unreadable codes. – open0121 Sep 12 '17 at 07:55

1 Answers1

0

Unfortunately, the odds may be stacked against you getting back any of the files, except for the last one. The reason why is because movefile doesn't append to an existing destination file, it overwrites it. The following will give you back your last file (by simply renaming fname):

movefile(fname, 'file2');

If you're lucky, your operating system will have options for you to restore previous versions of your files/folders. Your best bet may be to check and see if the folder containing your original files has any previous versions you can open/restore to get previous versions of 'file1' and 'file2'. For example, on my Windows machine I can right click on my default MATLAB folder, select "Properties", then select the "Previous Versions" tab, and I see this:

enter image description here

You can see there are a few versions I could open and copy files from if I've inadvertently deleted or overwritten anything recently. Good luck!

gnovice
  • 125,304
  • 15
  • 256
  • 359
  • Thanks for the tips. Unfortunately, there is no 'previous versions' of the file 'fname' when I right click to check the properties. – open0121 Sep 12 '17 at 07:51
  • @open0121: Did you also check for previous versions of the *folder* where your original files were moved from? That may be your better chance, but probably still a long shot. – gnovice Sep 13 '17 at 22:06