|
Post by mknarr on Dec 11, 2019 12:59:26 GMT -5
I've used name as several time and never had a problem.
I have a bunch of snips I've created over the years and a program to list them. Some of the basic files start with upper case and some with a lower case. What I am trying to do is convert all the lower case file names to start with an upper case letter so the sort actually sorts them in the correct order instead of listing the upper case ones first and then the lower case after them.
Here is the code and it fails on the Name as line. Why?
dim info$(10,10) files "C:\SnipManager\Snips","*.bas", info$() nr=val(info$(0,0)) for x=1 to nr filename$=info$(x,0) Original file name length=len(filename$) a$=upper$(left$(filename$,1)) 'Get the left letter as upper case b$=right$(filename$,length-1) 'Get the remainder of the file name Newfile$=a$+b$ 'New filename with the first letter upper case if Newfile$<>filename$ then name "C:\SnipManager\Snips\"+filename$ as "C:\SnipManager\Snips\"+Newfile$ 'Fails here "isEmpty end if next end
|
|
ntech
New Member
Posts: 49
|
Post by ntech on Dec 11, 2019 13:28:30 GMT -5
Try printing the first and second arguments to name before calling them, perhaps there's two "C:\"'s in the path's you're giving them.
Also, try combining "C:\SnipManager\Snips\"+filename$ into a variable and pass that variable to name, and do the same for the other path.
So try this:
dim info$(10,10) files "C:\SnipManager\Snips","*.bas", info$() nr=val(info$(0,0)) for x=1 to nr filename$=info$(x,0) Original file name length=len(filename$) a$=upper$(left$(filename$,1)) 'Get the left letter as upper case b$=right$(filename$,length-1) 'Get the remainder of the file name Newfile$=a$+b$ 'New filename with the first letter upper case if Newfile$<>filename$ then p1$ = "C:\SnipManager\Snips\"+filename$ p2$ = "C:\SnipManager\Snips\"+Newfile$ print p1$ print p2$ name p1$ as p2$ end if next end
|
|
|
Post by mknarr on Dec 11, 2019 14:30:27 GMT -5
I've already tried both printing and using simple string variables. Here is what is really odd. In order to list the names of the basic files in a listbox, I have a section that interrogates the Snips folder and look to see if I put a new bas file that starts with a lower case letter. Here is the code
length=len(filename$) a$=upper$(left$(filename$,1)) b$=right$(filename$,length-1) Newfile$=a$+b$ if Newfile$<> filename$ then name "C:\SnipManager\Snips\"+filename$ as "C:\SnipManager\Snips\"+ Newfile$ filename$=Newfile$ end if
And now it works. In the meantime I've gone in and changed the few basic files that stared witha lower case letter to an upper case. It was easier than trying too get the orig program to work.
|
|
|
Post by sarossell on Dec 11, 2019 14:56:13 GMT -5
filename$=info$(x,0) Original file name Should be: filename$=info$(x,0) ' Original file name
You missed a comment apostrophe. But the compiler should have caught that.
The program worked just fine for me after that.
The FILES command does not pull the path or drive letter, so I have to disagree with ntech on that issue, but he does make a very good point to print as you go, or use the debugger.
I suspect you *might* have a permissions issue blocking access to the C:\ drive. I always run as admin, so I don't have that issue. But I have to admit, when I tried moving the files to a protected directly to test my theory, the code ran without an error but failed to change the filenames and didn't even complain. So, I'm kind of stumped. Which version of LB and on what platform are you running?
:@)
Good luck!
:@)
|
|
|
Post by mknarr on Dec 12, 2019 9:19:21 GMT -5
Here is what is odd. I copied a basic file, Menumod.bas from the Snips Folder to the SnipManager folder. Then I wrote this one line program. name "C:\SnipManager\"+Menumod.bas as "C:\SnipManager\"+ menumod.bas and it changed the file from Menumod.bas to menumod.bas. Then I rewrote it like this: name "C:\SnipManager\Snips\"+Menumod.bas as "C:\SnipManager\Snips\"+ menumod.bas to change it in the Snips folder and it throws the error isEmpty meaning it can't find the file and the file is there. For what ever reason, it will change the file name in the parent folder but not the child folder. I have another program that will change a file name in a child folder but the name is changing from XXX to YYY. I don't believe this is an LB problem but a system problem.
LB 4.5.1 on Win 7 and have been for years.
|
|
|
Post by sarossell on Dec 12, 2019 9:40:36 GMT -5
Your code won't work because it is attempting to concatenate a string "C:\SnipManager\" to what it will identify as a numeric variable; Menumod.bas. For this to work, the code would have to assign the filename to a string variable first. Like this...
oldfilename$ = "Menumod.bas" newfilename$ = "menumod.bas"
oldfullpath$ = "C:\SnipManager\" + oldfilename$ newfullpath$ = "C:\SnipManager\" + newfilename$
name oldfullpath$ as newfullpath$
oldfullpath$ = "C:\SnipManager\Snips\" + oldfilename$ newfullpath$ = "C:\SnipManager\Snips\" + newfilename$
name oldfullpath$ as newfullpath$
|
|
|
Post by mknarr on Dec 12, 2019 16:05:48 GMT -5
Unfortunately if that were true, the first line of code would not work either. The "" says it's a string
|
|
|
Post by sarossell on Dec 12, 2019 17:10:47 GMT -5
My first move was to copy and paste your exact code and then try to run it.
The Type mismatch error is caused because Menumod.bas is not a string, nor is it enclosed in quotes. Therefore, LB sees it as a numeric variable. The same is true for the second line of code. It's easy to miss. :@)
|
|
|
Post by mknarr on Dec 13, 2019 10:00:49 GMT -5
You are correct,it should have been in quotes but I tried this this morning. This works and it changes the file from Menumod.bas to menumod.bas oldfile$="C:\SnipManager\Menumod.bas" newfile$="C:\SnipManager\menumod.bas" name oldfile$ as newfile$
This does not: oldfile$="C:\SnipManager\Snips\Menumod.bas" newfile$="C:\SnipManager\Snips\menumod.bas" name oldfile$ as newfile$
Here is picture of the path: I do other things with those basic files like deleting them, opening them in a text editor where I can copy the code etc. But for some reason, I can't change the name in the child folder but I can in the root folder.
|
|
ntech
New Member
Posts: 49
|
Post by ntech on Dec 13, 2019 10:31:48 GMT -5
You can always resort to the command line. Try this to use the batch command.
run "move " + from$ + " " + to$ 'syntax: move fileFROM fileTO
'Example: 'run "move C:\SnipManager\Snips\Menumod.bas C:\SnipManager\Snips\menumod.bas"
|
|
|
Post by sarossell on Dec 13, 2019 10:50:44 GMT -5
mknarrThat sounds like a permissions issue in Windows. You might try creating a new sub-folder for testing and see if it works any better. The code from your most recent post works fine for me. ntech is onto something clever as well by using the DOS approach through the RUN command. :@)
|
|
|
Post by Rod on Dec 13, 2019 11:39:30 GMT -5
The help file warns about read-only files and trying to name to a file that already exists. I created the same directory structure and could rename a file using your code. I would right click on the target file and check its properties. Is it read-only or is it blocked by Windows. Both show on the general pane. Also consider whether the destination file already exists.
There is nothing wrong with NAME AS so we need to find what the error actually is.
I find I can rename a read-only file, but I cannot copy a non existent file or copy to an existing file, both give clear error notices. What error notice are you getting?
I also find that I can rename from Menumod.bas to menumod.bas though Windows is supposed to be case insensitive for file names?
|
|
|
Post by mknarr on Dec 13, 2019 14:50:46 GMT -5
I may have found the issue. The properties of the files are Read Only as is the child folder Snips and the parent folder SnipManger. I can remove the Read Only from either, Apply it and Read Only comes back when I look at the properties again. I have finally changed the Permissions to allow me to write in the folders and now I can name as and the change takes place without error.
Thanks to all. How the folder came to be protected from me is beyond me. I have now notices that a lot of my own folders are now Read Only. Why?
|
|
|
Post by Carl Gundel on Dec 13, 2019 14:56:33 GMT -5
Sometimes files that are restored from a backup can be read only, and especially if they are restored from a CD or DVD disk.
|
|
|
Post by Rod on Dec 13, 2019 17:30:27 GMT -5
|
|