DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: Re: File Sync - Arthur Wood.

  1. #1
    Chris Guest

    Re: File Sync - Arthur Wood.


    Hi again Arthur,
    I have posted my reply to your query. Here is my code.

    **** START *****
    Private Sub Command1_Click()
    path1 = "C:\PATH1\" ' THis is path one which has A.txt(latest modified)
    path2 = "C:\PATH2\" ' THis is path two which also has A.txt (old)

    'Goal is to copy A.txt from path1 to path2 or VICE VERSA
    'and if not found do a blind copy. And yes its more than 1 file at each
    'path

    If path1 <> "" Or path2 <> "" Then

    path1_filename = Dir(path1) ' get the first file from path1 say A.txt

    If path1_filename = "" Then
    MsgBox "Folder/File doesn't exist"
    Exit Sub
    End If

    Do While path1_filename <> ""
    'Complete path to filename for file in path1
    temp_path1 = path1 + path1_filename

    'Create path with the same file name for path2
    temp_path2 = path2 + path1_filename

    'Call a function to check if the SAME file exists on path2
    'This is where I get stuck cause I can't use the Dir
    'recursivley
    check = FileCheck(temp_path2)

    If check = 0 Then
    Debug.Print "File Found in path2
    'If found I can compare the lastmodified date for the two
    Else
    Debug.Print "Not Found"
    'If not found I will copy it to path2
    End If
    'Move to the next file. It shouts at me for doing this!!!!
    path1_filename = Dir
    Loop

    End If
    End Sub

    'Simple function to check if the file in path1 exits in path2
    'Dirname is the path to path2 with the path1 filename.

    Function FileCheck(Dirname) As String

    If Dir(Dirname, vbNormal) <> "" Then
    FileCheck = 1
    Else
    FileCheck = 0
    End If

    End Function
    **** END *****








    "Chris" <Krishnan.O.Srinivasan@med.ge.com> wrote:
    >
    >Hi Arthur,
    > When I use the word Sync I am refering to files only and NOT the data
    >in them. To make it simple assume that you have two
    >directories
    >
    >C:\Arthur\A.txt
    >C:\Chris\A.txt
    >
    >Lets say the first time I make changes to a fie and save it to my space

    at
    >c:\Chris\A.txt and when I hit the sync button it should check to see if

    my
    >file (A.txt) is greater than yours (lastmodified date) if so, use the FileCopy
    >tool to overwrite it . hence at any given time I should have the same file
    >at both the places. It gets tricky here. I can't use the Dir fn in a recursive
    >manner !
    >
    >So I would re-phrase it like version control as opposed to sync.
    >
    >Thanks
    >Krishnan Srinivasan
    >
    >
    >"Arthur Wood" <wooda@saic-trsc.com> wrote:
    >>
    >>Chris,
    >> What exactly do you mean by "synch"--is it the case that both files

    >may
    >>contain common entries, but also each file will also have it's own set

    of
    >>additional entries, and what you want in the final output is only a single
    >>copy of the common entries, along with the entries which are unique to

    each
    >>of the individual files?
    >>
    >>Are the Common entries in the same order in each file?
    >>
    >>Arthur Wood
    >>
    >>
    >>
    >>"Chris" <Krishnan.O.Srinivasan@med.ge.com> wrote:
    >>>
    >>>Hi , I am new to VB and this has been my only resource that I need to

    get
    >>>ahead. I am facing a weird problem for which I couldn't find the solution
    >>>at your web site.
    >>>
    >>>I have to write a vb app that would sync two files sitting in two different
    >>>directories and when I hit on a "Sync" button both directories should

    have
    >>>the latest/greatest files. Can you advice me on how I should approach

    this
    >>>?
    >>>
    >>>Thanks for your time and consideration
    >>>
    >>>Krishnan Srinivasan
    >>>Web Developer, e-business.
    >>>GE Medical Systems.
    >>>

    >>

    >



  2. #2
    Patrick Marshall Guest

    Re: File Sync - Arthur Wood.


    Hi Chris,

    Consider using the FileDateTime function to check the file date. Just assume
    that the file is in each location and trap for the error if the file is missing.
    You will need to provide the full path to each file, e.g.

    on error resume next 'NEVER USE THIS WITHOUT FOLLOWING WITH A REAL ERR TRAP
    FileDate = FileDateTime ("c:\test\a.txt")
    if error = 53 then 'file not found
    'not found, do something here
    end if
    on error resume errtrap

    "Chris " <Krishnan.O.Srinivasan@med.ge.com> wrote:
    >
    >Hi again Arthur,
    > I have posted my reply to your query. Here is my code.
    >
    >**** START *****
    >Private Sub Command1_Click()
    >path1 = "C:\PATH1\" ' THis is path one which has A.txt(latest modified)
    >path2 = "C:\PATH2\" ' THis is path two which also has A.txt (old)
    >
    >'Goal is to copy A.txt from path1 to path2 or VICE VERSA
    >'and if not found do a blind copy. And yes its more than 1 file at each


    >'path
    >
    >If path1 <> "" Or path2 <> "" Then
    >
    >path1_filename = Dir(path1) ' get the first file from path1 say A.txt
    >
    > If path1_filename = "" Then
    > MsgBox "Folder/File doesn't exist"
    > Exit Sub
    > End If
    >
    > Do While path1_filename <> ""
    > 'Complete path to filename for file in path1
    > temp_path1 = path1 + path1_filename
    >
    > 'Create path with the same file name for path2
    > temp_path2 = path2 + path1_filename
    >
    > 'Call a function to check if the SAME file exists on path2
    > 'This is where I get stuck cause I can't use the Dir
    > 'recursivley
    > check = FileCheck(temp_path2)
    >
    > If check = 0 Then
    > Debug.Print "File Found in path2
    > 'If found I can compare the lastmodified date for the two
    > Else
    > Debug.Print "Not Found"
    > 'If not found I will copy it to path2
    > End If
    > 'Move to the next file. It shouts at me for doing this!!!!
    > path1_filename = Dir
    > Loop
    >
    >End If
    >End Sub
    >
    >'Simple function to check if the file in path1 exits in path2
    >'Dirname is the path to path2 with the path1 filename.
    >
    >Function FileCheck(Dirname) As String
    >
    > If Dir(Dirname, vbNormal) <> "" Then
    > FileCheck = 1
    > Else
    > FileCheck = 0
    > End If
    >
    >End Function
    >**** END *****
    >
    >
    >
    >
    >
    >
    >
    >
    >"Chris" <Krishnan.O.Srinivasan@med.ge.com> wrote:
    >>
    >>Hi Arthur,
    >> When I use the word Sync I am refering to files only and NOT the

    data
    >>in them. To make it simple assume that you have two
    >>directories
    >>
    >>C:\Arthur\A.txt
    >>C:\Chris\A.txt
    >>
    >>Lets say the first time I make changes to a fie and save it to my space

    >at
    >>c:\Chris\A.txt and when I hit the sync button it should check to see if

    >my
    >>file (A.txt) is greater than yours (lastmodified date) if so, use the FileCopy
    >>tool to overwrite it . hence at any given time I should have the same file
    >>at both the places. It gets tricky here. I can't use the Dir fn in a recursive
    >>manner !
    >>
    >>So I would re-phrase it like version control as opposed to sync.
    >>
    >>Thanks
    >>Krishnan Srinivasan
    >>
    >>
    >>"Arthur Wood" <wooda@saic-trsc.com> wrote:
    >>>
    >>>Chris,
    >>> What exactly do you mean by "synch"--is it the case that both files

    >>may
    >>>contain common entries, but also each file will also have it's own set

    >of
    >>>additional entries, and what you want in the final output is only a single
    >>>copy of the common entries, along with the entries which are unique to

    >each
    >>>of the individual files?
    >>>
    >>>Are the Common entries in the same order in each file?
    >>>
    >>>Arthur Wood
    >>>
    >>>
    >>>
    >>>"Chris" <Krishnan.O.Srinivasan@med.ge.com> wrote:
    >>>>
    >>>>Hi , I am new to VB and this has been my only resource that I need to

    >get
    >>>>ahead. I am facing a weird problem for which I couldn't find the solution
    >>>>at your web site.
    >>>>
    >>>>I have to write a vb app that would sync two files sitting in two different
    >>>>directories and when I hit on a "Sync" button both directories should

    >have
    >>>>the latest/greatest files. Can you advice me on how I should approach

    >this
    >>>>?
    >>>>
    >>>>Thanks for your time and consideration
    >>>>
    >>>>Krishnan Srinivasan
    >>>>Web Developer, e-business.
    >>>>GE Medical Systems.
    >>>>
    >>>

    >>

    >



  3. #3
    Patrick Marshall Guest

    Re: File Sync - Arthur Wood.


    Hi Chris,

    Sorry, typo in line:

    if error = 53 then 'file not found

    should be:

    if err = 53 then 'file not found

  4. #4
    Douglas J. Steele Guest

    Re: File Sync - Arthur Wood.

    "Patrick Marshall" <nospam@nospam.com> wrote in message
    news:3b326eaa$1@news.devx.com...
    >
    > Hi Chris,
    >
    > Sorry, typo in line:
    >
    > if error = 53 then 'file not found
    >
    > should be:
    >
    > if err = 53 then 'file not found


    Actually, to be precise, shouldn't it be

    if err.number = 53 then 'file not found

    (It's not unheard of for MS to change default behaviours!)

    --
    Doug Steele, Microsoft Access MVP
    http://I.Am/DougSteele/






  5. #5
    Patrick Marshall Guest

    Re: File Sync - Arthur Wood.


    Hi Douglas,

    Quite true, but you can always do a global replace on " err =* then " with
    " err.number=* then "

    With ALL the changes in VB.net, err is the least of my worries :-(

    I suppose they have gotten rid of the undocumented keyword erl (error line
    number) in VB.Net. Does anyone know?

    <Patrick>

    "Douglas J. Steele" <djsteele@canada.com> wrote:
    >"Patrick Marshall" <nospam@nospam.com> wrote in message
    >news:3b326eaa$1@news.devx.com...
    >>
    >> Hi Chris,
    >>
    >> Sorry, typo in line:
    >>
    >> if error = 53 then 'file not found
    >>
    >> should be:
    >>
    >> if err = 53 then 'file not found

    >
    >Actually, to be precise, shouldn't it be
    >
    >if err.number = 53 then 'file not found
    >
    >(It's not unheard of for MS to change default behaviours!)
    >
    >--
    >Doug Steele, Microsoft Access MVP
    >http://I.Am/DougSteele/
    >
    >
    >
    >
    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center