I was looking for a way to create hard links under Windows and I found this page: http://technet.microsoft.com/en-us/library/cc788097.aspx
To try it out, I created a file (1.txt) on the root of my C: drive with 100 lines of the following content:
C:\1.txt (2.598 bytes):
test test test test test
Then I open the command prompt and typed:
fsutil hardlink create C:\2.txt C:\1.txt
Success, 2.txt was created but when I go to see it's size it has exactly 2.598 bytes and also noticed some strange behaviours (as far as my understanding of hard links goes):
If I delete 2.txt (the hard linked file) 1.txt is not deleted, and vice-versa.
If I open 2.txt after I delete 1.txt (the original file) the content is still the same.
How does the fsutil hardlink create command differs from the copy command? And how can I create a true hard link under Windows?
I'm using Windows XP SP 3, and my file system is NTFS.
That's exactly the behavior that supposed to happen. Are you sure you understand how hard links work? Hard links are really just multiple entries in the file system that refer to the exact same file. If you create a hard link to a file and modify one of the instances of the file, the other file will show up with your changes because they both refer to the same blocks of data on disk.
When you delete one of the hard links, you're really just deleting one of the file system entries referring to that file. The file doesn't get deleted until you delete all of its hard links (including the original one). After you delete 1.txt, 2.txt still exists and refers to the same file that was originally there, only now there is only a single file system entry referring to that file (namely, 2.txt). 2.txt is that file.
How does the fsutil hardlink create
command differs from the copy command?
And how can I create a true hard link
under Windows?
After creating the hardlinked file, try editing either. You will discover that the changes are reflected in both files.
Try creating a hard-link of a very large file (say a video or disk-image). Notice that the available space on the disk has not changed (or not changed by more than a few bytes, if additional metadata had to be written to disk to reflect the new dir entry).
That is a true hard link. In UNIX (I'm not familiar with the Windows variant) a file is just a set of data on the disk (simplistically). It's the directory entry itself that gives that file a name.
When you have two directory entries pointing at the same underlying file, deleting one of them does not delete the file unless it's the last directory entry attached to it (and the file is not still open by a process, but that's a different matter).
Related
In WSL2, is it possible to access the Windows Recycling Bin? Say for example you move file.txt into the recycling bin in the Windows GUI, could you move to the directory that file.txt is contained in on the WSL terminal? How could this be done?
Officially, no. A special implementation of IShellFolder in shell32 handles the recycle bin when files are moved/deleted in the shell namespace.
Unofficially, each drive contains a hidden $Recycle.Bin folder (Recycler before Vista). Each user has a directory inside there named after their SID where their deleted files are stored.
The deleted files do not retain their original filenames, only their extension. Before Vista, a file named INFO2 stored this information. These days $I... stores the information for the original files renamed to $R...
Look at forensics tools like Rifiuti2 if you need to understand the internal format so you can extract the original name...
I have a batch file that copies the most recent version of an access front-end file to the user's C: drive and then opens it from there.
For some users, the copy command causes the batch file to close, and I can't work out what could cause that. The file seems to copy, but the batch file just closes itself without any visible error messages.
I've used Pause to confirm that the failure happens at the Copy step, not the Run or the If.
This is Windows 7, I've tried it with Copy and Xcopy. The users with the issue say it's worked in the past, they all have access to the location being copied from (and to). Mapping the location doesn't seem to make any difference, and UNC paths work for most users so it's not that.
Deleting the existing files in C:\databases doesn't help.
if not exist "C:\Databases\" mkdir "C:\Databases"
copy "\\SERVER02\FINOPS\COMMAQR\DIGIHUB\1. Live Version\DIGIHUB v2.5.accdb" "C:\Databases\"
start [the file]
For 95%+ of users, the batch file copies the most recent version down and opens the file. For a handful, the batch file reaches the copy step and closes itself.
Does anyone know why this could happen, or alternatives to both Copy and XCopy that might not fail?
I'm looking for a way to duplicate / clone an excel file from a source directory to a destination directory. Importantly, the source file(s) must remain in the source directory. Every example I've been able to find, however, uses the copy function of the shutil module which actually moves the source file to the destination.
What you can do is read the contents of the file into a variable, then create a new file where you want and write the contents of your variable in there.
Of course, there are better ways to do it, but this can be made cross-platform and will probably suit all your needs as long as you don't manage big files.
I need a way to select several files with check-boxes and drag them all to a batch-file icon. The first step in the script would be to be compressed them into a single zip file before proceeding to the next step. If possible, it would be useful to also end up with each in a separate zip of its own for storage.
I am not sure how to address the for:to commands to allow gathering all selected files into a single zip file in a script. The Windows 'sendto compressed zip' function works perfectly if I select all the files the copy and paste them to the Windows ZF filetype. But I don't know how to access it from within a batch.
Drag and drop multiple files
By default, if you drag a file onto a batch file it is the same as passing the filepath as a parameter. This can be accessed using %%1. Dragging multiple files would have a similar effect and be like calling test.bat file1.txt file2.txt file3.txt. Each "parameter" can be accessed using subsequent variables, %%1, %%2, %%3, etc, up to %%9.
Get more information here.
Zipping files
First you will need a utility that supports command line operations, such as 7-zip. Once you have the appropriate executable in your path, you will need to review the documentation on how to zip files from the command line. Instead of using the paths and filenames, you will use the variables mentioned above.
Here is some pseudo code:
zipfiles output.zip %%1 %%2 %%3 %%4 %%5
Notes
You will not be able to drop more than 9 files.
You may need to confirm that each variable exists. If you try to include %%9 in the zip command but you only dropped 8 files, you may get an error.
I would like to creat a batch file that will recognise folders date moidified in a network drive and then copy them to another network drive
while I was searching I found way to do that to files, but I need it for folders
I didn't find a way to do that
Sadly, you didn't say which method you'd found. If that method selects the files using a DIR.../a-d... structure for instance, then omit the - before the d and directories matching the selected pattern rather than files would be processed.
To create a batch file just get notepad++ and save as a .bat, is that what you meant? or did you want a certain type of Batch file, because I didn't think there was another type unless you count Command prompt and Notepad++ different?
Forfiles may be helpful, or robocopy
This will create a mirror backup in the destination folder. If files are deleted in the source then they will also be deleted in the destination.
#echo off
robocopy "\\172.172.172.10\folder" "\\172.172.172.2\destination" /mir