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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with SET DEFAULT TO 2

Status
Not open for further replies.

Bryan - Gendev

Programmer
Jan 9, 2011
408
0
16
AU
In my app ( written 10+ years ago and now being revised and checked) I have a need to change the default folder on a number of occasions. I use SET DEFAULT TO (cNewfolder) and this works on every occasion except one which I am now trying to resolve. I need to be placed in a certain folder in this instance to make a backup of an ini file before changing the current ini in a certain way - allowing the current ini to be restored later.
I don't know if this is the problem but the path required is like
C:\Users\username\AppData\Roaming\the_target_ini_appnameI am unable to set my default to this folder to backup the ini file which resides there using COPY FILE (file1) to backupfile1.txt.
Can anyone advise me on this?

GenDev
Adelaide
South Australia
 
What's the actual error and when does it occur? Already when you SET DEFAULT or when you COPY FILE?


Chriss
 
Try this.

*-- Save current directory
lc_currdir = SET("default") + CURDIR()

DO whatever...
...
...
*-- restore to prior directory
SET DEFAULT TO &lc_currdir

Hope this helps.

Edgar
Integrated Bar Code Systems, Inc.
 
Hi GenDev,

I hope you changed "username" in your command to the actual name of your user.

Regards, Gerrit
 
Hi Chriss

You said "What's the actual error and when does it occur?"

There is no error generated - observing what happens in the Debugger shows no change in path with curdir() so the copy just has no effect.

Gendev
 
Hi fitedgar

My problem is that my system will not set default to the required folder as specified.

Hi Gerrit
Of course <G>


Gendev
 
I have set up a list of set default statements to test the operation and output the result of curdir() after the command.
Allworks as expected except the last statement which is the one I have quoted above. As you can see the path is not changed and curdir() returns the previous path still.
paths_sj9ypi.png


GenDev
 
I am obviously unable to do what I was trying to do so I have found another way to accomplish what I was trying to do - thanks to all who replied.

Gendev
 
gendev said:
no change in path with curdir() so the copy just has no effect
Werll, that's interesting. Because if the directory doesn't change, then either SET DEFAULT would error "Invalid path" or COPY FILE would error "File not found", because how could the copy not error when trying to copy an ini that's not in the path, which you proved is not changing to the Roaming user profile directory.

So I assume you do something like ON ERROR *, suppressing errors. That way you don't find and fix errors.

Well, as you found a solution, it's not necessary to dive deeper.



Chriss
 
Hi Chriss,

I have no intention to hide errors - the only error report I have ever seen has been Table Error.
The bad path and FILE COPY just jumped past in the deugger with no visible output.


My errorhandler which I found and copied from this forum 10+ years ago is

Procedure errHandler
Parameter merror, Mess, mess1, mprog, mlineno
Local myMessage,myactualpath

myactualpath = Curdir()


myMessage=;
'Program with error: ' + mprog + Chr(13);
+'Error number: ' + Ltrim(Str(merror))+ Chr(13) ;
+ 'Error message: ' + Mess + Chr(13) ;
+ 'Line of code with error: ' + mess1 + Chr(13);
+ 'Line number of error: ' + Ltrim(Str(mlineno))+ Chr(13);
+ 'Current Path in Use : ' + myactualpath;




myReport =Chr(13)+ Chr(10) + Dmy(Date())+ ' ' + Time()+ Chr(13)+ Chr(10) ;
+'Error number: ' + Ltrim(Str(merror))+ Chr(13)+ Chr(10) ;
+ 'Error message: ' + Mess + Chr(13)+ Chr(10) ;
+ 'Line of code with error: ' + mess1 + Chr(13)+ Chr(10);
+ 'Line number of error: ' + Ltrim(Str(mlineno)) ;
+ Chr(13) +Chr(10);
+ 'Program with error: ' + mprog + Chr(13) + Chr(10);
+ 'Current Path in Use : ' + Curdir() + Chr(13) + Chr(10);
+ '***********************END*****************************';
+ Chr(13)+Chr(10);


If ! Empty(Alias())
myMessage = myMessage + Chr(13)+Chr(10) + ;
'Current ALIAS in Use : ' + Alias()
Do Case
Case Eof()
myMessage = myMessage + Chr(13)+Chr(10) + "EOF"
Case Bof()
myMessage = myMessage + Chr(13)+Chr(10) + "BOF"
Otherwise
myMessage = myMessage + Chr(13)+Chr(10) +;
"RECNO: " + Alltrim(Str(Recno()))
Endcase

Endif


=Messagebox(myMessage,16,"ERROR !!!")

If File('errors.dat') && Does file exist?
Strtofile(myReport,'errors.dat',.T.)
gnErrFile = Fopen('errors.dat',12) && If so, open read-write
Else
gnErrFile = Fcreate('errors.dat') && If not, create it
Strtofile(myReport,'errors.dat',.T.)
Endif


If gnErrFile < 0 && Check for error opening file
Wait 'Cannot open or create output file' Window Nowait
Else && If no error, move to eof write to file
= Fseek(gnErrFile, 2)
Strtran(myMessage,myMessage," ")
=Fwrite(gnErrFile , myReport)

Endif
=Fclose(gnErrFile ) && Close file


logging(myReport)
Set Defa To (myactualpath)
Endproc

called in main.prg by

On Error Do errHandler With ;
ERROR( ), Message( ), Message(1), Program( ), Lineno( )


 
Chriss,

As it happens I just got an error and an error message
error_zjk13r.png


So my errorhandler works correctly - so why no message when I tried to change to the path mentioned above and the COPY FILE command.

Strange.

GenDev
 
Do you also log these messages, or just display them? You can easily click on OK as reflex action or even just have SPACE in the keyboard buffer and therefor "click" OK without consciously perceiving such messages.

Good, that you have such an error handling. It seems you have a lot of pathing issues not finding files. Are you aware that on older systems (Win 95/98/XP) you don't have C:\Users? You might fail on assuming the profile location. There are system functions to determine system paths. What is unfortunate is that those functions changed also when the system paths changed, so having code that would work in XP and earlier wouldn't work on Vista and later, that makes it quite cumbersome, but you also have the GETENV("USERPROFILE") value that works on all OS versions to at least give the profile base path. I'm not sure the roaming part always is in the \AppData\Roaming\ subdirectory from there, though. The other thing to make use of is VFPs function OS(), that you can use to make the correct declarations of API functions and calls to determine system directories depßending on which OS your EXE runs. Not the simplest topic.

Edit: Another issue I see is that roming profiles are not necessarily enabled/existing. I assume you know you can work with a roaming profile, though, and you want to use that user specific system directory. GetEnv("APPDATA") might be better usable in any case. To me it is indeed my profiles roaming subdirectory, indepent of OS version it is the directory where applications should create their own application and user dependent directory and files within that. I'm not sure that you can always write into that directory.

Chriss
 
Thinking somewhat "outside the box" here :) Have you ever considered NOT using Windows stupid directory system?
At my around 50 installations all over Sweden, everything is on a directory on a server.
Inside that directory I have subdirectories like for example:

DATA
REPORTS
IN
OUT

And so on. All of those are found by the app by SET PATH TO

My 2 cents...
 
gendev,

Sorry, I overlooked your erorr handling code. It is appending to an error.dat file. Have you looked into that?



Chriss
 
It would also be helpful to see the code chaging default and copy file in a bigger context. Does it run within a TRY CATCH block?

Before you answer "no", be aware that doing something like
Code:
TRY
Do some.prg
CATCH
*
ENDTRY
Any error happening in some.prg would be catched by the catch block in this code section, which obviously can be in any other PRG.

Chriss
 
I now find that my solution to my path problem did not work out.
As a test of getting to the required path I used CD to walk down the required path.
That worked perfectly until it got to the required folder when it again didn't move to the folder.
I am trying to modify an ini file that is used by TMG ( saving/modifying/restoring).
Using the full path name does not work in a COPY FILE so I need to be in the folder I can't get to.
<sigh>

GenDev
 
Using the full path name does not work in a COPY FILE
Wrong, COPY FILE allows you to provide a fully qualified file name (i.e. with path).

It can also be relative to the current directory, therefore the pure file name works, when you first SET DEFAULT or CD (they both do the same, by the way, there is no difference of CD to SET DEFAULT)., but you don't have to change directory.

You could have the problem Tom mentions.



Chriss
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top