How can I prevent a folder from being inadvertently deleted by myself?

40

5

I have a very important folder on my Desktop. I occasionally clean up my desktop and I am very concerned that I might delete the mentioned folder inadvertently. Is there a way to prevent such a disaster without limiting my frequent read-write operations on the folder's content? Note I don't mind deleting the content inside the folder one by one on occasion but the folder itself matters to me. If it is deleted, I lose a lot of efforts.

codezombie

Posted 2015-09-23T13:00:43.593

Reputation: 1 426

69The desktop is the worst place to store critical data, store it somewhere else and make a shortcut to it on the desktop. – Moab – 2015-09-23T21:54:36.320

If I now move that folder to somewhere and create a shortcut with the same name on Desktop, will everything depending on the folder continue to work normally? – codezombie – 2015-09-23T21:57:37.807

2Its common practice, a shortcut just leads to the folder, everything will work. – Moab – 2015-09-23T23:22:32.723

3@JasonStack probably, but not necessarily. If you move the folder, and you have some other program or document that assumes the folder is on your desktop, it might break something. It could happen if you have files that link to other files, for example. If that doesn't apply to your content, then you probably won't have any issues. – barbecue – 2015-09-24T01:18:28.880

I have installation files for a program stored in this folder. So, should replacing it with a shortcut break the working @barbecue? – codezombie – 2015-09-24T06:24:04.670

8Don't do that.

<hr/> Make backups. **Always make backups**. On external media. **Always make backups on external media.** Also, you should check out Windows' File History/Previous Versions feature. It's pretty handy. – forloop – 2015-09-24T17:09:02.993

1“If I now move that folder to somewhere and create a shortcut with the same name on Desktop, will everything depending on the folder continue to work normally?” @JasonStack I answered that in my updated Answer, below. I'd like to point out that Junctions were introduced for the express reason to be able to move things to a different physical volume without affecting anything. – JDługosz – 2015-09-24T20:14:37.367

There is one thing you can do... create a deep nest of folders within that directory on the desktop and place a file or two in each level. Bonus points if the file you create has a long name too.
If you have long enough folder names and a deep enough path, you won't be able to delete the folder by accident because the recycle bin will throw an error message about the file name(s) being too long for the destination. You would need to delete contents from the deepest level backward (http://superuser.com/questions/755298/how-to-delete-a-file-with-a-path-too-long-to-be-deleted).

– Reece – 2015-09-25T01:38:24.597

This is a crazy suggestion but it is so crazy it might just work: Find a guy who can write a little code (or a full fledged programmer), ask him to create a simple application that keeps a handle to at least one of the files in the folder. No other software will be able to delete the file without getting you to close the application that has the handle's (except for a driver and NT). I am a programmer and used to do it when I had to share my computer. – nom – 2015-09-26T05:41:49.647

1I really hate when people store data on their desktop. Data should be stored at directories likes Documents. The desktop is meant for your current project data, and temporary storing of files. – KaareZ – 2015-09-26T16:12:44.883

You know @KaareZ Desktop is very convenient to access. – codezombie – 2015-09-26T17:03:55.407

Answers

110

Don't try to avoid the inevitable. Use backups and version control.

You could deny yourself the Delete permission though. Deleting files and folders within that directory is a separate permission that you could also disable when required.

CodeCaster

Posted 2015-09-23T13:00:43.593

Reputation: 1 429

26Good shout on backups + version control advice. – bertieb – 2015-09-23T13:09:19.593

6@bertieb it's crucial. OP doesn't have to accidentally delete the folder to lose their work, the drive can die tomorrow. – CodeCaster – 2015-09-23T13:10:10.117

11Agreed. Running without backups is just data loss at some point in the future- when, not if. Now, if you'll excuse me scurries off to double-check backups – bertieb – 2015-09-23T13:10:54.117

7As an IT guy, please use both backups and version control for all important files, especially anything for clients or your business. Please, please, please. – corsiKa – 2015-09-23T15:16:15.607

