daved
New Member
Posts: 24
|
Post by daved on Jan 27, 2022 15:22:09 GMT -5
GUI elements:
listbox #main.listbox, filearray$(, [selList]
textbox #main.renamebox
button #main.renbut, "Rename File", [ren]
button #main.renbut2, "Rename Now", [ren2]
Procedure:
1. load #main.filearray$ with a list of full pathnames (c:\dir\filename.ext)
2. select a pathname in #main.listbox
3. Select the #main.renbut button to get the selected pathname from the listbox using:
#main.listbox "selection? sel$"
5. Print sel$ in #main.renamebox textbox
It displays as "c:\dir\filename.ext"
6. Change the filename in #main.renamebox to: "c:\dir\New_filename.ext"
7. Click the #main.renbut2 Rename Now button using:
print #main.renbox, "!contents? newname$" (newname$ is now "c:\dir\New_filename.ext" NAME sel$ as newname$
This procedure works unless there is a space in sel$ (the original filename).
Works: NAME "c:\dir\filename.ext" as "c:\dir\New_filename.ext"
Fails: Works: NAME "c:\dir\file name.ext" as "c:\dir\New_filename.ext"
Runtime Eror: OS Error: The filename, directory name, or volume label syntax is incorrect.
(See error.log for more information)
|
|
|
Post by Brandon Parker on Jan 27, 2022 18:21:20 GMT -5
Here's some code that should work for you...
Global False : False = 0 Global True : True = 1
oldFilename$ = "c:\dir\file name.ext" newFilename$ = "c:\dir\New_filename.ext"
result = CopyFile(oldFilename$, newFilename$, True)
result = DeleteFile(oldFilename$) Wait
'_________________________________________________________________________________________________________________________________________________________ '_________________________________________________________________________________________________________________________________________________________
Function CopyFile(sourceFileName$, targetFileName$, bFailIfExists) sourceFileName$ = sourceFileName$ + chr$(0) : targetFileName$ = targetFileName$ + chr$(0) CallDLL #kernel32, "CopyFileA", sourceFileName$ As ptr, _ targetFileName$ As ptr, _ bFailIfExists As long, _ CopyFile As long End Function
'_________________________________________________________________________________________________________________________________________________________ '_________________________________________________________________________________________________________________________________________________________
Function DeleteFile(lpFileName$) lpFileName$ = lpFileName$ + chr$(0) CallDLL #kernel32, "DeleteFileA", lpFileName$ As ptr, _ DeleteFile As long End Function
{:0)
Brandon Parker
|
|
|
Post by Rod on Jan 28, 2022 3:13:58 GMT -5
I wonder if this is the same issue as we find with the RUN command. If there is a space in the path/file name it is seen as a terminator and shortens the path. The solution is to surround sel$ with quote characters.
So try chr$(34)+sel$+chr$(34)
Not at my pc so let us know how you get on. If I recall correctly Windows at one point in its life did not allow spaces in a file name I think it is a legacy of that but not sure.
|
|
|
Post by tsh73 on Jan 28, 2022 5:50:05 GMT -5
I tried on Win10
It changed error from "file not found" to "syntax error in a name of file"
I did that via DOS RENAME, but it is kind of ugly. And rename does not supports different path for a new name.
name2$="file with sps.txt" name2$=chr$(34)+name2$+ chr$(34) 'doesn't work without quotes around print ">";name2$;"<" print "cmd.exe /c cd "; DefaultDir$;" && rename "; name2$ ;" file_wo_sps.txt" run "cmd.exe /c cd "; DefaultDir$;" && rename "; name2$ ;" file_wo_sps.txt"
|
|
|
Post by Rod on Jan 28, 2022 8:01:39 GMT -5
I wonder now if it is the use of the name “file”?
|
|
|
Post by Brandon Parker on Jan 28, 2022 9:03:30 GMT -5
I wonder now if it is the use of the name “file”? I tried several scenarios on my Windows 10 machine with a different file and received similar errors. That is why I posted an API solution... Another API option is to simply use the MoveFileA() function, but you know...options are always good. Here is MoveFileA() at MSDN... oldFilename$ = "c:\dir\file name.ext" newFilename$ = "c:\dir\New_filename.ext"
result = MoveFile(oldFilename$, newFilename$) Wait
Function MoveFile(lpExistingFileName$, lpNewFileName$) lpExistingFileName$ = lpExistingFileName$ + chr$(0) : lpNewFileName$ = lpNewFileName$ + chr$(0) CallDLL #kernel32, "MoveFileA", lpExistingFileName$ As ptr, _ lpNewFileName$ As ptr, _ MoveFile As long End Function {:0) Brandon Parker
|
|
|
Post by Rod on Jan 28, 2022 9:47:14 GMT -5
OK Back at my PC all of these lines work for me
'NAME "c:\atemp\New filename.ext" as "c:\atemp\New filename1.ext" 'f$="c:\atemp\New filename1.ext" nf$="c:\atemp\New filename2.ext" 'NAME f$ as nf$ NAME nf$ as "c:\atemp\file name3.ext"
So I can have a space in the literal name or a space in the variable name they all NAME for me? What am I missing?
|
|
|
Post by Brandon Parker on Jan 28, 2022 14:11:18 GMT -5
So I can have a space in the literal name or a space in the variable name they all NAME for me? What am I missing? What version of Windows are you working on? {:0) Brandon Parker
|
|
|
Post by Rod on Jan 28, 2022 14:20:19 GMT -5
I suspect the original error log from the OP might be more revealing. We would have heard of this problem before now. I suspect the file already exists or the directory does not exist. So to name a file we need the original file to exist, the new directory to exist and the new dir/file NOT to exist. Win10 bang up to date is what I am on.
|
|
daved
New Member
Posts: 24
|
Post by daved on Jan 28, 2022 14:20:26 GMT -5
Thanks for the suggestions. I think I'll try the movefile API code and see how that works.
To reply to some queries in the answers here: Both oldname$ and newname$ are already quoted in the name command. I made routine that removes the quotes from oldname$ and it still fails.
The immediate mode command: name oldname$ as newname$ works in the IDE It throws the error at runtime when oldname$ is taken from the listbox and newname$ is taken from the textbox. then name oldname$ as newname$ fails.
|
|
|
Post by Rod on Jan 28, 2022 14:26:04 GMT -5
Then we have a simple coding error, but if you don’t show code we can’t help. If it works in immediate mode then it should work from the text box. Show us an extract of the code and more importantly the error.log.
It will help you debug if you print the content of the variables just before you use the, in the name command.
We don’t need to jump to an API solution this should just work.
|
|
daved
New Member
Posts: 24
|
Post by daved on Jan 28, 2022 14:29:26 GMT -5
>> So to name a file we need the original file to exist, the new directory to exist and the new dir/file NOT to exist
The original file does exist, the dir does exist, and the new dir/file exists.
The code works if there is no space in the originalfile$. The full path is quoted: "c:\utils\myfiles\old file.txt" c:\utils\myfiles\ exists and old file.txt exists
This fails: name "c:\utils\myfiles\old file.txt" as "c:\utils\myfiles\new_file.txt" This works: name "c:\utils\myfiles\oldfile.txt" as "c:\utils\myfiles\new_file.txt"
The actual line is: name sel$ as newfile$ where sel$ resolves to "c:\utils\myfiles\old file.txt" and is taken from the the listbox "!contents? sel$" newfile$ is resolves to "c:\utils\myfiles\new_file.txt" and is taken from the renametxt "!contents? newname$"
|
|
daved
New Member
Posts: 24
|
Post by daved on Jan 28, 2022 14:35:40 GMT -5
If this isn't enough code let me know.
#main.listbox "selection? sel$" . . . print #main.renbox, "!contents? newname$" print sel$, newname$ NAME sel$ as newname$
results of print print sel$, newname$ "C:\Stuff\Classmates\Barb_Susen\Hi Barb1.txt" "C:\Stuff\Classmates\Barb_Susen\Hi_Barb1.txt"
Error Log follows: Error log timestamp Friday 01/28/22 02:34:47 PM
Runtime error: OS Error: The filename, directory name, or volume label syntax is incorrect.
Error(Exception)>>defaultAction Error(Exception)>>activateHandler: <anUndefinedObject> Error(Exception)>>handle Error(Exception)>>signal Error class(Exception class)>>signal: <'OS Error: The filena...'> BasicProgram(Object)>>error: <'OS Error: The filena...'> BasicProgram>>terminateRun: <aFileError> [] in BasicProgram>>errorHandlerBlock ExceptionHandler>>evaluateResponseBlock: <aBlockClosure> for: <aFileError> [] in ExceptionHandler>>handle: ProtectedFrameMarker(BlockClosure)>>setUnwind: <aBlockClosure> BlockClosure>>invisibleEnsure: <aBlockClosure> ExceptionHandler>>handle: <aFileError> ExceptionHandler>>findHandler: <aFileError> FileError(Exception)>>activateHandler: <anExceptionHandler> FileError(Exception)>>handle FileError(Exception)>>signal FileError class>>signal: <'OS Error: The filena...'> hostErrorCode: <123> HostFileSystemError>>defaultAction ExceptionHandler>>findHandler: <aHostFileSystemError> HostFileSystemError(Exception)>>activateHandler: <anExceptionHandler> HostFileSystemError(Exception)>>handle HostFileSystemError(Exception)>>signal HostFileSystemError class>>signalWith: <123> File class(FileSystemEntity class)>>osError: <123> File class(Object)>>osError File class>>rename: <'C:\Stuff\Classmates\...'> to: <'"C:\Stuff\Classmates...'> [] in NameCommand>>using: [] in BasicProgram>>begin ExceptionHandler>>evaluateProtectedBlock: <aBlockClosure> [] in ExceptionHandler>>activateDuring: ProtectedFrameMarker(BlockClosure)>>setUnwind: <aBlockClosure> BlockClosure>>invisibleEnsure: <aBlockClosure> ExceptionHandler>>activateDuring: <aBlockClosure> ExceptionHandler class>>handle: <anError class> with: <aBlockClosure> during: <aBlockClosure> BlockClosure>>on: <anError class> do: <aBlockClosure> BasicProgram>>begin BasicProgram>>gotoAndIfStoppedBegin: <'[ren]'> BasicProgram>>handlerName: <'[ren]'> evaluate: <aBlockClosure> callParameters: <anOrderedCollection> BasicProgram>>submitHandlerName: <'[ren]'> evaluate: <aBlockClosure> callParameters: <anOrderedCollection> BasicProgram>>submitHandlerName: <'[ren]'> callParameters: <anOrderedCollection> LibButton>>click BasicWindow>>click: <aLibButton> LibButton(Button)>>click: <aLibButton> Message>>perform Message>>evaluate LibButton(Object)>>triggerEvent: <#clicked> LibButton(Button)>>triggerClickedEvent LibButton(Button)>>notifyClicked: <1181802> LibButton(Object)>>perform: <#notifyClicked:> with: <1181802>
|
|
|
Post by Brandon Parker on Jan 28, 2022 16:47:42 GMT -5
This behavior is very strange. Previously, Liberty BASIC was erroring out when spaces were anywhere in the file path, but today, this works like a charm.
Obviously, this file exists in the location on the drive specified...
Name "D:\ERROR LOG.LOG" As "D:\ERROR LOG NEW.LOG"
Name "D:\ERROR LOG NEW.LOG" As "D:\ERROR_LOG_NEW.LOG
Name "D:\ERROR_LOG_NEW.LOG" As "D:\ERROR LOG.LOG"
This was not working yesterday...
{:0)
Brandon Parker
|
|
|
Post by Carl Gundel on Jan 28, 2022 20:05:15 GMT -5
This behavior is very strange. Previously, Liberty BASIC was erroring out when spaces were anywhere in the file path, but today, this works like a charm. Obviously, this file exists in the location on the drive specified... Name "D:\ERROR LOG.LOG" As "D:\ERROR LOG NEW.LOG"
Name "D:\ERROR LOG NEW.LOG" As "D:\ERROR_LOG_NEW.LOG
Name "D:\ERROR_LOG_NEW.LOG" As "D:\ERROR LOG.LOG" This was not working yesterday... {:0) Brandon Parker The error as originally reported is: The filename, directory name, or volume label syntax is incorrect. This is an operating system error, right? Google that error text and maybe some clue might be uncovered?
|
|