Page 1 of 2 12>
Topic Options
#46540 - 2003-10-10 06:50 PM Rename File into a Single File Extension
cglccb Offline
Fresh Scripter

Registered: 2003-10-10
Posts: 6
[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 ]

Top
#46541 - 2003-10-10 07:02 PM Re: Rename File into a Single File Extension
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
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.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#46542 - 2003-10-10 07:03 PM Re: Rename File into a Single File Extension
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
code:
rename *.apd* *.apd

from the command prompt might work.
_________________________
There are two types of vessels, submarines and targets.

Top
#46543 - 2003-10-10 07:14 PM Re: Rename File into a Single File Extension
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
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 ]
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#46544 - 2003-10-10 07:23 PM Re: Rename File into a Single File Extension
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
Yeah, he definitely did not read all the responses.
_________________________
There are two types of vessels, submarines and targets.

Top
#46545 - 2003-10-10 07:45 PM Re: Rename File into a Single File Extension
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
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 ]

Top
#46546 - 2003-10-10 07:54 PM Re: Rename File into a Single File Extension
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
You just need to put the MOVE into it [Wink]
_________________________
There are two types of vessels, submarines and targets.

Top
#46547 - 2003-10-10 08:03 PM Re: Rename File into a Single File Extension
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
LOL forgot the command. I edited the code to include the REN
Top
#46548 - 2003-10-12 09:11 PM Re: Rename File into a Single File Extension
cglccb Offline
Fresh Scripter

Registered: 2003-10-10
Posts: 6
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]

Top
#46549 - 2003-10-13 04:28 AM Re: Rename File into a Single File Extension
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
[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.
_________________________
There are two types of vessels, submarines and targets.

Top
#46550 - 2003-10-13 05:09 AM Re: Rename File into a Single File Extension
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
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.

Top
#46551 - 2003-10-13 03:32 PM Re: Rename File into a Single File Extension
cglccb Offline
Fresh Scripter

Registered: 2003-10-10
Posts: 6
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]

Top
#46552 - 2003-10-13 03:38 PM Re: Rename File into a Single File Extension
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
Why not create the directorynames based on the [DateRun] values?
_________________________
There are two types of vessels, submarines and targets.

Top
#46553 - 2003-10-13 04:13 PM Re: Rename File into a Single File Extension
cglccb Offline
Fresh Scripter

Registered: 2003-10-10
Posts: 6
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]
Top
#46554 - 2003-10-13 04:15 PM Re: Rename File into a Single File Extension
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
If the date/time is stamped into the extension, why not just rip it from the extension?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#46555 - 2003-10-13 04:26 PM Re: Rename File into a Single File Extension
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
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

_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#46556 - 2003-10-13 04:26 PM Re: Rename File into a Single File Extension
cglccb Offline
Fresh Scripter

Registered: 2003-10-10
Posts: 6
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.
Top
#46557 - 2003-10-13 04:33 PM Re: Rename File into a Single File Extension
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Come to think of it, better to split() on the '_'.

$ext = Split($file,'_')
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#46558 - 2003-10-13 05:27 PM Re: Rename File into a Single File Extension
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
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.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#46559 - 2003-10-13 06:08 PM Re: Rename File into a Single File Extension
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
quote:

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

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

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
Page 1 of 2 12>


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

Who's Online
1 registered (Allen) and 466 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.074 seconds in which 0.026 seconds were spent on a total of 13 queries. Zlib compression enabled.

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