Topic: Manipulating Filenames (1 of 5), Read 47 times
Conf: Startup, File Open, Exit
From: Dale Cook
Date: Thursday, June 03, 2004 06:08 PM

Someone may have invented this wheel, but I haven't yet figured it out.

I have a macro that gets a filename from point-and-shoot. I need to take that filename (which is actually a full path) from the text register that it is stored in and alter it - specifically I need to change part of the path so that variants of the original file, created by the macro, can be stored in different directories.

I don't see any way to, say, delete the first "n" characters from a text register. I could stuff the contents of the register into a buffer and edit it there, but how do I get the contents of the buffer back into a text register so I can use it in, say, a File_Save_As() command?

Alternatively, is there anyway to truncate the result of a Get_Filename() using wildcards, so that only the filename and extension are left in the text register, without the rest of the path?

 


Topic: Manipulating Filenames (2 of 5), Read 46 times
Conf: Startup, File Open, Exit
From: Ian Binnie
Date: Thursday, June 03, 2004 09:22 PM

On 6/3/2004 6:08:19 PM, Dale Cook wrote:
>Someone may have invented this
>wheel, but I haven't yet
>figured it out.

I have a
>macro that gets a filename
>from point-and-shoot. I need
>to take that filename (which
>is actually a full path) from
>the text register that it is
>stored in and alter it -
>specifically I need to change
>part of the path so that
>variants of the original file,
>created by the macro, can be
>stored in different
>directories.

I don't see any
>way to, say, delete the first
>"n" characters from a text
>register. I could stuff the
>contents of the register into
>a buffer and edit it there,
>but how do I get the contents
>of the buffer back into a text
>register so I can use it in,
>say, a File_Save_As()
>command?

Alternatively, is
>there anyway to truncate the
>result of a Get_Filename()
>using wildcards, so that only
>the filename and extension are
>left in the text register,
>without the rest of the path?

The following code fragment does not exactly answer your question, but if you have the file open in Vedit it should show how to do what you want.

Reg_Set(30,PATH_ONLY) // path of current file
Reg_Set(30,"\",APPEND)
Reg_Set(30,FILE_ONLY,APPEND) // Name of current file
Reg_Set(30,".",APPEND)
Reg_Set(30,"txt",APPEND)
#105=Buf_Free // temporary buffer
Buf_Switch(#105)
File_Open("|@(30)") // Open "output" file
Buf_Switch(#104)

In the past I had procedures to manipulate file names, but the above is much more convenient.

I could try to dig these up if you like, but even if your file is not open, then opening it just to get the above is probably easier.

 


Topic: Manipulating Filenames (4 of 5), Read 44 times
Conf: Startup, File Open, Exit
From: Dale Cook
Date: Friday, June 04, 2004 04:26 AM

On 6/3/2004 9:22:59 PM, Ian Binnie wrote:

>The following code fragment does not
>exactly answer your question, but if you
>have the file open in Vedit it should
>show how to do what you want.

Ian -

Thanks - that works, but I think Christian's approach is even more elegant.

- Dale

 


Topic: Manipulating Filenames (3 of 5), Read 45 times
Conf: Startup, File Open, Exit
From: Christian Ziemski
Date: Friday, June 04, 2004 03:19 AM

On 6/3/2004 6:08:19 PM, Dale Cook wrote:

> I have a macro that gets a filename from point-and-shoot. I need to
> take that filename (which is actually a full path) from the text
> register that it is stored in and alter it - specifically I need to
> change part of the path so that variants of the original file,
> created by the macro, can be stored in different directories.
>
> I don't see any way to, say, delete the first "n" characters from a
> text register. I could stuff the contents of the register into a
> buffer and edit it there, but how do I get the contents of the
> buffer back into a text register so I can use it in, say, a
> File_Save_As() command?


Get_Filename(90, "*.*")
#103=Buf_Num // remember current buffer
Buf_Switch(Buf_Free) // open temporary buffer
Reg_Ins(90) // insert path+filename
// Begin_Of_File // edit it somehow
// Del_Char(...)
//
Reg_Copy_Block(90, 0, File_Size) // copy the result back to register
Buf_Quit(OK) // close temporary buffer
Buf_Switch(#103) // switch back to original buffer
// File_Save_As("|@(90)") // do something with the modified path+filename



> Alternatively, is there anyway to truncate the result of a
> Get_Filename() using wildcards, so that only the filename and
> extension are left in the text register, without the rest of the
> path?


One possibility using the editing above:


Get_Filename(90, "*.*")
#103=Buf_Num // remember current buffer
Buf_Switch(Buf_Free) // open temporary buffer
Reg_Ins(90) // insert path+filename
Search("|{\,/}", REVERSE+ADVANCE) // search the last path devider
Reg_Copy_Block(91, Cur_Pos, File_Size) // copy filename+ext to register
Buf_Quit(OK) // close temporary buffer
Buf_Switch(#103) // switch back to original buffer



Or another possibility:


Get_Filename(90, "*.*")
#103=Buf_Num // remember current buffer
File_Open("|@(90)") // open the file temporary
Reg_Set(91, FILENAME) // get filename with extension
Buf_Quit(OK) // close it again
Buf_Switch(#103) // switch back to original buffer





Christian

 


Topic: Manipulating Filenames (5 of 5), Read 44 times
Conf: Startup, File Open, Exit
From: Dale Cook
Date: Friday, June 04, 2004 04:30 AM

On 6/4/2004 3:19:22 AM, Christian Ziemski wrote:


>Get_Filename(90, "*.*")
>#103=Buf_Num // remember current buffer
>Buf_Switch(Buf_Free) // open temporary buffer
>Reg_Ins(90) // insert path+filename
>Search("|{\,/}", REVERSE+ADVANCE) // search the last path devider
>Reg_Copy_Block(91, Cur_Pos, File_Size) // copy filename+ext to register
>Buf_Quit(OK) // close temporary buffer
>Buf_Switch(#103) // switch back to original buffer

Christian -

Thanks - that is clean and simple, and works great.

- Dale