Program for copying files with conditions

Status
Not open for further replies.

Cerulean

[H]F Junkie
Joined
Jul 27, 2006
Messages
9,476
Greetings,

I am looking for a program where I could copy and paste folders and files (mixed selection) to a location with an identical set of files. However, these are the conditions I need it to keep in mind:

  • If its "Date modified" timestamp is 2013/3/23 or older, overwrite the file; else skip
  • If the source file has a filesize of 0 bytes, skip

TeraCopy pops up a prompt for every single file, and does not have a way where I could make the first condition be true (only a button to overwrite if older).

Windows 8 does it very nicely, but lacks the logging capacity of TeraCopy; I need to know what files were not copied (and their full paths). If a file or folder is corrupt and gives me an error indicating "Error 0x80070570: The file or directory is corrupted and unreadable", it will not tell me the full path of the file (it will only provide the filename, item type, and size). It will allow me to "Skip 1650 files with the same date and size", and it gives me a nice 2-column presentation of Source and Destination file asking me to checkbox which file I want to keep, so I can scroll down and ignore the 0-byte files and checkbox anything that is 2013/3/23 or older that I want to keep (or use as the final file).

Ideas and suggestions? :(

(Barracuda doesn't play nicely with Windows Server 2012 when file dedupe is turned on.)

EDIT: Nevermind, supervisor isn't interested and wants it to be done one file at a time even if a user profile has 37,000 files in it. For those interested, here are a couple scripts:

executeThis.bat (scans for 0-byte files at X:\Shares\Profiles\jdoe recursively logging to log_0byte-files.txt, and executes PowerShell script)
Code:
@echo off
echo "Scanning for 0-byte files"
set out="log_0byte-files.txt"
(for /r X:\Shares\Profiles\jdoe %%F in (*.*) do (if %%~zF LSS 1 echo %%F)) > %out%
echo "Finished scanning for 0-byte files"
echo "Executing PowerShell script to scan for differences"
powershell .\compareFoldersRecursively.ps1
echo "Finished executing PowerShell script for exporting differences"
pause

compareFoldersRecursively.ps1 (will scan for differences and output to <hardcoded.location>\log_differences.txt)
Code:
$dir1 = "\\server1\E$\Shares\Profiles\jdoe"
$dir2 = "\\server1\X$\Shares\Profiles\jdoe"
$d1 = get-childitem -path $dir1 -name -recurse
$d2 = get-childitem -path $dir2 -name -recurse
$results = @(compare-object -casesensitive $d1 $d2)

foreach($result in $results)
{
$result.InputObject
}

$results | Out-File C:\Users\Administrator\Desktop\log_differences.txt -width 255

The differences that it will log on the PowerShell script are..
  • File is missing from source (but exists in target)
    • Example why this could happen: brand new file user created since a full restore of backups to alternate location (aka NOT restored original location)
  • File is missing from target (but exists in source)
    • Example why this could happen: corrupted file (thus could not be copied)
  • Access denied to directory

Before execution the script, I select everything inside X:\Shares\Profiles\jdoe\Desktop with Ctrl+A, do Ctrl+C, and then go to E:\Shares\Profiles\jdoe\Desktop, and Ctrl+V to paste. First it calculates how much it has to copy over, then proceed to prompt me with files it will not be able to copy over due to corruption, then will ask me what I want to do with files that already exist --> I click on "Let me decide", check the box to skip all files of same date+filesize, and then in the two-column presentation above I scroll through checkboxing files that are (1) not 0-bytes, and (2) if the destination is newer than 2013/3/23 I keep it, but if destination is 2013/3/23 or older, I choose to have the file from source (as long as it doesn't meet criteria #1 of 0-byte filesize).

THEN I run the script. I can go back and delete the 0-byte files, and have a log of what files had a 0-byte filesize and could not be restored. In addition, I have a log of what couldn't get copied over (i.e. because files were corrupt) and what files are brand new since the backup date that was restored (or, did not exist in backup that was restored to alternate non-original location).
 
Last edited:
Status
Not open for further replies.
Back
Top