UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
2 Pages V < 1 2  (Go to first unread post)
   Reply to this topicStart new topic
> Saving A Sequential Backup, visual Studio 2017    
 
   
AlbertKallal
post Mar 29 2020, 01:38 PM
Post#21


UtterAccess VIP
Posts: 3,053
Joined: 12-April 07
From: Edmonton, Alberta Canada


QUOTE
is 'File' a built-in class in vb.net, or does it have to be imported? If so, what's the import look like?


Yes - my sorry, my bad.

CODE
Imports System.IO


That will get you the use of the "file" and "path" options you need.

.net is REALLY nice in this regards. All of the things like:
Does a file exist, get the path, get the extension, get only file name without extension. (and more!!!).


Such things are built into .net - its one of the best features. The only trick is knowing where to find the feature! ;-)

I can only suggest that:
If there something that you in the past think you needed some API for (say like in VBA)?

JUST ASSUME it exists in .net - it almost nearly does. The result tends to be far less code, and code that is easy to read and clean.

R
Albert

Go to the top of the page
 
cheekybuddha
post Mar 29 2020, 04:18 PM
Post#22


UtterAccess Moderator
Posts: 12,803
Joined: 6-December 03
From: Telegraph Hill


Thanks, Albert.

Doesn't System.IO also cover file operations?

If so, then with this class imported, Mike can perform the backup operation too.

Otherwise, Mike, use the FileIO import that Frank demonstrated in Post#15

thumbup.gif

d

--------------------


Regards,

David Marten
Go to the top of the page
 
FrankRuperto
post Mar 29 2020, 05:03 PM
Post#23



Posts: 966
Joined: 21-September 14
From: Tampa, Florida USA


.. and if you're going to use methods like GetCommandLineArgs() and properties like CurrentDirectory, then you will also have to Imports the System.Environment class.
This post has been edited by FrankRuperto: Mar 29 2020, 05:04 PM

--------------------
Currently supporting pawnbrokers that use my store management system developed with Access 2010 on Windows7. Experienced with Informix, Oracle & PostgreSQL db's.
Go to the top of the page
 
mdelke@chartermi...
post Apr 7 2020, 07:26 PM
Post#24



Posts: 11
Joined: 26-March 20



Albert,
I tried the code and when I run it in debug it preforms as advertised just didnt print it into the folder so I used filecopy(original file,strf file) is still didnt write it into the folder (strF,strF) didnt work either. I think I have gone BRAIN DEAD
I have the imports System.IO at top of the forms page

Public Function GetServerFileNext(strFileFullPath As String) As String
Dim aFile As String
Dim strF As String
Dim i As Integer = 0
'strFileFullPath = ("c:\RRLogger Data\County Hunter - K8EMS.mdb")<-----------------This is the file I want to make a copy of
'aFile = ("c:\RRLogger Data\County Hunter - K8EMS-RRLog-Bup-1.mdb")<--------------This is the first copy
'BFile = ("c:\RRLogger Data\County Hunter - K8EMS-RRLog-Bup-2.mdb")<--------------This is the second copy...and so forth
' check if file already exist - start increamnt -N to file name
Do
If i = 0 Then
strF = strFileFullPath
Else
strF = Path.GetFileNameWithoutExtension(strFileFullPath) & "-RRLog-Bup-" & i & Path.GetExtension(strFileFullPath)
End If
If File.Exists(strF) = False Then
Exit Do
End If
i = i + 1
Loop
FileCopy(strF, strF)
Return strF

End Function

it does run the loop but when it gets to the available file name .......it has the right file name it doesn't put it into the folder
This post has been edited by mdelke@chartermi.net: Apr 7 2020, 07:27 PM
Go to the top of the page
 
FrankRuperto
post Apr 7 2020, 07:53 PM
Post#25



Posts: 966
Joined: 21-September 14
From: Tampa, Florida USA


If all the source files are in the same folder, why not just copy the entire folder to a destination path instead of looping through each file individually? My vb.net program copies entire folders.

--------------------
Currently supporting pawnbrokers that use my store management system developed with Access 2010 on Windows7. Experienced with Informix, Oracle & PostgreSQL db's.
Go to the top of the page
 
mdelke@chartermi...
post Apr 8 2020, 09:47 AM
Post#26



Posts: 11
Joined: 26-March 20



Frank,
The program I am working on is a replacement for a visual basic 6 program that members have been using for years. They feel the need for more than one backup because it is a lot of time and effort to make a contact with another ham in all 3077 counties in the US and loosing that info would be a devastating loss, with an immense amount of work to rebuild it.Thus they make many backups to eliminate as much work as possible to recover after a computer crash. Most users of program are not computer savvy so they use the backup routine at least weekly so they have multiple chances to rebuild their log book, with a little less effort.
Again I am not a professional programmer I am a retired Paramedic working on this program to keep my mind active and learn new skills, I appreciate all the help I have received from people with a lot more knowledge than I have such as yourself. I have been combing the MSDN for info on my problem but it is confusing to me. So I apologize if my questions don't make complete sense to more advanced programmers, I am still learning the programming lingo. I again THANK YOU for the help and incite into programming.

I guess the real question is ...How to use the return from the loop to write the file to the folder?

The Loop does cause the name to be generated and I can understand how this is done in the loop. Then it is like a deep fog, I have lost my way to get to the next point in the journey.

A Big THANK YOU to all who are trying to help if I were better at programming it might not be so frustrating for you.
Go to the top of the page
 
FrankRuperto
post Apr 8 2020, 10:17 AM
Post#27



Posts: 966
Joined: 21-September 14
From: Tampa, Florida USA


Ham contacts as in QSL contact cards? I suggest you also export their logs to csv files and back those up in case the tables become corrupted. We provided this for all users of my pawnshop app. They backup their accdb's and the csv files each workday on a seven-day rotating basis. Each weekday has its own external storage device. If accdb corruption occurs and Compress/Repair doesn't fix the problem, we created an automated utility that imports the csv's into a new accdb backend and reconstructs the table relationships and rebuilds the indexes.

It surprises me to hear you say that most ham radio operators are not computer savvy. I often QSO as a guest on my neighbor's Yaesu FT-950 rig and he is very computer savvy.
This post has been edited by FrankRuperto: Apr 8 2020, 10:34 AM

--------------------
Currently supporting pawnbrokers that use my store management system developed with Access 2010 on Windows7. Experienced with Informix, Oracle & PostgreSQL db's.
Go to the top of the page
 
cheekybuddha
post Apr 8 2020, 12:07 PM
Post#28


UtterAccess Moderator
Posts: 12,803
Joined: 6-December 03
From: Telegraph Hill


Hi,

This line doesn't look right:
CODE
' ...
    FileCopy(strF, strF)
' ...


Shouldn't it be something more like:
CODE
' ...
    FileCopy(strFileFullPath, strF)
' ...

???

hth,

d

--------------------


Regards,

David Marten
Go to the top of the page
 
mdelke@chartermi...
post Apr 8 2020, 06:38 PM
Post#29



Posts: 11
Joined: 26-March 20




FileCopy(strFileFullPath, strF)

You are correct although it seemed to work the other way also. I found after watching in the debugger the the number kept going up but the file never appeared in the folder, so did some investigation and found the files were being placed into the debug folder of the file the program was being loaded from. I went back and checked more closely using a couple of break points and it appears that just before the filecopy statement the file to be written lost the (C:\RRLogger Data\) part of the path and only said ( County Hunter - K8EMS-RRLogr-Bup-1.mdb )
and then it was written to the Debug folder. That is kinda why I was looking around the C drive for where it was written as it was continuing to increase the number every time I ran it.

Any ideas?.........Like I said I am at a loss
Go to the top of the page
 
FrankRuperto
post Apr 8 2020, 07:39 PM
Post#30



Posts: 966
Joined: 21-September 14
From: Tampa, Florida USA


It looks like its placing the files in a relative path instead of a fully qualified absolute path: Path.IsPathFullyQualified Method
If a path isn't fully qualified, Windows applies the current directory to it: File path formats on Windows systems
I also never use blank spaces or symbols like hyphens in paths or file names, even though enclosing them in quotes supports them.
This post has been edited by FrankRuperto: Apr 8 2020, 08:07 PM

--------------------
Currently supporting pawnbrokers that use my store management system developed with Access 2010 on Windows7. Experienced with Informix, Oracle & PostgreSQL db's.
Go to the top of the page
 
mdelke@chartermi...
post Apr 8 2020, 08:09 PM
Post#31



Posts: 11
Joined: 26-March 20



Yes Frank it is the relative path.

Thewhole path is sent to the function...strFileFullPath = ("c:\RRLogger Data\County Hunter - K8EMS.mdb")<-----------------This is the file I want to make a copy of

it finds the file to copy but just where it is supposed to write the file it looks like ( County Hunter - K8EMS.mdb) and has lost the rest of the path preceding it

what in the code that is posted above would cause this to happen?
Go to the top of the page
 
FrankRuperto
post Apr 8 2020, 08:27 PM
Post#32



Posts: 966
Joined: 21-September 14
From: Tampa, Florida USA


So step through the code in debug to see the destination path in the loop that's being pased to FileCopy.
You said its incrementing correctly.
What are the values of strF when you step through this code segment?

CODE
If i = 0 Then
strF = strFileFullPath
Else
strF = Path.GetFileNameWithoutExtension(strFileFullPath) & "-RRLog-Bup-" & i & Path.GetExtension(strFileFullPath)
End If

Wish I could recreate the problem locally to test, but your better setup to do that.

CODE
Do
If i = 0 Then
strF = strFileFullPath
Else
strF = Path.GetFileNameWithoutExtension(strFileFullPath) & "-RRLog-Bup-" & i & Path.GetExtension(strFileFullPath)
End If
If File.Exists(strF) = False Then
Exit Do
End If
i = i + 1
Loop
FileCopy(strF, strF)
Return strF

This post has been edited by FrankRuperto: Apr 8 2020, 08:38 PM

--------------------
Currently supporting pawnbrokers that use my store management system developed with Access 2010 on Windows7. Experienced with Informix, Oracle & PostgreSQL db's.
Go to the top of the page
 
mdelke@chartermi...
post Apr 9 2020, 08:57 AM
Post#33



Posts: 11
Joined: 26-March 20



This is what happens when I run the debugger

Do
If i = 0 Then
strF = strFileFullPath <----TheComplete path is here C;\RRLogger Data\ County Hunter - K8EMS.mdb
Else
strF = Path.GetFileNameWithoutExtension(strFileFullPath) & "-RRLog-Bup-" & i & Path.GetExtension(strFileFullPath) <---------TheComplete path is here C;\RRLogger Data\ County Hunter - K8EMS.mdb
End If
If File.Exists(strF) = False Then <----Only file part of path is here County Hunter - K8EMS.mdb <---Second time thru County Hunter - K8EMS-RRLog-Bup-1.mdb
Exit Do
End If
i = i + 1
Loop
FileCopy(strFileFullPath, strF) <-----After first time thru (strFileFullPath)=C;\RRLogger Data\ County Hunter - K8EMS.mdb and (strF)=County Hunter - K8EMS-RRLog-Bup-1.mdb
Return strF


Looking at this it appears I have to rebuild strF to include the (C:\RRLogger Data\) part of the path string just prior to writing it to the folder, am I looking at this correctly, as this is where it assumes the relative path instead of the actual path.
This post has been edited by mdelke@chartermi.net: Apr 9 2020, 08:58 AM
Go to the top of the page
 
cheekybuddha
post Apr 9 2020, 09:02 AM
Post#34


UtterAccess Moderator
Posts: 12,803
Joined: 6-December 03
From: Telegraph Hill


CODE
' ...
    strF = Path.GetFileNameWithoutExtension(strFileFullPath) & "-RRLog-Bup-" & i & Path.GetExtension(strFileFullPath)
' ...


Look at your function calls here:
Path.GetFileNameWithoutExtension
Path.GetExtension

You are only getting the filename and the extension. There must be one to get the path as well. Something like:
CODE
' ...
    strF = Path.GetPath(strFileFullPath) & "\" & Path.GetFileNameWithoutExtension(strFileFullPath) & "-RRLog-Bup-" & i & Path.GetExtension(strFileFullPath)
' ...

(you will have to look up the correct function to use, and whether it will include a trailing slash)

hth,

d

--------------------


Regards,

