Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RENAME changes upper to lower

Status
Not open for further replies.

k2a

Programmer
Jun 26, 2012
133
DE
Renaming files changes uppercase to lowercase, such as

lcCSVname = "0207986742_EUR_20161026_100259.csv“
lcNewCSVname = "E1-0207986742-25AUG2016-26OCT2016.CSV“
RENAME &lcCSVname TO &lcNewCSVname

Result e1-0207986742-25okt2016-26okt2016.csv

Is there a way to force it to uppercase?

Klaus
 
try command interpreter

run rename lower.csv UPPER.CSV

there is no 'to' reserve word in the command above.





 

NasibKalsi,

Do you mean to replace the Statement RENAME &lcCSVname TO &lcNewCSVname with run rename &lcCSVname &lcNewFileName?

 
About that, yes. you will need to provide full paths or CD into the directory. VFP current directory is not cmd.exe current directory when you use RUN.

Bye, Olaf.
 
lcCSVname = „0207986742_EUR_20161026_100259.csv“
lcNewCSVname = „E1-0207986742-25AUG2016-26OCT2016.CSV“

Made the following changes:
lcCSVname = "C:\Appl\Test\" + lcCSVname
lcNewCSVname = "C:\Appl\Test\" + lcNewFileName

run rename &lcCSVname &lcNewFileName
and
run rename lcCSVname lcNewFileName

Result no renaming.
 
The way in which I have had to address the filename Case issue was as follows

Code:
cOutputFile = <fully pathed original file name>
cDestinationFile) = <fully pathed new Case-specific file name>
* --- Retain File Name UPPER CASE ---
WOBJ = CREATEOBJECT("WSCRIPT.SHELL")
wss = WOBJ.RUN('cmd /c copy ' + (cOutputFile) + ' ' + UPPER(cDestinationFile),0)

Good Luck,
JRB-Bldr


 
your second try can't work, it would literally look for a file named "lcCSVname".

Is this the real path or abbreviated for the post? If you have spaces, you have to use RUN rename "&lcCSVname" "&lcNewFileName", also I think the target name has just to be the name itself, since RENAME cannot move a file to any other directory anyway. Actually this is what help rename says in the help text, you can't specify drive and path for the target file name.

This should run:
Code:
lcCSVname = "0207986742_EUR_20161026_100259.csv"
lcNewCSVname = "E1-0207986742-25AUG2016-26OCT2016.CSV"

lcCSVname = "C:\Appl\Test\" + lcCSVname
* no change for lcNewCSVname 
* lcNewCSVname = lcNewCSVname && no drive/path here!

run rename "&lcCSVname" "&lcNewCSVname"

Bye, Olaf.
 
Try this:

Code:
lcCSVname = "C:\Appl\Test\" + lcCSVname
lcNewCSVname =  lcNewFileName 

run rename &lcCSVname &lcNewCSVname

In other words, leave out the path in the destination filename.

From the Help for the Rename command:

RENAME [drive:][path]filename1 filename2.
REN [drive:][path]filename1 filename2.

