filename change and extraxct 5 char from name
Moderators: Dorian (MJT support), JRL
filename change and extraxct 5 char from name
Hello
new topic .... and im gettin or better to say im already addicted to MS
I have a file, it has a filename like asdf_xxxx_assd.DAT
And the x can change from 4 till 8 times x, like : asdf_xxxxxxxx_assd.DAT
I have another file, this one i want to rename into xref_xxxxx.DAT, where the xxxxx is the one from the otherfile.
Is this possible ?
I checked out Position, Length and so on, but since the amount of x changes im stuck at the moment.
Any help or tipps ?
Thanx in advance
new topic .... and im gettin or better to say im already addicted to MS
I have a file, it has a filename like asdf_xxxx_assd.DAT
And the x can change from 4 till 8 times x, like : asdf_xxxxxxxx_assd.DAT
I have another file, this one i want to rename into xref_xxxxx.DAT, where the xxxxx is the one from the otherfile.
Is this possible ?
I checked out Position, Length and so on, but since the amount of x changes im stuck at the moment.
Any help or tipps ?
Thanx in advance
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
This is the long-winded, but probably easier to understand, method:
Change the value of fname and it will always extract the part between the underscores.
Code: Select all
//play around with different values between the underscores
Let>fname=asdf_123456_assd.DAT
//extract the part between the underscores (_)
Position>_,fname,1,start
Let>start=start+1
Length>fname,lf
MidStr>fname,start,lf,temp
Position>_,temp,1,end
Let>end=end-1
MidStr>temp,1,end,midPart
Let>newfile=xref_%midPart%.DAT
MessageModal>newfile
//RenameFile>sourcefile,newfile
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
This is what i finished, the only thing is maybe that if there are more DAT files in the directory, but it still works :-) ;-)
---------------------------------------------------------------------------------
---------------------------------------------------------------------------------
GetFileList>c:\directory\*.DAT,aantal,;
Let>fname=%aantal%
//extract the part between the underscores (_)
Position>_,fname,1,start
Let>start=start+1
Length>fname,lf
MidStr>fname,start,lf,temp
Position>.,temp,1,end
Let>end=end-1
MidStr>temp,1,end,midPart
Let>newfile=XREF_%midPart%.DAT
RenameFile>c:\directory\XREF.DAT,c:\directory\%newfile%
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
Thanx again for the help :-) ;-)
---------------------------------------------------------------------------------
---------------------------------------------------------------------------------
GetFileList>c:\directory\*.DAT,aantal,;
Let>fname=%aantal%
//extract the part between the underscores (_)
Position>_,fname,1,start
Let>start=start+1
Length>fname,lf
MidStr>fname,start,lf,temp
Position>.,temp,1,end
Let>end=end-1
MidStr>temp,1,end,midPart
Let>newfile=XREF_%midPart%.DAT
RenameFile>c:\directory\XREF.DAT,c:\directory\%newfile%
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
Thanx again for the help :-) ;-)
Ok,
now it doesnt work so well as i thought......
this is the error...
i have 5 files with different start names but the same ID(but the ID ispossible from 3 till 8)
Like :
abc_ID1_ID2.dat
def_ID1_ID2.dat
ghi_ID1_ID2.dat
jkl_ID1_ID2.dat
mno_ID1_ID2.dat
XREF.dat
I want to rename that XREF.dat into XREF_ID1_ID2.dat
What i tried was to get the first file, takeout the ID1 and ID2.
I did that with :
---------------------------------------------------------------------------------
GetFileList>c:\directory\*.DAT,aantal,;
Let>fname=%aantal%
Position>_,fname,1,start
Let>start=start+1
Length>fname,lf
MidStr>fname,start,lf,temp
Position>.,temp,1,end
Let>end=end-1
MidStr>temp,1,end,midPart
Let>newfile=XREF_%midPart%.DAT
RenameFile>c:\directory\XREF.DAT,c:\directory\%newfile%
-----------------------------------------------------------------------------
But ... as MS it works somehow, but if i compile it into an exe it gives an error
As you maybe can think im a beginner, so my "coding" if you can speak of it is more the less very basic, but im triing ;-)
Maybe some thoughts ?
now it doesnt work so well as i thought......
this is the error...
i have 5 files with different start names but the same ID(but the ID ispossible from 3 till 8)
Like :
abc_ID1_ID2.dat
def_ID1_ID2.dat
ghi_ID1_ID2.dat
jkl_ID1_ID2.dat
mno_ID1_ID2.dat
XREF.dat
I want to rename that XREF.dat into XREF_ID1_ID2.dat
What i tried was to get the first file, takeout the ID1 and ID2.
I did that with :
---------------------------------------------------------------------------------
GetFileList>c:\directory\*.DAT,aantal,;
Let>fname=%aantal%
Position>_,fname,1,start
Let>start=start+1
Length>fname,lf
MidStr>fname,start,lf,temp
Position>.,temp,1,end
Let>end=end-1
MidStr>temp,1,end,midPart
Let>newfile=XREF_%midPart%.DAT
RenameFile>c:\directory\XREF.DAT,c:\directory\%newfile%
-----------------------------------------------------------------------------
But ... as MS it works somehow, but if i compile it into an exe it gives an error
As you maybe can think im a beginner, so my "coding" if you can speak of it is more the less very basic, but im triing ;-)
Maybe some thoughts ?
Ok, now i got a solution, but also a problem :
I did it now different, i did a readout of the file and the proper position.
I got the info i needed.
--------------------------------------------------------------------
--------------------------------------------------------------------
ReadLn>C:\directory\XREF.DAT,3,text
MidStr>text,69,11,show
Let>rest=show
//MessageModal>show
Position>\,rest,1,start
Let>start=start+1
Length>rest,lf
MidStr>rest,start,lf,temp
Position>.,temp,1,end
Let>end=end-1
MidStr>temp,1,end,midPart
Let>newfile=%midPart%
//MessageModal>newfile
RenameFile>C:\directory\XREF.DAT,C:\directory\XREF_1_%newfile%.DAT
---------------------------------------------------------------------
---------------------------------------------------------------------
As a macro i works, but as soon as i convert it into an exe-file it doesnt work, could someone help me why this is ?
Aspecially the rename function doesnt work !!
I did it now different, i did a readout of the file and the proper position.
I got the info i needed.
--------------------------------------------------------------------
--------------------------------------------------------------------
ReadLn>C:\directory\XREF.DAT,3,text
MidStr>text,69,11,show
Let>rest=show
//MessageModal>show
Position>\,rest,1,start
Let>start=start+1
Length>rest,lf
MidStr>rest,start,lf,temp
Position>.,temp,1,end
Let>end=end-1
MidStr>temp,1,end,midPart
Let>newfile=%midPart%
//MessageModal>newfile
RenameFile>C:\directory\XREF.DAT,C:\directory\XREF_1_%newfile%.DAT
---------------------------------------------------------------------
---------------------------------------------------------------------
As a macro i works, but as soon as i convert it into an exe-file it doesnt work, could someone help me why this is ?
Aspecially the rename function doesnt work !!