egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

change filenames

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
glennsftn
Voice


Joined: 23 Mar 2015
Posts: 2

PostPosted: Mon Mar 23, 2015 11:26 pm    Post subject: change filenames Reply with quote

Please excuse my noobiness, I’ve just been learning TCL a few days now and have little coding experience except a rudimentary understanding of Expect.

I have a NAS with a bunch of files that I’d like to rename. I want to create a script which will generate the commands to name the files from “this” to “that.” Below is a quick example of how I’m going about this.


Code:
#!/usr/bin/tcl

set src1 myfilename1.txt
set src2 myfilename2.txt
set src3 myfilname3.txt
set dst1 mynewfilename1.txt
set dst2 mynewfilename2.txt
set dst3 mynewfilename3.txt
set count 0
set log [open output.txt w]


while { $count < 4 } {
   set count [incr $count]
   set srcName "src$count"
   set dstName "dst$count"
   puts $log "mv $srcName $dstName"
}

close $log


What I would like the output.txt to be is:

mv myfilename1.txt mynewfilename1.txt
..
..
mv myfilename4.txt mynewfilename4.txt


The actual output:
$ cat output.txt
mv src1 dst1
mv src1 dst1
mv src2 dst2
mv src1 dst1
mv src3 dst3
mv src1 dst1
mv src4 dst4
Back to top
View user's profile Send private message
heartbroken
Op


Joined: 23 Jun 2011
Posts: 106
Location: somewhere out there

PostPosted: Tue Mar 24, 2015 1:08 am    Post subject: Reply with quote

actualy "mv" not a Tcl command. ( http://www.tcl.tk/man/tcl8.6/TclCmd/contents.htm ) you can use file rename : http://www.tcl.tk/man/tcl/TclCmd/file.htm - http://wiki.tcl.tk/10083
_________________
Life iS Just a dReaM oN tHE wAy to DeaTh


Last edited by heartbroken on Tue Mar 24, 2015 1:17 am; edited 1 time in total
Back to top
View user's profile Send private message
SpiKe^^
Owner


Joined: 12 May 2006
Posts: 792
Location: Tennessee, USA

PostPosted: Tue Mar 24, 2015 1:16 am    Post subject: Reply with quote

Maybe this is closer to what you say you want...
Code:
#!/usr/bin/tcl

set src(1) "myfilename1.txt"
set src(2) "myfilename2.txt"
set src(3) "myfilname3.txt"
set dst(1) "mynewfilename1.txt"
set dst(2) "mynewfilename2.txt"
set dst(3) "mynewfilename3.txt"
set count 0
set log [open output.txt w]


while {$count < 3} {
   incr count
   set srcName $src($count)
   set dstName $dst($count)
   puts $log "mv $srcName $dstName"
}

close $log



You should probably have the tcl script actually do the file renaming, and as mentioned above, mv is not a tcl command:)
_________________
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
Back to top
View user's profile Send private message Visit poster's website
glennsftn
Voice


Joined: 23 Mar 2015
Posts: 2

PostPosted: Tue Mar 24, 2015 1:14 pm    Post subject: Reply with quote

Thanks guys,

That is exactly what I wanted. The output was to go to a text file which I could copy/paste into an SSH session. It would have been ideal to write this in Expect, as I could send the commands I want within the SSH session, but I didn't know how to do the loop with the variables. I think I have enough now to migrate this over to Expect. I appreciate the help.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber