Move directory and inherit permissions from target folder (as Copy would do) - winapi

That's what I want to achieve for my VCL application:
I extract a ZIP file to a directory in %TEMP%. If everything was okay, I move the directory to the target dir.
For the move operation I use JclFileUtils.FileMove (from JCL which resolves to MoveFileEx), because I need a real move operation and I want to overwrite files in the target dir.
This works so far, but the moved files have a per user file permission (inherited from Temp). I want the moved files to inherit permissions from the target folder.
Remarks:
Copy and delete is a workaround, I am aware of. But I want to avoid this (because of file size).
System.IOUtils.TFile.Move does not work for me, because it is implemented by copy and delete (in XE4).
Here a similar problem is described for .NET, but I do not know if an equivalent to GetAccessControl/SetAccessControl exists in Delphi.

Related

How can I mirror deleted duplicates from a source into a destination?

Here's the scenario: We have a computer running Windows 10 which has a directory that's backed up nightly. The backups are done with a batch file utilizing Robocopy and scheduled via Windows. The parameters are as such that the backup will always add any new files or existing file edits into the destination, but it will never delete files from the destination that have been deleted in the source. It essentially archives all files which are in the source directory at the end of each day.
Here's the tricky part. The source directory is very large, and occasionally someone finds a duplicate file (or several duplicates of a file) in it. When that happens, we need to delete all but one copy of the file, and then we need to access the backup directory manually, locate the file there, and do the same. This is tedious and time-consuming as it's not rare for someone to notice an entire subdirectory full of files that exist 5+ times each.
What we're looking for is a way to scan the source directory and all subdirectories inside for duplicate files and remove all but one copy of them, and then a way to reflect that into the destination. I've assumed that we will not be able to use Robocopy to reflect the changes in the destination due to the nature of the backup script it's running, but we do have the ability to run any third-party software on the destination directory as well, essentially running an action in both directories to clean each of them of duplicate files.
On that note, I'm not against using third-party tools to make this cleaner or more efficient, I'm just not aware of any.
There is one way to solve this problem I was also suffering from this problem. but I found that how to use "BATCH" file
There are mainly 2 command
X_COPY
ROBO_COPY
According to your need here, (1)x_copy will be helpfull
xcopywill backup your specific file or folder even if you changed some megabytes data, it will copy the new data and will not be replaced on previous data it will make new copy.
HOW TO DO
Open NotePad and type
xcopy "source file" "destination" /y/e/d/c/f/h/i/z/j
And then save your notepad as ".bat" file
for more requirement use below url
https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/xcopy

What's the proper way to overwrite system/hidden files with Windows API?

When you copy files using CopyFileExA function (see Windows API Reference: winbase.h) it has the ability to "fail" or not, if the destination file already exist, using (or clearing) the flag COPY_FILE_FAIL_IF_EXISTS. However, I can not find the way to overwrite files with attributes Read Only, Hidden or System.
I am working on a backup program with specific requirements which I can't find anywhere else.
I was thinking that before copying a file with one or more of those attributes set, perhaps I could clear those attributes on an existing file and then proceed to copy the file, knowing that my program will overwrite existing file with clear attributes.
Is that the best approach?
Another option would be just delete the old file before copying a new one. But I'm afraid that if I delete the old (backup) file and only then will try to copy the new one AND if the copy for some reason fails, then I will ended up without a backup file.
Or maybe there's a way of overwriting System/Hidden files that I'm not aware of.
What would be the best method of accomplishing this - copy and overwriting files with System/Hidden/ReadOnly attributes set?

Rename folder with overwrite deletes the source folder in Cloud Files API

I am creating a virtual file system using Cloud Files API. I am trying to implement rename/move and delete operations for folders. The rename folder with overwrite scenario (when the target folder exists) behavior is confusing. In Windows Explored I am trying to rename Z:\Folder1 to Z:\Folder2 while the Z:\Folder2 already exists. Before the the rename operation is performed, the source folder is being deleted by calling CF_CALLBACK_TYPE_NOTIFY_DELETE callback.
Here is the sequence of callbacks that I get with Cloud Filter API:
CF_CALLBACK_TYPE_NOTIFY_DELETE is called on the source folder.
Each file from source folder is being moved to the target folder.
CF_CALLBACK_TYPE_NOTIFY_DELETE_COMPLETION is called on the source folder.
As a result there is no way to delete a folder in my storage inside the CF_CALLBACK_TYPE_NOTIFY_DELETE callback because this will delete all files prior to the move operation. Also there is no way to distinguish between delete and move operations inside the CF_CALLBACK_TYPE_NOTIFY_DELETE (so I can ignore it for the move operation).
How do I properly implement the delete and rename/move callbacks in Cloud Files API?
It is specific of Windows File Manager. I tried "Move" operation using PowerShell "Move-Item" with "-Force" option and I got next sequence of callbacks (without delete callbacks):
CF_CALLBACK_TYPE_NOTIFY_RENAME
CF_CALLBACK_TYPE_NOTIFY_RENAME_COMPLETION

Change ItemType from file to directory

to clean up my hard disk I use a Powershell script that automatically copies video files from one folder to a different hard disk and deletes them from the old folder.
Now I installed a new hard disk and wanted to use it to save the files. I changed the paths in the script, but unfortunately forgot to create the destination folder on the new hard disk. The files should be copied to the folder Y:\Moved. However, since this did not exist, the script created a file called "Moved".
Is it possible to convert this file so that Windows recognizes it as a folder? So to change the ItemType from "file" to "directory"?
Best regards,
Florian
No, changing a file to a folder is not possible. Rename the file you created, create the folder, then move the renamed file to the folder.
I made a mistake in thinking. I assumed that a single file was created from all files (just like a folder). Of course, this is not the case. The Moved file was overwritten for each video. So the file only holds the last video. Thanks for your answers anyway.

What is a right way to deal with tests, temporary files and version control

I use Ruby for writing a code, test it with Cucumber and Rspec and control versions with Git. But here are some unclear things for me. E.g. temporary files, created by tests. I don't want to track their changes with every commit.
So, what way I should use for that:
Locate temporary files inside project folder and use some Git tricks for ignoring changes. gitignore is not useful, because I need some files to be in the place, when tests are started.
Locate temporary files in the /tmp. It gives some unclear for test environment, though.
Any other ways deal with that?
The files required when the tests start should be in source control. Ideally you want temp files created by tests to be in one directory so you can ignore the whole directory. If that's not possible then add each file to the .gitignore file. Really, outside of test results, your specs should clean up after themselves, which should include deleting temp files created during testing.
gitignore is not useful,...
gitignore should be useful here:
either you can limit those temporary files to a dedicated folder within the repo, and you can ignore that all folder;
or you can identify those temporary files by their extension or naming convention, and you can ignore them by a name pattern.
Ruby has facilities for creating temp files and directories and cleaning them up for you, use that. It will pick the correct location for temp files for the current environment, probably well outside your repository, and you never have to worry about them again. While the rule of thumb for tests is to not write files outside your source directory, using a global temp directory is acceptable and reliable.
Otherwise, create a temp directory in your project (possibly inside your test directory) and put all your temp files there. Set .gitignore to ignore that directory. This has the slight advantage of keeping your test artifacts entirely inside your source directory, and you can find them easier for debugging purposes. You should still use Ruby's Tempfile class to manage them, just tell it to use your temp directory, to handle cleanup and to ensure your temp names are unique to allow parallel testing.
I would recommend just using whatever Tempfile.new spits out. Remembering to set the special test temp directory is one more moving part you don't need.

Resources