Flat copying without Flatview

The bigger picture: I want to move files off my camera into a single folder on my PC. I have a (working) button that uses SET FLATVIEW and FLATVIEWCOPY=single, but after reading Leo's statements here, I want to do it the right way.

So the specific problem is: how do I move all files from all subfolders to the base folder?

This is what I have so far:

@set mySource D:\test\RX100
@set myDest /Pix\in{date|yyyyMMdd}-{time|HHmmss}
CreateFolder {$myDest}
COPY {$mySource}\* TO {$myDest} FILTER *.(arw|jpg|mts|mp4)
Rename RECURSE FROM {$myDest} CASE=extlower

But I can't get the Rename statement right to move all files to the base folder:

Rename RECURSE FROM {$myDest} PATTERN * TO $.\*

I tried all kinds of variations with slashes and asterixes, but either the folder structure remains or the files end up one level too high.

I have a rename preset that works well when used separatedly,

Old name: *
New name: $.\*

but shifts the files one level too high when used in the button

Rename RECURSE FROM {$myDest} PRESET="into sourcefolder"

Here's how I would do it, if I've understood everything correctly.

(That Resolve(destPath) line shouldn't really be needed, but seems to be at the moment. Looking into that as it might be a bug with the Rename command not working with aliases.)

function OnClick(clickData)
{
	var sourcePath = 'D:\\test\\RX100';
	var destPath = '/Pix\\in' + DOpus.Create.Date().Format('D#yyyyMMdd-T#HHmmss');
	var extensions = DOpus.Create.StringSetI('.arw', '.jpg', '.mts', '.mp4');

	destPath = DOpus.FSUtil.Resolve(destPath); // Rename command at end needs resolved path.

	var cmd = clickData.func.command;

	// Create destPath.

	cmd.ClearFiles();
	cmd.RunCommand('CreateFolder NAME="' + destPath + '"');

	// Copy files from sourcePath to destPath, flattening to a single dir.

	var anyFiles = false;
	var folderEnum = DOpus.FSUtil.ReadDir(sourcePath, true); // Recursive
	while (!folderEnum.complete)
	{
		var folderItem = folderEnum.Next();
		if (folderItem.is_dir) continue;
		if (!extensions.exists(folderItem.RealPath.ext)) continue;

		cmd.AddFile(folderItem.RealPath);
		anyFiles = true;
	}
	if (!anyFiles) return;
	cmd.RunCommand('Copy TO="' + destPath + '"');

	// Lower-case file extensions in destPath.

	cmd.ClearFiles();
	cmd.RunCommand('Rename FROM="' + destPath + '\\*" TO=* CASE=extlower');
}
1 Like

That's fixed and the Resolve line shouldn't be needed after the next update. (It's still not a bad thing to do, since it means the path only gets resolved once instead of several times.)

Thanks a lot! Works well, just as intended. I will also use it as a base and improvement for some other scripts. Learned again a few things, which is a really nice bonus :slight_smile: