I made one Windows file exist in two folders with out making a second copy


If you ask almost anyone where a file is on Windows, they’re going to identify a folder, and I’d normally agree. But after making a single textual content file stay in two totally different folders, with no copies concerned, I began issues in a different way. There’s a built-in mechanism on Windows for this, and all you want is a single command.

I examined it by making an attempt to interrupt issues; I edited, deleted, moved it between drives, and acquired outcomes I did not count on.

One file, two folders

I checked whether or not Windows had saved one other gigabyte

To begin, I created a plain textual content file known as authentic.txt, and placed it in a folder called Projects. Then I opened the Command Prompt and ran this command:

mklink /H C:TestArchivesecond-name.txt C:Take a look atProjectsauthentic.txt

The command created a tough hyperlink, giving the identical file knowledge a second identify: second-name.txt. It pointed on to the identical file’s knowledge I had created. I acquired affirmation of my arduous hyperlink when Windows printed each paths beneath the identical file after I ran the command:

fsutil hardlink record C:Take a look atProjectsauthentic.txt

While it instructed me each names had been linked, nothing had been copied. Next to each file names, File Explorer listed 1GiB, however this wasn’t a lot assist. I wanted extra context, so I created a 1GiB dummy file and observed the free area on my C: drive dropped by about 1GiB. Then I hard-linked it to the second folder and this time the free area dropped by solely 671,744 bytes (about 656 KiB), not a whole gigabyte.

I nonetheless could not account for the additional bytes, however the hard-link record confirmed that Windows hadn’t created one other copy of the file’s knowledge. It added a second identify for that very same file.

Edit one, change each

The catch is how your app saves the file

Original text document created in folder A
Afam Onyimadu / MUO

I appended a line to the second name using this command:

echo Added by the second identify >> C:TestArchivesecond-name.txt

I opened authentic.txt and that line was already there. No syncing or copying occurred; I had edited just one file.

Appending is the simple case as a result of it writes instantly into the present file. The route most individuals would relatively take is to open an app, edit the file, and reserve it. So I attempted it. I opened second-name.txt with Notepad, and after making an edit, I saved it. Then I headed again to the Command Prompt and ran fsutil hardlink record.

Once once more, I may see each paths listed with authentic.txt exhibiting the adjustments.

I solely examined utilizing Notepad, so this is probably not the identical expertise with each program. Other packages can break the hyperlink by saving to a brand new momentary file and changing the unique, leaving the 2 names connected to totally different recordsdata.

If you utilize a unique app, run the fsutil hardlink record command and ensure that each paths nonetheless seem.

Delete a reputation, hold the information

I deleted the file I known as “authentic” and misplaced nothing

Both folders created within HardLinkTest for this experimeng
Afam Onyimadu / MUO

Here was the purpose I assumed I would break it. I deleted the primary file I created, authentic.txt. When I opened second-name.txt, nothing had modified. Even my most up-to-date edits had been nonetheless mirrored.

However, after I deleted second-name.txt, each file names had been now gone. This was mirrored in my 1GiB check: the obtainable area on my C: drive barely modified after I deleted the primary identify, however I acquired again about 1GiB after deleting the final identify. As lengthy because the identify pointed to it, the information remained obtainable on my pc.

Filenames on Windows are listing entries for particular recordsdata, and the information exists individually. When you delete one arduous hyperlink, you might have merely eliminated the label, however the shared knowledge stays accessible by the remaining hyperlink.

Every file in your pc has a reputation which is already one listing entry for its knowledge. Using the mklink /H command permits you to add a second identify. Even although I known as one file authentic.txt, it actually does not matter as a result of neither identify was ever extra authentic than the opposite.

I got here out with two sensible realizations. As lengthy as a tough hyperlink exists, you do not reclaim any area that the information holds by deleting a reputation that factors to it. Only eradicating the final hyperlink will unlock area. Secondly, a tough hyperlink shouldn’t be mistaken for a backup; each names entry the identical knowledge. Any change made by one identify seems by the opposite.

My C: to D: try, and what to make use of when you have to cross drives

I wasn’t carried out simply but. I attempted to hyperlink a file throughout drives, and Windows outright refused the operation: “The system can’t transfer the file to a unique disk drive.” It’s additionally inconceivable to hard-link a folder or create a tough hyperlink throughout drives. For folders or recordsdata on totally different drives, I’d take into account two different choices:

Hard hyperlink

Shortcut

Symbolic hyperlink

Description

Another identify for a similar file

A .lnk file that shops a goal

A filesystem hyperlink to a goal path

Crosses drives

No

Yes

Yes

Works on folders

No

Yes

Yes

Delete the hyperlink

Other arduous hyperlinks nonetheless entry the information

Target stays; shortcut disappears

Target stays; hyperlink disappears

Delete the goal

Other arduous hyperlinks nonetheless entry the information

Shortcut could cease working

Link could turn out to be damaged

A tough hyperlink is the best way to go on the identical drive in order for you an actual second identify for a file. When linking across drives or to folders, use a symbolic link.



Source link