GP SoftwareTwitter
Opus FAQsManualCommandsObjects

Is it possible to copy only file names, not contents?


#1

Hello.

Is it possible to copy only file names, not contents ? I’m not saying about copying file names to clipboard. I mean copying files to other folders without copying contents of those, which results in size of copied files being almost 0.

E.g

I have 3 files in A1 folder.

readme.txt 256kb
readme.doc 2.2mb
readme.exe 5.5mb

I want files with identical names to be in B1 folder too, only their size being 0(or almost 0).

readme.txt 0
readme.doc 0
readme.exe 0

I could manually do that by creating empty files, and then copying original file names to created ones. But there are tons of files, so it is almost impossible to do it again and again.

Can I do this with dopus?

Thanks in advance.


#2

It can certainly be done with a script. Details of all (or selected) files in the source tab are available via the tab object and can be used to create empty files with the same names in the destination tab.


#3

Scripting? Hmm… I’m not familiar with programming language. I’m afraid writing a script is difficult for me.
But I’ll try to read help document about script.


#4

Or you can use:

Clipboard COPYNAMES=nopaths

Right click on a toolbar
click Customize
right click toolbar again
select New
select New Button
and then copy the above code line in so it looks like the picture.
Click OK
Click OK on the Customize Dialog
You should now have a button that when you have selected a file, and you click it, it will copy the filename to the Clipboard.

Hope that works out for you, have a nice day.

image

PS There is already an existing method to do that too. You can right click on a file, and on the context menu there is a command “Copy File Name(s)” that will do what it sounds like you need.


#5

#6

@danielmonk
Thank you, but I didn’t meant to copy file names to clipboard.

@blueroly
Incredible! That’s exactly what I was looking for! I can’t thank you enough. It would be better should I be able to copy files in subfolders, but beggars can’t choose. It reduces tons of effort still.
Thank you blueroly and thanks for this script, Leo.


#7

When this thread started it motivated me to write my own script to create zero byte copies of selected files and folders. My code performs a Select SOURCETODEST and a Set DEST=toggle after the copies are complete so that copied items are selected in what becomes the new Source tab.

If there is initially no Dest or Dual target folder then my script prompts the user to select a target folder. This works as expected in most circumstances but not in one unusual (I admit) situation. When there is a single, non-dual, lister the active tab can be in either Source or Dest mode. If it is in Source mode and my script is executed from a toolbar button or immediate (>makezero) command, the Select SOURCETODEST operation works as expected but if it starts in Dest mode then Select SOURCETODEST appears to do nothing.

makezero.zip (1.7 KB)

// Create zero byte copies of selected source files and/or folders in the destination folder.
// Only copy if the destination folder exists and is not the same as the source folder.
// Do not replace existing items in the destination folder.

function OnInit(initData)
{
	initData.name = "makezero";
	initData.vars("name") = initData.name;
	initData.desc = "Create zero byte copies of selected items";
	initData.copyright = "(c) 2018 Aussie";
	initData.version = "1.0";
	initData.vars("version") = initData.version;
	initData.default_enable = true;
	
	var cmd = initData.AddCommand();
	cmd.name = initData.name;
	cmd.method = "do_main";
	cmd.desc = initData.desc;
	cmd.label = initData.name;
	cmd.template = "parms/m";
	
	initData.config_desc = DOpus.create.map();
	initData.config.dbg = false;
	initData.config_desc("dbg") = 'Set to TRUE to write trace information to "Other" log.';
}

//-- Global Variables

var dbg;
var d, f, c, fsu;
var dlg, msg, btns, title;
var src, tgt;
var n, str;

function do_main(clickData){
	d = clickData;
	f = d.func;
	c = f.command;
	fsu = DOpus.fsutil;
	//-- Possibly switch debugging on (set via Preferences)
	dbg = Script.config.dbg;
	title = Script.vars("name")+" version "+Script.vars("version");
	btns = "OK";
	if (dbg) DOpus.output(title+" starting..");
	src = f.sourcetab;
	dlg = src.dlg;
	if (dbg) DOpus.output("src.source = " + src.source);
	// When there is a single non-dual lister, source = dest (obviously)
	// and less obviously the active tab can be set to dest rather than source
	tgt = (src.source) ? f.desttab : f.sourcetab;
	if (Number(tgt)==0) tgt = f.sourcetab;
	var src_path = resolve(src.path);
	if (src_path=="") {
		msg = "Invalid source.";
		dlg.request(msg, btns, title);
		return;
	}
	if (dbg) DOpus.output("src_path = " + src_path);
	n = src.selected.count;
	if (n==0) {
		msg = "Nothing selected, nothing to do.";
		dlg.request(msg, btns, title);
		return;
	}
	var tgt_path = resolve(tgt.path);
	if (tgt_path=="") {
		msg = "Invalid destination.";
		dlg.request(msg, btns, title);
		return;
	}
	if (tgt_path==src_path) {
		tgt_path = dlg.folder("Select a target folder..");
		if (dbg) DOpus.output("tgt_path.result = " + tgt_path.result);
		if (tgt_path.result==false) return false;
		tgt_path = String(tgt_path);
		c.runcommand('Go "'+tgt_path+'" '+"OPENINDUAL");
	}
	if (dbg) DOpus.output("tgt_path = " + tgt_path);
	n = src.selected_files.count;
	if (n!=0) {
		var tgt_file, tgt_file_name;
		for (var i = 0; i < n; i++) {
			tgt_file_name = src.selected_files(i).name;
			// Open output file for write only if it does not already exist
			tgt_file = fsu.OpenFile(tgt_path + "\\" + tgt_file_name, "cw");
			// Close immediately to create a zero byte file if the file did not already exist
			tgt_file.Close;
		}
	}
	n = src.selected_dirs.count;
	if (n!=0) {
		for (var i = 0; i < n; i++) {
			str = "CreateFolder " + '"' + tgt_path + "\\" + src.selected_dirs(i).name + '"'
			c.addline(str);
		}
		c.run;
	}
	
	// Select newly created items in the destination folder.
	var cmdstr = "Select SOURCETODEST DESELECTNOMATCH MAKEVISIBLE=immediate";
	if (dbg) DOpus.output("cmdstr = " + cmdstr);
	c.runcommand(cmdstr);
	// Toggle Source and Dest
	c.runcommand("Set DEST=toggle");
}

// -- Resolve supplied item (file or folder) spec

function resolve(name){
	var spec = (name=="") ? "" : String(fsu.resolve(name));
	if (spec=="") return "";
	// For most items the resolved name will be just fine
	// Deal with the likes of mtp:// specs by using the display name
	if (spec.indexOf("?")>0) return String(fsu.displayname(name));
	// Eliminate collections
	if (spec.toLowerCase().slice(0,5)=="coll:") return "";
	// OK with individual libraries but not with Lib://
	if (spec.toLowerCase()=="lib://") return "";
	// Eliminate This PC or Trash
	if (spec.slice(0,3)=="::{") return "";
	return spec
}

#8

Now that several versions of this came up and since I wouldn’t know which one to choose the next time I would like to copy only empty files and (maybe) the folder structure they reside in, it might be time to think about implementing this in a native fashion - by some new “EMPTY” switch on the “Copy” and/or “Clipboard PASTE” command e.g.

I’d assume, that flatview, special locations, folders, relative paths, absolute paths, single- and dual-listers would work “right out of the box”, in contrast to each script not supporting all use cases at once. So the foremost enhancement would be, that no special knowledge or scripting would be required. Existing buttons and mechanics (copy, paste etc.) could work as they used to, just not copying the content of items.