Page 1 of 1

Need Script for logging files that are copied

Posted: 25 Jan 2013 18:26
by tatters
Apologies for this stupid question!!!

I need a script that will create a "log file" that lists files that are copied from a server to another hard drive. The "log file" will list the folder structure for the file that is copied from.

I understand that there is a "multi-level undo/redo" with an "action log" that is useful, however, I am unable to export detailed information from the "action log".
For example, if I right-click in the "action log" and select "copy all items", then paste into Notepad, I don't get the detailed information that I require only:

"Copy (2 hours ago) Copy 3 items to "C:\Temp" from "C:\Reports".


I require more detail as in the following example:

"Copy (2 hours ago) Copy 3 items to "C:\Temp" from "C:\Reports
Report.xls to "C:\Temp" from "C:\Reports
Document.pdf to "C:\Temp" from "C:\Reports
Analysis.doc to "C:\Temp" from "C:\Reports"

Any help would be appreciated!
cheers,
Tim

Re: Need Script for logging files that are copied

Posted: 25 Jan 2013 19:43
by highend
Help file: moveto (covers backupto, which is what you're probably looking for).
E.g.: Type into address bar:
rtfm "idh_scripting_comref.htm#idh_sc_moveto";

If you have the latest beta, and your custom copy settings include "Show summary report", you have a "Reports" button in the summary dialog after each copy, that provides the same information.

Re: Need Script for logging files that are copied

Posted: 25 Jan 2013 21:00
by tatters
Thanks for the quick response - i appreciate it!

I like the "Reports" button in the summary dialog - definitely creates the info I need to get the job done!

However, I will probably spend a couple of days copying files - instead of creating a new report after each copy is complete, is there some way to create a report that would cover file copying over a specific time period of copying files (i.e. over a few hours, or a few days?)

thanks again for helping me out!!!

Re: Need Script for logging files that are copied

Posted: 25 Jan 2013 22:38
by serendipity
tatters wrote:Thanks for the quick response - i appreciate it!

I like the "Reports" button in the summary dialog - definitely creates the info I need to get the job done!

However, I will probably spend a couple of days copying files - instead of creating a new report after each copy is complete, is there some way to create a report that would cover file copying over a specific time period of copying files (i.e. over a few hours, or a few days?)

thanks again for helping me out!!!
If you don't mind one log file for each Copy/Move/backup operation then check the "Create log file" inside the "Configure..." dialog window here: Tools>Configuration>File Operations>Backup Operations / Custom Copy operations

Re: Need Script for logging files that are copied

Posted: 25 Jan 2013 23:11
by highend
This script (you have to use it EVERYTIME, if you want the log to be accurate!) copies files and creates a logfile for all operations.
Limitations:
-If the copy fails during the process, the log will not reflect this...
-I'm too lazy to add counts (for files)

What you have to edit: $logFile (the path for it). Eventually the $curDate & $curTime variables to reflect your needs.
Atm it only writes a logfile, the real copy command is commented out (// copyto $dstFolder, $allItems;).

Make a few copies, look at the log file and if you trust the script, comment it in. Ofc you should delete the logfile before you do real copies.
At least it allows you to collect information for a single day.

It works for selected files & folders (at the same time). The inactive pane is always the destination folder (but ofc this could be changed in the script)!

Here we go:

Code: Select all

/* *********************************************************
 * @@ScriptName: CopyWithLog.xys
 * @@Author: Highend
 * @@Create Date: 25.01.2013 20:56:27
 * @@Modify Date: 25.01.2013 22:10:42
 * @@Function: Copy files and create a logfile
********************************************************* */
	$curDate = "<date yyyy-mm-dd>";
	$curTime = "<date hh:nn:ss>";
	$logFile = "C:\Temp\BackupLog_$curDate.txt";
	$selItems = get("SelectedItemsPathNames", "<crlf>");
	$srcFolder = get("path", "a");
	$dstFolder = get("path", "i");

	$report = "";
	$allItems = "";
	foreach($item, $selItems, "<crlf>") {
		if(exists($item) == 1) {
			$allItems = $allItems . $item . "|";
			$report = $report . getpathcomponent($item, "file") . " to " . quote($dstFolder) . " from " . quote(getpathcomponent($item, "path")) . "<crlf>";
		} elseif(exists($item) == 2) {
			$tmpReport = formatlist(folderreport("files", "r", $item, "r", , "|"), "e", "|");
			$allItems = $allItems . $item . "|";
			$allLines = regexmatches($tmpReport, "^.*(?=|)", "<crlf>");
			foreach($line, $allLines, "|") {
				if($line != "") {
					$file = regexreplace($line, "(.*\\)(.*)", "$2");
					$srcPath = gettoken(regexmatches($line, "^.*(?=\\)", "|"), 1, "|");
					$dstPath = $dstFolder . replace($srcPath, $srcFolder, "");
					$report = $report . $file . " to " . quote($dstPath) . " from " . quote($srcPath) . "<crlf>";
				}
			}
		}
	}
	// copyto $dstFolder, $allItems;
	writefile($logFile, "<crlf>" . "Copy operation on $curTime:" . "<crlf>" . $report, "a");
Results to:
C:\Temp\BackupLog_2013-01-25.txt
With the content:
Copy operation on 23:20:53:
cover.jpg to "C:\Temp\Daniel Glattauer - Gut gegen Nordwind" from "D:\Users\Highend\Downloads\Daniel Glattauer - Gut gegen Nordwind"
Gut gegen Nordwind - Daniel Glattauer.pdf to "C:\Temp\Daniel Glattauer - Gut gegen Nordwind" from "D:\Users\Highend\Downloads\Daniel Glattauer - Gut gegen Nordwind"
CodeStyleConventions.doc to "C:\Temp" from "D:\Users\Highend\Downloads"
Evernote_4.6.1.7772.exe to "C:\Temp" from "D:\Users\Highend\Downloads"