David Marten
Go to the top of the page
 
FrankRuperto
post Apr 9 2020, 09:15 AM
Post#35



Posts: 966
Joined: 21-September 14
From: Tampa, Florida USA


CODE
strF = strFileFullPath <----TheComplete path is here C;\RRLogger Data\ County Hunter - K8EMS.mdb
strF = Path.GetFileNameWithoutExtension(strFileFullPath) & "-RRLog-Bup-" & i & Path.GetExtension(strFileFullPath) <---------TheComplete path is here C;\RRLogger Data\ County Hunter - K8EMS.mdb
FileCopy(strFileFullPath, strF) <-----After first time thru (strFileFullPath)=C;\RRLogger Data\ County Hunter - K8EMS.mdb and (strF)=County Hunter - K8EMS-RRLog-Bup-1.mdb

In the paths, why do you have semicolons after the C drives instead of colons?
I dont think the trailing slash matters.
Something is just not right in the construct of your absolute paths and the destination paths are defaulting to current directory.
Can you test removing all blanks and that hyphen from your paths?
What happens if the destination path doesn't exist, does it create it, or default to current directory?
This post has been edited by FrankRuperto: Apr 9 2020, 09:30 AM

--------------------
Currently supporting pawnbrokers that use my store management system developed with Access 2010 on Windows7. Experienced with Informix, Oracle & PostgreSQL db's.
Go to the top of the page
 
cheekybuddha
post Apr 9 2020, 09:33 AM
Post#36


UtterAccess Moderator
Posts: 12,803
Joined: 6-December 03
From: Telegraph Hill


@Frank,

strF never gets the actual path, only the filename and extra bit and then the extension.

--------------------


Regards,

David Marten
Go to the top of the page
 
FrankRuperto
post Apr 9 2020, 09:40 AM
Post#37



Posts: 966
Joined: 21-September 14
From: Tampa, Florida USA


He's getting full path on first iteration of the loop, then just filename with no path afterwards and he is using same function that gave him full path for first file.
In the loop, this part of the code never executes after the first iteration, so strF will just have the filename.extension on subsequent iterations, so he needs to append the filename to the absolute path.

CODE
If i = 0 Then
strF = strFileFullPath <----TheComplete path is here C;\RRLogger Data\ County Hunter - K8EMS.mdb

This post has been edited by FrankRuperto: Apr 9 2020, 10:01 AM

--------------------
Currently supporting pawnbrokers that use my store management system developed with Access 2010 on Windows7. Experienced with Informix, Oracle & PostgreSQL db's.
Go to the top of the page
 
mdelke@chartermi...
post Apr 9 2020, 10:14 AM
Post#38



Posts: 11
Joined: 26-March 20



THANK YOU GUYS

finally I have it working the way I would like it to work...... changed

Else
'strF = Path.GetFileNameWithoutExtension(strFileFullPath) & "-RRLog-Bup-" & i & Path.GetExtension(strFileFullPath)

End If

to

Else

strF = Path.GetDirectoryName(strFileFullPath) & "\" & Path.GetFileNameWithoutExtension(strFileFullPath) & "-RRLog-Bup-" & i & Path.GetExtension(strFileFullPath)

End If

you guys have been a great help in getting this problem overcome...........THANK YOU Again
Go to the top of the page
 
AlbertKallal
post Apr 9 2020, 08:17 PM
Post#39


UtterAccess VIP
Posts: 3,053
Joined: 12-April 07
From: Edmonton, Alberta Canada


All good!

I was simply too busy this week - was unable to follow this thread.

That one routine simply checks if the full file path name exists, and adds a _1 to the file name.

Nothing more, nothing less.

Ultimate, one would want to have:


MyFileCopy (strFromFile, strToFolder)

I suppose, one could assume the file name is JUST a file name without path, and have a routine that does this:

MyFileCopy (strFromFile, strFromFolder, strToFolder)


So above would simply copy the file, but if name already exists, then any file like Picture.png would become Picture_1.png etc.

Anyway, others like Frank jumped in - so all is well!

R
Albert
Go to the top of the page
 
2 Pages V < 1 2


Custom Search


RSSSearch   Top   Lo-Fi    24th May 2020 - 06:44 PM