fileutil::multi::op(n)
π fileutil::multi::op β the manual page, but make it make sense π
okay bestie, welcome to fileutil::multi::op(n) from the file utilities corner of the world. this is part 1, so don't go anywhere, there's more coming. πΈ
β¨ NAME β¨
fileutil::multi::op β multi-file operation, scatter/gather. it's giving "do stuff to a whole bunch of files at once" energy. π¦
β¨ SYNOPSIS β¨
package require Tcl 8.5 9
package require fileutil::multi::op ?0.5.4?
package require wip ?1.0?
::fileutil::multi::op ?opName? ?word...?
opName option ?arg arg ...?
$opName do ?word...?
into directory
in directory
to directory
from directory
not pattern
for pattern
exclude pattern
but
except
as name
recursive
recursively
copy
move
remove
expand
invoke cmdprefix
reset
(
)
cd directory
up
for-windows
for-win
for-unix
the pattern
the-set varname
-> varname
strict
!strict
files
links
directories
dirs
all
state?
as?
excluded?
from?
into?
operation?
recursive?
strict?
β¨ DESCRIPTION β¨
so like, this package hands you objects that can do actions on multiple files that get picked out by glob patterns. no cap. π
at the very core of it there's a whole domain specific language that makes it easy-peasy to specify multi-file copy and/or move and/or deletion operations. alternate names for this whole thing would be scatter/gather processor, or honestly maybe even assembler. it's iconic like that. π
β¨ CLASS API β¨
the main character command of the package is:
::fileutil::multi::op ?opName? ?word...?β this one creates a brand new multi-file operation object, and it comes with an associated global Tcl command whose name is opName. you use that command to invoke all the various possible file operations. its general form goes like this:
opName option ?arg arg ...?
Option and the args are what determine the exact behavior of the command. periodt.
if you pass the string %AUTO% as the opName, the package will generate a unique name all on its own. self-sufficient queen. π
if one or more words are specified, they get interpreted as an initial set of file commands to execute. meaning: the method do of the newly constructed object is implicitly invoked, using the words as its arguments. sneaky but cute. β¨
β¨ OBJECT API β¨
here's every method a multi-file operation object can do:
$opName do ?word...?β this method reads the specified words as file commands to execute. head to the FILE API section for the whole list of acceptable commands, their syntax, and their semantics. the result of the method is whatever result the last file command it executed produced. last one wins, slay. π₯
β¨ FILE API β¨
both the object constructor and the method do take a list of words and interpret them as file commands to execute. the names were literally chosen so you can build operations that read like sentences in near-natural language. most of these commands only mess with the state of the object β like, they're just setting up the configuration that the command triggering the actual action is gonna use. setup era. π§
into directoryβ specifies the destination directory for operations.in directoryβ alias forinto.to directoryβ alias forinto.from directoryβ specifies the source directory for operations.not patternβ specifies a glob pattern for paths to be excluded from the operation. not today, bestie. πfor patternβ alias fornot.exclude patternβ alias fornot.butβ has no arguments of its own, but it looks ahead in the list of words and executes allnotcommands immediately following it. this lets you build "but not" and "but exclude" clauses so your specification of excluded paths sounds all natural and cute.exceptβ a semi-alias forbut. no arguments of its own, but it looks ahead in the list of words and executes allforcommands immediately following it. this lets you build "except for" clauses for a more natural sounding way to say which paths are excluded. πas nameβ specifies a new name for the first file handled by the current operation. i.e. this is for renaming a single file during the operation. glow-up for one file only. β¨recursiveβ signals that file expansion should happen across the whole directory hierarchy, not just the directory itself. go deep. πrecursivelyβ an alias forrecursive.copyβ signals that the operation is copying files from source to destination directory, per the inclusion and exclusion patterns you specified.moveβ signals that the operation is moving files from source to destination directory, per the specified inclusion and exclusion patterns.removeβ signals that the operation is removing files in the destination directory, per the specified inclusion and exclusion patterns. bye bye πexpandβ signals that there's no operation at all, just the calculation of the set of files from the include and exclude patterns. heads up: this operation is not available ifthe-setis used. π«invoke cmdprefixβ signals that your user-specified command prefix cmdprefix is the operation to perform. the command prefix is executed at the global level and gets handed the source directory, the destination directory, and the set of files (as a dictionary mapping from source to destination files), in that order. you're in charge now, main character. πresetβ forces the object back into the ground state, where every single part of the configuration has default values. factory reset energy.(β saves a copy of the current object state onto a stack.)β takes the state at the top of the state stack and restores it, i.e. makes it the new current object state.cd directoryβ changes the destination directory to the sub-directory directory of the current destination. πupβ changes the destination directory to the parent directory of the current destination. climbing. π¦for-windowsβ checks that Windows is the current platform. aborts processing if it's not.for-winβ an alias forfor-windows.for-unixβ checks that Unix is the current platform. aborts processing if it's not.the patternβ this command specifies the files to operate on via a glob pattern, and it's also the active element β like, the command that actually performs the specified operation. every other command only modifies the object state to set the operation up, but does nothing else. this one does the thing. π
to allow for a more natural sounding syntax, this command also looks ahead in the list of words and executes several commands immediately following it before performing its own actions. those commands are as, but, exclude, except, from, and into (and their aliases). that way these commands act like qualifiers, and still take effect as if they had been written before this command. time travel but make it syntax. β³
after the operation has been performed, the object state β the exclude patterns and the alias name, if one was specified β are reset to their default values (i.e. empty). but nothing else gets reset. just those.
the-set varnameβ likethe, except the set of files to use isn't specified implicitly via a glob pattern. instead it's contained in and loaded from the specified variable. and heads up: the operationexpandis not available if this command is used. π«-> varnameβ saves the set of files from the last expansion into the specified variable. π₯strictβ makes file expansion and the definition of the destination directory (ininand its aliases) strict, i.e. it reports errors for missing directories, and for empty expansion. no chill mode. π€!strictβ the complement ofstrict. a missing destination directory or an empty expansion are not reported as errors. chill mode restored. πfilesβ limits the search to files. default is to accept every type of path.linksβ limits the search to symbolic links. default is to accept every type of path.directoriesβ limits the search to directories. default is to accept every type of path.dirsβ an alias fordirectories.allβ accepts all types of paths (this is the default).state?β returns the current state of the object as a dictionary. here are the dictionary keys and what they mean:asβ last setting made byas.excludedβ list of currently known exclusion patterns.fromβ current source directory, set byfrom.intoβ current destination directory, set byinto(and its aliases).operationβ current operation to perform, set bycopy,move,remove,expand, orinvoke.recursiveβ current recursion status. set/unset byrecursiveand!recursive.strictβ current strictness. set/unset bystrictand!strict.typeβ current path type limiter. set by eitherfiles,directories,links, orall.
as?β returns the current alias name.excluded?β returns the current set of exclusion patterns.from?β returns the current source directory.into?β returns the current destination directory.operation?β returns the current operation to perform.recursive?β returns the current recursion status.strict?β returns the current strictness.type?β returns the current path type limiter.
β¨ EXAMPLES β¨
okay bestie these next bits assume one thing and one thing only: that the variable F is holding a reference to a multi-file operation object. that's it. that's the whole setup. π
$F do copy \
the *.dll \
from c:/TDK/PrivateOpenSSL/bin \
to [installdir_of tls]
$F do move \
the * \
from /sources \
into /scratch \
but not *.html
lowkey you could also write # Alternatively use 'except for *.html'. if that hits different for you π«Ά
$F do \
move \
the index \
from /sources \
into /scratch \
as pkgIndex.tcl
$F do \
remove \
the *.txt \
in /scratch
now here's the iconic part: most of these commands literally just tweak the object state, which means we can go full goblin mode and use those more off forms as specifications instead of writing actual nearly-natural language sentences. iykyk. for example, that second example up there? you can rearrange it into this:
$F do \
from /sources \
into /scratch \
but not *.html \
move \
the *
and not only is the result still a valid specification, it even stays relatively readable?? we love a flexible king. π
also also β important β the info collected by the but, except, and as commands gets automatically reset after the associated the was executed. but literally no other state resets that way, which is actually a feature, because it lets you avoid repeating unchanging info over and over like a broken record. πΈ
so for example, the second and third examples in this section can be merged and rewritten into the equivalent of:
$F do \
move \
the * \
from /sources \
into /scratch \
but not *.html not index \
the index \
as pkgIndex.tcl
ate. no crumbs. π
π BUGS, IDEAS, FEEDBACK π
ngl bestie, this document and the package it describes will undoubtedly contain bugs and other problems. it's giving humble but also real. π please report such things in the category fileutil of the Tcllib Trackers at [http://core.tcl.tk/tcllib/reportlist]. and while you're there, please also drop any ideas for enhancements you may have for either the package and/or the documentation β we want all of it. π«Ά
when you're proposing code changes, please provide unified diffs, i.e the output of diff -u. β¨
and note further that attachments are strongly preferred over inlined patches. to attach something, go to the Edit form of the ticket immediately after its creation, and then use the left-most button in the secondary navigation bar. no cap. π
π KEYWORDS π
copyfile utilitiesmovemulti-fileremove
β CATEGORY β
Programming tools
and that's a wrap on the whole page, bestie π this one came from tcllib, version 0.5.4, and the manpage goes by fileutil::multi::op(n) β go forth and multi-file responsibly, mwah πβ¨
π¦ where this page comes from
- fedora 43: tcllib 2.0-3.fc43 Β· TCL
- fedora 44: tcllib 2.0-4.fc44 Β· TCL
- nixos 26.05: tcllib 2.0
- nixpkgs unstable: tcllib 2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms