cglccb
(Fresh Scripter)
2003-10-10 06:50 PM
Rename File into a Single File Extension

[Moderator (Sealeopard): Moved thread from 'Scripts' to 'Starters' forum due to lack of script in body]

KiXtart 3.63/95

Can anybody help on how to rename files having extensions when the files was created. Sample files below;
(They are saved in the same directory)

GREG_PKTFILE.APD_07122002171327 ---> Renamed as GREG_PKTFILE.APD
GREG_QTYPERFILE.APD_07122002171327 ---> Renamed as GREG_QTYPERFILE.APD
GREG_WLOTFILE.APD_07122002171327 ---> Renamed as GREG_WLOTFILE.APD

GREG_PKTFILE.APD_07122002171527 ---> Same as above filename
GREG_QTYPERFILE.APD_07122002171527 ---> Same as above filename
GREG_WLOTFILE.APD_07122002171527 ---> Same as above filename

My problem here is how to rename files in such a way that i can create 3 files mentioned above and ftp the 3 files.
Appreciate someone's help - Thank you.

Greg

[ 10. October 2003, 18:58: Message edited by: sealeopard ]


Howard Bullock
(KiX Supporter)
2003-10-10 07:02 PM
Re: Rename File into a Single File Extension

If you are doing this task yourself, then I would recommend using KiXtart 4.21 as it has much better capablilites that would make you file name manipulation much easier.

Could you use 4.21? Let us know so that we can better assist you.


Sealeopard
(KiX Master)
2003-10-10 07:03 PM
Re: Rename File into a Single File Extension

code:
rename *.apd* *.apd

from the command prompt might work.


Kdyer
(KiX Supporter)
2003-10-10 07:14 PM
Re: Rename File into a Single File Extension

Did you not get my response from
Renaming Files with Different Extension
on October 1?

This should work for you..

You should get version 4.21 of KiXtart and use the MOVE Command to Rename files.

Kent

[ 10. October 2003, 19:17: Message edited by: kdyer ]


Sealeopard
(KiX Master)
2003-10-10 07:23 PM
Re: Rename File into a Single File Extension

Yeah, he definitely did not read all the responses.

NTDOCAdministrator
(KiX Master)
2003-10-10 07:45 PM
Re: Rename File into a Single File Extension

This will work with KiX 3.x and 4.x just as Jens said.





SHELL '%COMSPEC% /C "REN path\*.apd* *.apd" >NUL 2>NUL'
? 'Result was: '+@ERROR+' '+@SERROR



[ 10. October 2003, 20:02: Message edited by: NTDOC ]


Sealeopard
(KiX Master)
2003-10-10 07:54 PM
Re: Rename File into a Single File Extension

You just need to put the MOVE into it [Wink]

NTDOCAdministrator
(KiX Master)
2003-10-10 08:03 PM
Re: Rename File into a Single File Extension

LOL forgot the command. I edited the code to include the REN

cglccb
(Fresh Scripter)
2003-10-12 09:11 PM
Re: Rename File into a Single File Extension

Does this code:

SHELL '%COMSPEC% /C "REN path\*.apd* *.apd" >NUL 2>NUL'
? 'Result was: '+@ERROR+' '+@SERROR

------------------
will it not create conflict if i have many of those 3 files i've created. Let us say that i have 150 files in one directory and the only different is its files extensions having the following samples;

GREG_PKTFILE.APD_10062003153155
GREG_PKTFILE.APD_10062003160529
GREG_PKTFILE.APD_10062003171459
GREG_PKTFILE.APD_10062003172522
GREG_PKTFILE.APD_10062003190028
GREG_PKTFILE.APD_10072003094000
GREG_QTYPERFILE.APD_10062003153155
GREG_QTYPERFILE.APD_10062003160529
GREG_QTYPERFILE.APD_10062003171459
GREG_QTYPERFILE.APD_10062003172522
GREG_QTYPERFILE.APD_10062003190028
GREG_QTYPERFILE.APD_10072003094000
GREG_QTYPERFILE.APD_10072003102554
GREG_WLOTFILE.APD_10062003172522
GREG_WLOTFILE.APD_10062003190028

Considering files above..my purpose is when i found files having same file extension, i will rename those file by just removing _{DateRun} and the renamed files will only have the extension of .APD . How will i do this?.

Thank you [Smile]


Sealeopard
(KiX Master)
2003-10-13 04:28 AM
Re: Rename File into a Single File Extension

[Confused] [Confused] Are you sure you know what you're doing? If you have two files with the same filename but different extensions and you make the extensions the same, then one file will overwrite the other one as you can only have a single file per filename [Confused]

There is a reason you have [d]different[/b] fileextensions as the numbers most likely represent timestamps.


NTDOCAdministrator
(KiX Master)
2003-10-13 05:09 AM
Re: Rename File into a Single File Extension

Hi cglccb,

I'm not sure what you are really trying to accomplish here as you only seem to dole out littple pices of the pie.

I LOVE KiXtart and if you were just looking for the challenge of doing this in KiXtart to increase your knowledge of scripting that would be cool. However, I assume you really want to complete this task more so then learn more of the inner working of KiXtart.

There are certain tasks that even though they can be performed with KiXtart it is not optimal to perform with KiXtart.

A mass file rename is something I would consider in that category.

Please take a look at this FREE utility for performing just about any type of mass file rename you can think of.

Rename files at once. One of the most powerful renamers. And it's freeware

Aside from that, If I get bored I may attempt to write something in KiX just to exercise and learn more about KiX, but don't hold your breath. Rather use the tool above or search for your own tool on Google.com or some other location.


cglccb
(Fresh Scripter)
2003-10-13 03:32 PM
Re: Rename File into a Single File Extension

Ok, thanks for your help guys, anyway..what i will have to do here is to compare files that created the same time, anyway the other program that created those files will only create 3 files and will only differ from the 3 other files by just the date it rans.

GREG_PKTFILE .APD_[DateRun]
GREG_QTYPERFILE .APD_[DateRun]
GREG_WLOTFILE .APD_[DateRun]

I will have compare filetime created, and if i found file having same time of creation, i will have to move those files to a different directory, and there i renamed or removed extension when it was ran.

So the output would then be;

GREG_PKTFILE.APD
GREG_QTYPERFILE.APD
GREG_WLOTFILE.APD

[Wink] [Wink]


Sealeopard
(KiX Master)
2003-10-13 03:38 PM
Re: Rename File into a Single File Extension

Why not create the directorynames based on the [DateRun] values?

cglccb
(Fresh Scripter)
2003-10-13 04:13 PM
Re: Rename File into a Single File Extension

Is it necessary for me to do a filetime compare for a file?..i'm a bit new for kix and i'm not that much good in programming. Can anybody give me a sample code on how to do that..Thanks you. [Smile] [Smile]

Les
(KiX Master)
2003-10-13 04:15 PM
Re: Rename File into a Single File Extension

If the date/time is stamped into the extension, why not just rip it from the extension?

Les
(KiX Master)
2003-10-13 04:26 PM
Re: Rename File into a Single File Extension

Here is some code to get you started.


Break ON
$Dir = 'GREG_PKTFILE.APD_10062003153155',
'GREG_PKTFILE.APD_10062003160529',
'GREG_PKTFILE.APD_10062003171459',
'GREG_PKTFILE.APD_10062003172522',
'GREG_PKTFILE.APD_10062003190028',
'GREG_PKTFILE.APD_10072003094000',
'GREG_QTYPERFILE.APD_10062003153155',
'GREG_QTYPERFILE.APD_10062003160529',
'GREG_QTYPERFILE.APD_10062003171459',
'GREG_QTYPERFILE.APD_10062003172522',
'GREG_QTYPERFILE.APD_10062003190028',
'GREG_QTYPERFILE.APD_10072003094000',
'GREG_QTYPERFILE.APD_10072003102554',
'GREG_WLOTFILE.APD_10062003172522',
'GREG_WLOTFILE.APD_10062003190028'

For each $file in $dir
  $ext = Split($file,'.')
  $ext[ubound($ext)] ?
Next



cglccb
(Fresh Scripter)
2003-10-13 04:26 PM
Re: Rename File into a Single File Extension

That's I want to do with the script i'll have to rip time stamp. So after i ripped it, i'll have to ftp those 3 files and remove ripped files after ftp then do a loop for the rest of the files.

Les
(KiX Master)
2003-10-13 04:33 PM
Re: Rename File into a Single File Extension

Come to think of it, better to split() on the '_'.

$ext = Split($file,'_')


Les
(KiX Master)
2003-10-13 05:27 PM
Re: Rename File into a Single File Extension

Well, so far we squandered 18 posts worth of korg bb time... [Frown]

Ok, now that the req's are clearer, let me outline what you probably should do.

You need to get all the files into an array for ease of use. Jooel's DirScan() - yet another dir UDF will do this.

Using the principle I outlined in my previous example, Split() the date/time off the extension.

Use the KiX move command to rename the file to lose the extension. Using the same Split() results that got you the date/time, you can Join() all but the last element with Ubound()-1 to get the filename and extension sans the date/time.

Not sure if there is an FTP send UDF, but I did find Jooel's FTPget() - download a file that you can use as a basis to build your own send UDF.

Move the file to another folder and repeat. I would create folders named after the extension with the date/time stamp and move them there. One cannot always rely on FTP to send the file. I guess you could do a list on the FTP site to confirm.

I still don't understand the req's 100%. There are files with the same name but different extensions due to the date/time stamp. Do all the files need to be sent or only the most recent? If the older one never gets sent, does the newer one still make the older one redundant? Seems to me some sort of compare is needed, but the rules are unclear.


Kdyer
(KiX Supporter)
2003-10-13 06:08 PM
Re: Rename File into a Single File Extension

quote:

$ext = Split($file,'_')

Sheesh.. Did I not recommend that on 1 October over at http://www.kixscripts.com ?

Kent


NTDOCAdministrator
(KiX Master)
2003-10-13 06:23 PM
Re: Rename File into a Single File Extension

And if he would use the program mentioned above on Oct 1st (had he known abou it) he would be done already.

He would not have learned more about KiX scripting, but he would have completed the job by now.


cglccb
(Fresh Scripter)
2003-10-14 05:52 PM
Re: Rename File into a Single File Extension

Thank all for the help, i made a work around just to resolve my problem..i will have to post my code once i finish it.

Thank you.
[Wink]