Page 1 of 1 1
Topic Options
#9300 - 2001-06-07 04:00 PM Renaming files in a directory
Anonymous
Unregistered


I need kix to move some files from a source-directory to a target-directory and rename them in the process. Now, the moving (copy/delete) part is easy, but how do I get kix to rename a file from an unknown filename to a new generated (@time) filename?
If I have more than one file in a directory and copy them to a new directory using a new generated filename I think each file is given that filename and then is overwritten by the next file as it gets the same name.
Any hints, ideas???

Top
#9301 - 2001-06-07 09:47 PM Re: Renaming files in a directory
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
kram, hi

maybe you can give kixtart's imbedded dir() and copy command a try ...

code:

break on


$sourcedir = "m:\dir1"
$targetdir = "m:\dir2"
$newext = ".new"


$sourcefile = dir("$sourcedir\*.*")


while @error = 0


if $sourcefile


if (getfileattr("$sourcedir\$sourcefile") & 16) = 0


copy "$sourcedir\$sourcefile" "$targetdir\$sourcefile$newext"


endif


endif


$sourcefile = dir()


loop


exit


-Shawn

[This message has been edited by Shawn (edited 07 June 2001).]

Top
#9302 - 2001-06-08 02:30 PM Re: Renaming files in a directory
Anonymous
Unregistered


Hello,

I've tried this script for fun. may be it answers your needs.


break on cls
cls

;---------- variables
;
$dirsrc = "c:\dir_src\" ; source directory
$dirdst = "c:\dir_dst\" ; destination directory
$filename = "new" ; new filename
$count = 1 ; counter
$extension= ".kix" ; new extension filename

;---------- create files list collect.txt
;
del c:\kixtart\collect.txt ; if exist
shell "%comspec% /c dir /b " + $dirsrc + " >> c:\kixtart\collect.txt"

;---------- start read files list
del $dest + "*.*" ; empty the destination directory
if open (1, "c:\kixtart\collect.txt", 2) = 0
$readfile = readline (1)

;---------- start copy / rename
while @error = 0

$1ST = LTRIM(SUBSTR(@time, 1, 2)) ; hour
$2ND = LTRIM(SUBSTR(@time, 4, 2)) ; minute
$3RD = LTRIM(SUBSTR(@time, 7, 2)) ; second
$number = $1ST + $2ND + $3RD ; time for filename

copy $dirsrc + $readfile $dirdst + $filename + $number + $count + $extension ; action

$count = $count + 1
$readfile = readline (1)
loop
;---------- end copy /rename

close (1)
endif
;
;


Happy test
PhilV

Top
#9303 - 2001-06-08 02:35 PM Re: Renaming files in a directory
Anonymous
Unregistered


Hello !


hum ... error :

;---------- start read files list
del $dest + "*.*" ; empty the destination directory


replace with :

;---------- start read files list
del $dirdst + "*.*" ; empty the destination directory


sorry.
PhilV

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 675 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.081 seconds in which 0.012 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org