I have heard version control for software developers. Does it apply to me too? – codezombie – 2015-09-23T16:10:32.257

1@Jason yes, you can version any file with version control. They work best on text files, but you can store binaries as well. – CodeCaster – 2015-09-23T16:11:21.747

@JasonStack try tortoise SVN, very easy to use. Make a local repository, convert the folder on your desktop to a working copy, bam. – Mindwin – 2015-09-23T18:22:53.720

2Having used both SVN and git, I wouldn't touch SVN with a 10 foot pole unless someone was paying me a lot to do so. Use git. – Derek Stucki – 2015-09-24T13:51:20.467

1@Derek yeah, well, you know, that's just, like, your opinion, man. ;-) For a single user, does it really matter? – CodeCaster – 2015-09-24T13:56:07.587

1http://www.taobackup.com/ – kurast – 2015-09-24T17:46:57.687

2If important data doesn't exist in at least 3 different physical locations, it doesn't exist at all. – undergroundmonorail – 2015-09-25T01:04:07.070

8What're the odds of this happening, you ask? PRETTY DAMN GOOD, I myself accidentally deleted a folder full of important stuff late last year that I couldn't get back. Major wakeup call, I now fervently backup my work in GitHub, mirrored on BitBucket, and also mirrored on a portable hard-drive. TAKE IT FROM A SURVIVOR, KIDS, DON'T LET IT HAPPEN TO YOU. LISTEN TO THESE GUYS, BACK YOUR STUFF UP. SERIOUSLY. – None – 2015-09-25T11:48:58.077

We can all learn from Dej Loaf and Pitbutt. When they say "Back UP!" (stop listening after that) – kevingreen – 2015-09-28T14:54:01.263

@kevingreen who are they? I'm getting old... – CodeCaster – 2015-09-28T14:58:21.413

@CodeCaster two rap groups. The songs aren't relevant other than they both have 1 named "Back Up". I don't listen to either group, but I know they had songs with that name. We do need a song with a catchy chorus so everyone remembers to back up their data. – kevingreen – 2015-09-28T19:59:25.123

50

There is a better solution to your problem: move the folder to a more appropriate place (e.g. %USERPROFILE%\Documents)

If you must have access to the folder from the Desktop, you can always create a shortcut. This ensures that while you might accidentally delete the shortcut, you never actually delete the folder or its precious contents themselves.

If other applications depend on this folder being on the Desktop, you could create a symbolic link with the "mklink" command. Since symbolic links are handled at the file system level (while shortcuts are actual files that simply point to another location), there should not be any compatibility issues with programs that try to use this type of "shortcut" in paths.

Michael Becker

Posted 2015-09-23T13:00:43.593

Reputation: 611

2Given the circumstances, this is the right answer. – Angstrom – 2015-09-23T15:24:56.513

I like the idea. but, I don't understand if it will work for Cygwin that I have installed on the mentioned folder on Desktop. Wouldn't it cause problems for my Cygwin installation and functionality? – codezombie – 2015-09-23T16:09:20.353

@JasonStack, A Cygwin install might very well have problems if you move it to another location. – barbecue – 2015-09-24T01:37:26.680

1@JasonStack, you might want to edit your question to include the Cygwin details, as it does affect possible answers. – barbecue – 2015-09-24T01:41:37.157

1@JasonStack Cygwin should treat Junctions invisibly, like Unix mount points. Unix programs know about symbolic links and newer versions of Cygwin libraries should treat (Vista-style) symbolic links as that, so it's up to the program to "see" them as something special or not. – JDługosz – 2015-09-24T20:17:52.147

@JDługosz the key point is that simply moving a folder from one location to another may have undesirable consequences. – barbecue – 2015-09-24T22:54:49.127

Note that symbolic links are less transparent than junctions. – user541686 – 2015-09-26T06:01:19.433

7

