This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

auto rename file

Old posts that have not been replied to for several years.
Locked
r
ribbon
Voice
Posts: 4
Joined: Mon Jun 28, 2004 1:33 pm
Location: belgium
Contact:

auto rename file

Post by ribbon »

can i let rename the eggdrop a file name at the begin of a new mounth ?

Code: Select all

#qoutefile
set qoutefile "/home/ribbon/quote/qoute.txt" 
#binds
bind time - "00 00 01 * *" qoute_ren
now i have to save each time at the begin of the mounth the old file like
quote.jan, qoute.feb, ...
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

Code: Select all

#setting the filename ur about to change
set filename "yourfile"

#bind time <flags> <mask> <proc>
bind time - "00 00 00 ?? *" file_rename

#proc-name <minute> <hour> <day> <month> <year>
proc file_rename {min hour day month year} {
  global filename
  file rename $filename $filename.[clock format [clock seconds] -format {%B}]; #tolower %B if u want short month name
}
not tested reply if errors occure and include the errormsg
XplaiN but think of me as stupid
T
TammeN
Voice
Posts: 4
Joined: Fri Dec 24, 2004 12:39 am
Location: Belgium

How To rename more than one file at the same time

Post by TammeN »

Nice Script, but how to rename more than one file at the same time ?

Tnx
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Re: How To rename more than one file at the same time

Post by demond »

TammeN wrote:Nice Script, but how to rename more than one file at the same time ?

Tnx
by using the rename command more than once?
T
TammeN
Voice
Posts: 4
Joined: Fri Dec 24, 2004 12:39 am
Location: Belgium

Post by TammeN »

no, 1 rename command and it renames 3a4 files
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

TammeN wrote:no, 1 rename command and it renames 3a4 files
"3a4" files? 3 or 4 files?

the [file rename] command operates on multiple files only to move the whole pack to another directory

so, why wouldn't you want to use multiple rename commands, as many as needed?
T
TammeN
Voice
Posts: 4
Joined: Fri Dec 24, 2004 12:39 am
Location: Belgium

Post by TammeN »

3 files!

to move to another directory is also OK!
the files are from a game, i don't want to reset them but rename or move to keep them for he site!
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

some Tcl docs guy wrote: file rename ?-force? ?- -? source target

file rename ?-force? ?- -? source ?source ...? targetDir

The first form takes the file or directory specified by pathname source and renames it to target, moving the file if the pathname target specifies a name in a different directory. If target is an existing directory, then the second form is used. The second form moves each source file or directory into the directory targetDir. Existing files will not be overwritten unless the -force option is specified. When operating inside a single filesystem, Tcl will rename symbolic links rather than the things that they point to. Trying to overwrite a non-empty directory, overwrite a directory with a file, or a file with a directory will all result in errors. Arguments are processed in the order specified, halting at the first error, if any. A - - marks the end of switches; the argument following the - - will be treated as a source even if it starts with a -.
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

there is 2 ways to do this .. either its a private dir for only those files then you can use glob other wize you can make a list and use foreach..

Code: Select all

#setting the filename ur about to change
set filename "yourfile,file2,file3"

#bind time <flags> <mask> <proc>
bind time - "00 00 00 ?? *" file_rename

#proc-name <minute> <hour> <day> <month> <year>
proc file_rename {min hour day month year} {
  global filename
  foreach {x} [split $filename \x2C] {
    file rename $x $x.[clock format [clock seconds] -format {%B}]; #tolower %B if u want short month name
  }
}

Code: Select all

#setting the path
set path "/path/to/private/dir"

#bind time <flags> <mask> <proc>
bind time - "00 00 00 ?? *" file_rename

#proc-name <minute> <hour> <day> <month> <year>
proc file_rename {min hour day month year} {
  global path
  foreach {x} [glob -nocomplain -types f -directory $path *] {
    file rename $x $x.[clock format [clock seconds] -format {%B}]; #tolower %B if u want short month name
  }
}

first method will rename every file you provide in that list ..

second method will rename every file in that directory..

to move em to an other dir check out file rename as mentioned above by changing the target path..
XplaiN but think of me as stupid
Locked