How to recover files that were moved to a single file?

155 views Asked by At

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!

1

There are 1 answers

2
gnovice On

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!