Yes, potentially limited by which version of Windows you have (Home versions may not have the ability to adjust ownership). Also, beware that removing your delete permissions is not a guarantee that you can't delete the folder. I've been burned multiple times.

Here is a method that is usually foolproof:

  1. Create a new user
  2. Assign ownership of the folder you don't want to be able to delete to this new user
  3. Remove your user's access to delete the folder, make sure your user has full read/write privileges in the folder.

I've used this trick on Windows NT to Windows 7. Sometimes you have to monkey around with the settings a bit before you get it perfect.

TEST THIS ON A NEW FOLDER FIRST (including creating files and folders within the test folder!

Also: Heed the advice of "Use Backups and version control". If the files are that important, you need at least 2 copies.

Bill

Posted 2015-09-23T13:00:43.593

Reputation: 81

Windows Home Basic can adjust ownership; they just didn't include any applet to do so. A third-party permissions tool still works. Also the so-called "God Mode" PIDL might have it listed; I don't recall. It depends on whether they withheld the snap-in too. – JDługosz – 2015-09-24T20:19:49.720

5

Windows file systems have a "read-only" flag. That is simpler than having to set DACL permissions for such a simple effect.

In a command prompt, use the ATTR command. In the GUI shell it should be in the Properties, though the gui might do something complex and beyond what you really wanted.


Also, if you re-create a directory with the same name you can then apply "restore previous versions" on it.


Update

I experimented on a Win7 system. The GUI delete (without recycle bin) ignores the R flag on the directory. There are no additional prompts warning about it, either, like I've seen for H and/or S flags. Issuing rd from the command line gives access denied as expected. However, you can't just rd a non-empty directory anyway: delete file and remove directory are different commands. A command to recursively remove a directory with contents will remove the contents and than fail to remove the now-empty directory.

So protecting the directory itself doesn't work in the GUI action you have in mind. And it implies that any fancier approach to preventing the directory itself from being removed won't prevent it from being emptied first! You said you still want normal access within the directory to create and remove files, so locking it down completely is not a solution for you.

The best solution seems to be the symbolic link. Making a symbolic link (new style, what Windows Vista and above now call a symbolic link) to the directory on the desktop, when the directory actually exists somewhere else, works in the sense that if I delete the desktop icon (shift-delete, no recycle bin) the actual directory is unaffected as only the link was deleted.

Shift-Delete of the desktop icon did not care if it was marked with the R attribute.

A program using the standard Windows file-open dialog box navigated through the symlink with no problems. It actually resolved the name of the linked directory, so the file opened was the real name; e.g. Desktop\MyFolder became D:\scratch\MyFolder as I navigated through it.

Using an old-style link (a Junction), the program saw the name with the junction still in the path; e.g. C:\Users\john\Desktop\MyFolder\test.txt so the fact that it's a link is invisible. Yet, the GUI delete action still treated it as a link, not invisibly following it.

Either way, if a program does use the aliased name directly it will work. But having files sometimes seen with one name and sometimes the other could confuse things.

Conclusion

Use a Junction on the desktop with the folder really located elsewhere, and it will be completely transparent that this is what is happening. Optionally, using DACL to prevent accidental deleting of the junction point file on the desktop. At least, have a script to re-create it when needed.

Bonus

I've not tried this, but I wonder if you could have something in "new items" to re-create the junction or symbolic link? Then just right-click on the now-empty desktop, choose New... and pick "Desktop Junk" from the menu. Have it restore everything you really did want on the desktop.

JDługosz

Posted 2015-09-23T13:00:43.593

Reputation: 597

I have never heard of Desktop Junk or junction in Windows. What I knew was shortcut. Is that what you mean by junction? By the way, I recently discovered from answers and comments about mklink and I moved the folder I wanted (Temp) to Documents folder, then ran mklink mylink %userprofile%\Documents\Temp on it. It worked and I seem to have no problems with the programs dealing with the directory. – codezombie – 2015-09-24T20:41:20.663

Desktop Junk is a name I made up for his script. Or rather for the menu item he adds to invoke the script. It's a pun on Desktop Junction and Junk Drawer. A shortcut is a different thing. Shortcuts are known only to the GUI shell and confuse everything else. So it probably works like the symbolic links when using File-Open dialog, but you would not be able to use it as an actual directory name: "C:\Users\john\Desktop\Shortcutname\foo.txt" would not work. – JDługosz – 2015-09-24T20:51:12.310

2

Another thing you might consider doing is enabling the File History feature of Windows 8.1. This will allow your system to automatically keep a history of changes to your files and folders. It's best to use with an external storage location, but could be used with a local drive as well.

http://blogs.msdn.com/b/b8/archive/2012/07/10/protecting-user-files-with-file-history.aspx

barbecue

Posted 2015-09-23T13:00:43.593

Reputation: 1 065

I can't speak to Win 8.1 and how File History works, but in Win 7 right-clicking on a folder reveals the "Previous Versions" to recover files from a previous "Restore Point". Great in theory, but if you fill up the disk, Windows discards previous restore point and ... poof - no previous version anymore. Don't rely on the OS any more than you do yourself. – Ian W – 2015-09-25T00:25:06.750

The previous versions feature was removed in Win 8.1, the file history feature is its replacement. – barbecue – 2015-09-25T14:40:57.240

I understand the feature change, however, the question of when the disk runs out of space to make new File History entries, what occurs remains. Wanna test it out? The guidance - don't trust the OS any more than you trust yourself remains. – Ian W – 2015-09-25T20:01:25.857

@Ian W, Not sure how that's relevant. File History creates its backups on a separate storage volume. Filling your hard drive completely can't overwrite the backups, because they're on a separate volume. – barbecue – 2015-09-26T01:31:34.830

1

An effective solution could be moving the folder out of the desktop and then setting up a NTFS junction using the MKLINK command.

C:\Users\Administrator>MKLINK

Creates a symbolic link.

MKLINK [[/D] | [/H] | [/J]] Link Target
        /D      Creates a directory symbolic link.  Default is a file
                symbolic link.
        /H      Creates a hard link instead of a symbolic link.
        /J      Creates a Directory Junction.
        Link    specifies the new symbolic link name.
        Target  specifies the path (relative or absolute) that the new link
                refers to.

So in your case the command would be:

MKLINK /J %userprofile%\Desktop\ImportantFolder D:\ImportantFolder

Where D:\ImportantFolder is the actual folder and %userprofile%\Desktop\ImportantFolder is the junction.

Notes:

  • The Junction doesn't have to bear the same name of the source folder.
  • The junction is not a copy, is in fact a redirection another way to access your folder. Imagine it like the foldr version of a normal (*.lnk) shortcut.
  • Junctions differ from normal shortcut to folders in that they are totally transparent to programs.
  • If the junction is deleted the actual folder is not deleted.
  • But, any file modification is the same as going to D:\ImportantFolder and doing things. So if you delete a passwords.txt file in the junction, you have deleted it from d:/ImportantFolder too.
  • If you accidentally delete the junction, you create it again.

Graphical (More Efficient Easier) Way (With Contextual Menu Extension)

You can instead install Link Shell Extension then you move your folder somewhere else, right-click it and select Pick link source... then you right-click your desktop and select drop as... -> Junction. And you are done.

This is the first application I install on fresh systems, as it is an extremely useful solution. I strongly recomend this if you wil ever have to manage junctions or hard/symbolic links on your pc.

beppe9000

Posted 2015-09-23T13:00:43.593

Reputation: 403

0

You can backup all your files and folder in onedrive. You can use it free but limited for 15gb. However, if you have office 365 subscription you have 1TB storge in onedrive and it is included.

zeleena

Posted 2015-09-23T13:00:43.593

Reputation: 82

Thanks for the suggestion, but I cannot currently use cloud backup due to intense read/write operations in this folder and thus, limitations on bandwidth usage. – codezombie – 2015-09-24T07:31:20.853