Author |
Topic: Renaming files (Read 611 times) |
|
KenDown
Full Member
member is offline


Posts: 181
|
 |
Re: Renaming files
« Reply #3 on: Nov 10th, 2011, 09:20am » |
|
The main problem you are going to face is the limit in OSCLI of 256 characters. If the filename (including the path name) is longer than about 123 then the command
OSCLI("RENAME "+old$+" "+new$)
is going to exceed the 256 character limit and you will get an error message. It's very frustrating.
I've bodged it by having two RENAMEs
OSCLI("RENAME "+old$+" D:temp."+type$) OSCLI("RENAME D:temp."+type$+" "+new$)
You'll have to find type$, but that is simply RIGHT$(old$,3)
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: Renaming files
« Reply #4 on: Nov 10th, 2011, 10:42am » |
|
on Nov 10th, 2011, 09:20am, KenDown wrote:I've bodged it by having two RENAMEs
OSCLI("RENAME "+old$+" D:temp."+type$) OSCLI("RENAME D:temp."+type$+" "+new$)
You'll have to find type$, but that is simply RIGHT$(old$,3) |
|
Surely type$ can be anything (e.g. tmp), but a much simpler solution is to use the Windows API:
Code:SYS "MoveFile", old$, new$ I almost invariably use that in preference to OSCLI "RENAME".
Richard.
|
|
Logged
|
|
|
|
Orpheus2000
New Member
member is offline


Posts: 3
|
 |
Re: Renaming files
« Reply #5 on: Nov 10th, 2011, 2:37pm » |
|
[quote]You'll have to find type$, but that is simply RIGHT$(old$,3) [quote]
This isn't always true, e.g. .docx, .html
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: Renaming files
« Reply #6 on: Nov 10th, 2011, 4:18pm » |
|
on Nov 10th, 2011, 2:37pm, Orpheus2000 wrote: Quote:| You'll have to find type$, but that is simply RIGHT$(old$,3) |
|
This isn't always true, e.g. .docx, .html |
|
It will still work though. Since type$ can be anything, if it's ocx instead of docx, or tml instead of html, it won't make any difference. However it's obviously easier to set it to something constant like tmp than to bother with deriving it from the original filename. After all, the temporary file only exists for a very short time.
But using SYS "MoveFile" avoids the use of a temporary file altogether.
Richard.
|
|
Logged
|
|
|
|
|