ClipListDialog

Title ClipListDialog
File Name ClipListDialog.txt
Description Copy file name(s) to the clipboard according to the settings from the dialog box
Author Vochomurka
Parameters ("%L")
Plugins Called file, vec, clip
Icon
Version 1.2
Updated on 18.05.2006
local fh = file.open(arg(1), "r")
local Str, Counter, What, Depth, i, j, Result, Temp, Before, After
local Char, Len, Path, Slash

if(fh > 0) do
	for(not(file.eof(fh))) 
		Str = file.readstring(fh)
		if(Str != 0) do
			Counter = Counter + 1
			What = Str
		endif
	endfor
else
	messagebox("ok error", "File not opened", "FILE plugin error")
	quit
endif

;Sub_ParsePath - name of script ParsePath 
Depth = runfile.Subs\Sub_ParsePath(What, "")

v = vec.create(Counter)
if(v == 0) do
	messagebox("ok error", "Vector not created", "VEC plugin error")
	quit
endif

Path = "Copy " ++ Counter ++ " name(s) to clipboard"
Temp = "maximum is " ++ Depth
What = "default - Full Path"

Result = Inputdialog("~What=What to Copy??Name with Extension (name.txt)|Path (c:\dir)|Name Only (name)|Extension Only (txt)|Full Path (c:\dir\name.txt)|File Size|Path + Name; No Extension (c:\dir\name), Temp=Path Depth, Before=Before, After=After, Slash=Replacer for \ (default - none)", Path)

if(Result == 0) do
	file.close(fh)
	quit
endif

Depth = ifelse(miscplugin.is_int(Temp) == "1", Temp, 0) 
file.restart(fh)

for(i = 0; i < Counter; i = i + 1)
	Str = file.readstring(fh)
	v[i] = Str

	if(Depth != 0 && Depth != "") do
		Path = runfile.Subs\Sub_ParsePath(Str, Depth)
		Path = Path ++ "\"
	else
		Path = file.folder(Str) ++ "\"
	endif

	if(What == "Name with Extension (name.txt)") do
		v[i] = file.nametype(Str)
	elseif(What == "Full Path (c:\dir\name.txt)" || What == "default - Full Path") do
		v[i] = Path ++ file.nametype(Str)
	elseif(What == "Path (c:\dir)") do
		v[i] = remove(Path, -1)
	elseif(What == "Name Only (name)") do
		v[i] = file.name(Str)
	elseif(What == "Extension Only (txt)") do
		v[i] = file.type(Str)
	elseif(What == "File Size") do
		v[i] = file.size(Str)
	elseif(What == "Path + Name; No Extension (c:\dir\name)") do
		v[i] = Path ++ file.name(Str)
	endif
	if(Slash != "")
		v[i] = replacechars(v[i], "\", Slash)
	v[i] = Before ++ v[i] ++ After
endfor

file.close(fh)

Str = vec.makelines(v)
clip.set(Str)
vec.destroy(v)
vec.unload
file.unload

Comments:

After developing the ClipFileList script and using it for a certain time I have noticed that it is not enough to satisfy my requirements in all cases when I need to copy file name(s) to the clipboard.

While the ClipFileList script is good for "standard", "typical" copy operations, everybody needs to perform special, ad hoc actions. For example, sometimes I need to copy file name(s) with different path depths. It is not suitable to create separate buttons (or hotkeys) to copy file names with path depth of 2, 3, 4, and so on. Thus, it is required to have script able to select the path depth depending on the user's choice.

Everybody has his/her own personal, specific requirements to the "file name to clip" copy operations. They can be roughly divided into "frequent" and "all others". While the ClipFileList script is good for the former group, the present script can cover all other cases.

To copy single file name to the clipboard, just put the cursor on it and run the script. To perform the same copy operation for several files, first select them.

After running the script you'll see the window looking like this one:

The "What to copy" dropdown list contains the same choices that the ClipFileList script does for the second parameter, but presented in more readable way.

The "Path Depth" edit box initially contains the maximum path depth of the last file selected. This number is a prompt or a guide rather than limit or requirement. If the number entered by used exceeds the maximum path depth of some file, then the full path will be copied. Moreover, if files selected have different paths (for instance, they are taken from the listbox panel after search), the "Path Depth" value is of no importance.

Edit boxes "Before" and "After" are initially empty and correspond to the 5th and 6th parameters of the ClipFileList script. The difference is that here there is no restriction to the use of quotes in these strings. The said is demonstrated by text shown on the screenshot.

The last edit box can contain any character or string replacing the backslash character (usually forward slash).

By the way, the "List To Clipboard" utility has no dialog function at all!


All Scripts Total Commander TotalCmd.net PowerPro