Note that you cannot specify a new drive or path for your destination file.


Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
You made some bad typos, too. You never initialise lcNew[highlight #FCE94F]File[/highlight]Name but use it in rename. It would really help, if you copy & paste exactly what you have and do, because initialising [tt]lcNew[highlight #FCE94F]CSV[/highlight]name = „E1-0207986742-25AUG2016-26OCT2016.CSV“[/tt], then setting [tt]lcNew[highlight #FCE94F]CSV[/highlight]name = "C:\Appl\Test\" + lcNew[highlight #FCE94F]File[/highlight]Name[/tt] with uninitialised lcNew[highlight #FCE94F]File[/highlight]Name and finally doing [tt]run rename &lcCSVname &lcNew[highlight #FCE94F]File[/highlight]Name[/tt] can't work. How?

Don't be so lazy in looking exactly at your code and/or posted code. This has to fail if this is literally what you do, even putting aside the issue to not be able to use path in target name. Concentrate.
I said "you will need to provide full path[highlight #FCE94F]s[/highlight]", sorry for that, but if it would work with a path in the target name, RENAME could also move files, when the target path is not equal and that's not the intent of the RENAME command.

Bye, Olaf.
 
Olaf said:
I said "you will need to provide full paths", sorry for that, but if it would work with a path in the target name, RENAME could also move files, when the target path is not equal

That's what I would have thought as well. But I just did a couple of tests, and found that the command failed when I included a path with the target file.

SpecificallY:

[tt]RENAME c:\work\junk.txt junk1.txt[/tt]

that works; but:

[tt]RENAME c:\work\junk1.txt c:\work\junk2.txt
[/tt]
that doesn's work (but no error message).

Also:

[tt]RENAME c:\work\junk1.txt c:\data\junk2.txt[/tt]

failed with a syntax error.

I'm a but surprised at this, because like you I thought you could use RENAME as a way of moving files to another directory, but I must have been wrong. (I might have been getting confused with the MOVE command, which actually does a rename rather than a physical move.)

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Well, my only thought about providing paths was, that [tt]RENAME some.csv another.csv[/tt] most probably only fails because the cmd.exe process you start via RUN is not in the same working/current directory as VFP is. Providing paths always helps in case of external processes involved, also Word.Application and other OLE automation. I could say I talked about the plural path[highlight #FCE94F]s[/highlight] because I thought of multiple renames, but indeed I thought about RENAME also being able to work with full name in both parameters, even if the second name doesn't need a path, when it should stay where it is and only be renamed. Anyway, Klaus code had more flaws with the variable names.

Bye, Olaf.
 
jrbbldr,
i also tried your suggestion, but the origional file remains unchanged.

Mike,
yes, i left out the path in the destination filename, but again no renaming.

Olaf,
Yes, i abbreviated the real path for the post and there are no spaces in the names.
Ok, you right bad typos happen when abbreviating, here is some parts of the real code:

SET DEFAULT TO C:\Allg-VFP9\Appl\AbgleichDaten\SM-ApoBank\Test
lcCSVname = SUBSTR(lcDirFile, lnNameStart, 34) && lcCSVname = „0207986742_EUR_20161026_100259.csv“
lcNewFileName = lcPraxisID + "-" + lcKtoNr + "-" + lcDateStart+;
"-" + lcDateEnd + ".CSV" && lcNewFileName = „E1-0207986742-25OKTG2016-26OKT2016.CSV“
RENAME &lcCSVname TO &lcNewFileName && This works fine but changes uppercase to lowercase

So what i have tried.
lcCSVname = "C:\Allg-VFP9\Appl\AbgleichDaten\SM-ApoBank\Test\" + lcCSVname
lcNewFileName = "C:\Allg-VFP9\Appl\AbgleichDaten\SM-ApoBank\Test\" + lcNewFileName
run rename &lcCSVname &lcNewFileName

lcCSVname = "C:\Allg-VFP9\Appl\AbgleichDaten\SM-ApoBank\Test\" + lcCSVname
run rename &lcCSVname &lcNewFileName && No path in the destination file

cOutputFile = lcCSVname && with fully path from original file
cDestinationFile = lcNewFileName && with fully path for the new filename
* --- Retain File Name UPPER CASE ---
WOBJ = CREATEOBJECT("WSCRIPT.SHELL")
wss = WOBJ.RUN('cmd /c copy ' + (cOutputFile) + ' ' + UPPER(cDestinationFile),0)
 
Code:
So what i have tried.
lcCSVname = "C:\Allg-VFP9\Appl\AbgleichDaten\SM-ApoBank\Test\" + lcCSVname
lcNewFileName = "C:\Allg-VFP9\Appl\AbgleichDaten\SM-ApoBank\Test\" + lcNewFileName
run rename &lcCSVname &lcNewFileName

lcCSVname = "C:\Allg-VFP9\Appl\AbgleichDaten\SM-ApoBank\Test\" + lcCSVname
run rename &lcCSVname &lcNewFileName && No path in the destination file

Well, again, concentrate!

When you already put the path in front of lcNewFileName, the second try still has this path in it.
If you make several experiments at once, you will have to reset lcNewFilename to the name without path!

Your two experiments are the same, in both cases lcNewFileName already has the path prefixed, which it must not have.
Either set lcNewFileName = JUSTFNAME(lcNewFileName) or make it two separate experiments, where you once prefix the path and the other time not.

Also you will want to make sure the code never breaks when there will be spaces in a path, so use quotes. This code somwhat ensures the outset is alright:

Code:
SET ASSERTS ON
ASSERT SUBSTR(lcCSVName,2,1) $ "\:" AND ADIR(laDummy,lcCSVName)=1 MESSAGE "lcCSVName must have a path starting with drive: or \\ (unc) and the file must exist."
lcNewFileName = JUSTFNAME(lcNewFileName)
ASSERT CHRTRAN(lcNewFilename,":\*%?","")==lcNewFilename AND LEN(lcNewFilename)>0 MESSAGE "lcNewFilename must be a valid file name."
Run Rename "&lcCSVname" "&lcNewFileName"

The assertions could be more elaborate on how to detect a valid path and how to detect a valid file name. But it's a start to ensure you provide a path to the first parameter "&lcCSVname" and no path but a valid name in the second parameter "&lcNewFileName". This now could still fail on target name already existing and more, but it should work out for the right values in lcCSVname and lcNewFileName.

Bye, Olaf.
 
Klaus,

I'm surprised that you said that my suggestion didn't work. I have now tested it again in both VFP (using RUN) and via the command prompt. It always works for me.

What's more, I have no difficulty with this:

[tt]RUN RENAME e1-0207986742-25okt2016-26okt2016.csv E1-0207986742-25AUG2016-26OCT2016.CSV[/tt]

As expected, that converts the filename from lower to upper case (which I think it what you want). The capitalised filename appears both at the DOS prompt and in Windows. (In VFP, filenames always shows up in upper case - at least, in functions such as ADIR()).

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Well, as I said you maya CD into a directory, I don't know whether cmd.exe will always run in the current/default directory of VFP, though. As Klaus has started that way, it's quite clear it does not always work. It may depend on settings, OS Version, VFP version, whatever. I stated to like paths wherever they avoid any ambiguity and yes, Mike, your code and my last work, but the Klaus set lcFilename he didn't do it with lcFilename only being a file name.

Bye, Olaf.
 
Olaf
On each experiments the program got restarted then stopped at the run command and checked the contents of the file variables.


Mike
When executing the command RUN RENAME 0207986742_EUR_20161026_100259.csv E1-0207986742-25AUG2016-26OCT2016.CSV then of cause that works, the file is in uppercase then. But the problem is i cannot do that within my program. The file names are in variables.

Therefore i have use RUN RENAME &lcCSVname &lcNewFileName, with or without the path in the destination filename.

But listen, fact is RENAME &lcCSVname TO &lcNewFileName renames the file from 0207986742_EUR_20161026_100259.csv to e1-0207986742-25okt2016-26okt2016.csv and not to E1-0207986742-25OKTG2016-26OKT2016.CSV as i wanted it.

However, this is not a big problem and can really live with it. I thought forcing it to uppercase would be just a simple VFP trick. I do not think that is worth the time digging much deepper into the details.

What really impresses me is the quick response on this hotline.

Therefore many thanks to all of your great help.

Best Rgards
Klaus
 
Well, it works for me (RUN RENAME , not RENAME), and I paid attention the case of the name was your initial problem and was the reason to recommend shell (RUN) rename instead of VFPs own rename.
It works, just do it again. In your test you set lcNewFileName = "C:\Allg-VFP9\Appl\AbgleichDaten\SM-ApoBank\Test\" + lcNewFileName before the first rename and it's still with the path in the second run of rename. Of course this doesn't work.

Code:
lcSourcename = ADDBS(GETENV("TEMP"))+"initial.csv"
lcTargetname = "FINAL.CSV"
STRTOFILE("1,2,3",lcSourcename)
ADIR(laFiles,lcSourcename,"",1)
? laFiles[1,1]
RUN RENAME "&lcSourceName" "&lcTargetname"
ADIR(laFiles,ADDBS(GETENV("TEMP"))+"final.csv","",1)
? laFiles[1,1]

It works, and using nFlags=1 in ADIR proves it gets the correct capitalization.

Notice: By intention I let ADIR look for "final.csv" in lower case. It returns the file in upper case. You can also use any mixture of lower and upper case as you like, ADIR will find a file no matter in what case the file skeleton parameter is passed in, due to last parameter (nFlags) being 1 it returns the file name as it is in the file system, so what you get from laFiles[1,1] is the name as it is on HDD.

Bye, Olaf.
 
Hi Olaf,

your last post motivated me again to look concentrated to all the messages and run the tests all over again. I was pretty sure that i also run the destination file with and without the path and both failed.

So my supprice was not bad as it suddenly worked. The program look now like this:

lcNewFileName = lcPraxisID + "-" + lcKtoNr + "-" + lcDateStart+ "-" + lcDateEnd + ".CSV"
*RENAME &lcCSVname TO &lcNewFileName && OK, but this changes uppercase to lowercase
lcCSVname = "C:\Allg-VFP9\Appl\AbgleichDaten\SM-ApoBank\Test\" + lcCSVname
Run Rename &lcCSVname &lcNewFileName

You and Mike are right no path in the destination filename.

Regards
Klaus
 
My suggestion is for a COPY of File1 to File2.
The original filename (File1) is not supposed to change.
But since you define the name of the Destination file (Case-specific File2), that is retained as intended.

I have not tried it with a RENAME.
But, although it might be over-kill, you could always write the original file as some 'generic' filename and then COPY it to the Case-specific intended Destination file.

Actually that is specifically what I was doing with it.
I'd write the original file via Bullzip to a 'generic' location and 'generic' filename
Then immediately COPY it to the intended different directory with a Case-specific filename.
That enabled me to run a pre-configured Bullzip over and over and still end up with client-specific PDF files.

Good Luck,
JRB-Bldr

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top