41

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.

  • 69
    The desktop is the worst place to store critical data, store it somewhere else and make a shortcut to it on the desktop. – Moab Sep 23 '15 at 21:54
  • 2
    Its common practice, a shortcut just leads to the folder, everything will work. – Moab Sep 23 '15 at 23:22
  • 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 Sep 24 '15 at 1:18
  • 8
    Don'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 Sep 24 '15 at 17:09
  • 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 Sep 24 '15 at 20:14
112

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.

  • 26
    Good shout on backups + version control advice. – bertieb Sep 23 '15 at 13:09
  • 6
    @bertieb it's crucial. OP doesn't have to accidentally delete the folder to lose their work, the drive can die tomorrow. – CodeCaster Sep 23 '15 at 13:10
  • 11
    Agreed. 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 Sep 23 '15 at 13:10
  • 7
    As 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 Sep 23 '15 at 15:16
  • 8
    What'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. – Alhadis Sep 25 '15 at 11:48
51

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.

  • 2
    Given the circumstances, this is the right answer. – Angstrom Sep 23 '15 at 15:24
  • 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 Sep 23 '15 at 16:09
  • @JasonStack, A Cygwin install might very well have problems if you move it to another location. – barbecue Sep 24 '15 at 1:37
  • 1
    @JasonStack, you might want to edit your question to include the Cygwin details, as it does affect possible answers. – barbecue Sep 24 '15 at 1:41
  • 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 Sep 24 '15 at 20:17
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.

  • 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 Sep 24 '15 at 20:19
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.

  • 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 Sep 24 '15 at 20:41
  • 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 Sep 24 '15 at 20:51
  • 1
    @JasonStack see superuser.com/questions/253935/… – JDługosz Sep 24 '15 at 20:53
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

  • 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 Sep 25 '15 at 0:25
  • The previous versions feature was removed in Win 8.1, the file history feature is its replacement. – barbecue Sep 25 '15 at 14:40
  • 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 Sep 25 '15 at 20:01
  • @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 Sep 26 '15 at 1:31
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.

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.

  • 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 Sep 24 '15 at 7:31

protected by Community Jul 20 '16 at 21:03

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.