Results 1 to 14 of 14
  1. #1
    Uranium Lounger CWBillow's Avatar
    Join Date
    Jul 2002
    Location
    Las Vegas, NV USA
    Posts
    6,371
    Thanks
    78
    Thanked 12 Times in 11 Posts

    Copying files (VB 6)

    Is there a way (VB? VBScript?) To set up batch files in windows to copy files from one folder to another (like backing up)?

    I know you can do this in a command window, but how might you do it so it is like copying directly in Windows?

    Batch files just open the command window.

    Regards,
    Chuck Billow
    -------------------------------------------------
    "Good judgment comes from experience, and experience - well, that comes from poor judgment."

    ~ A(lan) A(lexander) Milne (1882-1956)- "House at Pooh Corner"

  2. #2
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Copying files (VB 6)

    Chuck,

    Just create a batch file that will do the job, then test it to make sure it does the right things, then use the task scheduler to automate it.

    StuartR

  3. #3
    Uranium Lounger CWBillow's Avatar
    Join Date
    Jul 2002
    Location
    Las Vegas, NV USA
    Posts
    6,371
    Thanks
    78
    Thanked 12 Times in 11 Posts

    Re: Copying files (VB 6)

    Stuart:

    That'll do the job... Thanks.

    Is there a way to make that operate "totally within Windows" as opposed to opening up a command window?

    Chuck
    -------------------------------------------------
    "Good judgment comes from experience, and experience - well, that comes from poor judgment."

    ~ A(lan) A(lexander) Milne (1882-1956)- "House at Pooh Corner"

  4. #4
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Copying files (VB 6)

    You can make this operate "totally within windows" by allowing it to open a Command Window. Is there any problem caused by the type of window that it uses?

    StuartR

  5. #5
    Uranium Lounger CWBillow's Avatar
    Join Date
    Jul 2002
    Location
    Las Vegas, NV USA
    Posts
    6,371
    Thanks
    78
    Thanked 12 Times in 11 Posts

    Re: Copying files (VB 6)

    Stuart:

    No, no. I just thought that the way, say explorer copies files (in a window) could be applied here -- a very simple example to use for "learning" the methods etc. -- like, when VB, VBScript, or vba...

    Regards,
    Chuck
    -------------------------------------------------
    "Good judgment comes from experience, and experience - well, that comes from poor judgment."

    ~ A(lan) A(lexander) Milne (1882-1956)- "House at Pooh Corner"

  6. #6
    5 Star Lounger st3333ve's Avatar
    Join Date
    May 2003
    Location
    Los Angeles, California, USA
    Posts
    705
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Copying files (VB 6)

    I'm not a VBScript guy myself, but my understanding is you can use VBScript to copy, move, delete, etc. files & folders. See here, for example.

  7. #7
    Uranium Lounger CWBillow's Avatar
    Join Date
    Jul 2002
    Location
    Las Vegas, NV USA
    Posts
    6,371
    Thanks
    78
    Thanked 12 Times in 11 Posts

    Re: Copying files (VB 6)

    st3333ve:

    I'm not either, but that'll sure point me in a good direction...

    Thanks.

    Regards,
    Chuck
    -------------------------------------------------
    "Good judgment comes from experience, and experience - well, that comes from poor judgment."

    ~ A(lan) A(lexander) Milne (1882-1956)- "House at Pooh Corner"

  8. #8
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Copying files (VB 6)

    Of course one could create a new program with the copying functionality of Windows Explorer and the nice "flying document" progress bars, but I don't think anyone would consider it worth re-inventing the wheel!

  9. #9
    Uranium Lounger CWBillow's Avatar
    Join Date
    Jul 2002
    Location
    Las Vegas, NV USA
    Posts
    6,371
    Thanks
    78
    Thanked 12 Times in 11 Posts

    Re: Copying files (VB 6)

    Jefferson:

    I'm (truly) not out to re-invent the wheel... I's just by simple projects I can extrapolate... I've learned *just enough* VBasic to understand, for instance, the "window" premise...

    I cannot however, glom onto such commands as "copy" which, as noted, throw up a command window.

    I often find that my needs encompass a combination of pieces of various programs already out there, none of which is customizable.

    What I'd like to be able to do is customize for the projects I find myself constantly faced with... Just little things like syncing directories (folders) or files... Yes, I know (now) about the "SyncToy"... But:

    If I know I plan to use that, for instance, every day, on several folders, AND I want some error-trapping built in (overwrite Yes/No?) Then some form of coding seems inevitable.

    I've "started" VB6, but it seems a great deal more than I need... where maybe (vbscript) or (vba) would work...

    Chuck
    -------------------------------------------------
    "Good judgment comes from experience, and experience - well, that comes from poor judgment."

    ~ A(lan) A(lexander) Milne (1882-1956)- "House at Pooh Corner"

  10. #10
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Copying files (VB 6)

    > I cannot however, glom onto such commands as "copy" which, as noted, throw up a command window.

    I misunderstood, I thought you wanted something drag-and-drop like Windows Explorer.
    <UL><LI>Visual Basic has a built-in copy command, FileCopy, that doesn't open any windows.

    <LI>The Scripting library has the somewhat more flexible FileSystemObject which has a couple different ways to copy, neither of which necessitates any windows.

    <LI>Batch files can be launched without any visible window, I believe, or perhaps it is with a minimized window. This can be set somewhere in the shortcut or, if you are using the shell to run the batch file from VB/VBS, somewhere in the shell command or run method.
    [/list]Lots of options.

  11. #11
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Copying files (VB 6)

    The third option mentioned by Jefferson can be achieved using something like:
    <code>
    Shell Environ("ComSpec") & " /c copy c:file1.txt c:file2.txt", vbHide
    </code>
    The vbHide will prevent any new console window from appearing at all.

    Alan

  12. #12
    Uranium Lounger CWBillow's Avatar
    Join Date
    Jul 2002
    Location
    Las Vegas, NV USA
    Posts
    6,371
    Thanks
    78
    Thanked 12 Times in 11 Posts

    Re: Copying files (VB 6)

    Alan:

    Ok... Now this command set you just gave me:

    Shell Environ("ComSpec") & " /c copy c:file1.txt c:file2.txt", vbHide

    Cannot be used in a shortcut. I know I can use this within Office as a macro... How would something like this be modified to operate directly from, say, the Windows (XP) desktop?

    Regards,
    Chuck
    -------------------------------------------------
    "Good judgment comes from experience, and experience - well, that comes from poor judgment."

    ~ A(lan) A(lexander) Milne (1882-1956)- "House at Pooh Corner"

  13. #13
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Copying files (VB 6)

    To run the equivalent from the Windows desktop, you'd probably be better off using a .BAT or .VBS file, saved directly on the desktop.

    For a .BAT file, the line would be:
    cmd /c copy c:file1.txt c:file2.txt

    To make the running as unobtrusive as possible, set the Properties of the .BAT file as shown below. This will generate a .PIF (shortcut) file to run the .BAT from.

    For a .VBS it would be:
    Dim fso, MyFile
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set MyFile = fso.GetFile("c:file1.txt")
    MyFile.Copy ("c:file2.txt")

    Alan

  14. #14
    Uranium Lounger CWBillow's Avatar
    Join Date
    Jul 2002
    Location
    Las Vegas, NV USA
    Posts
    6,371
    Thanks
    78
    Thanked 12 Times in 11 Posts

    Re: Copying files (VB 6)

    Alan:

    Those sure help...

    I'll give some of these a try...

    Thanks,
    Chuck
    -------------------------------------------------
    "Good judgment comes from experience, and experience - well, that comes from poor judgment."

    ~ A(lan) A(lexander) Milne (1882-1956)- "House at Pooh Corner"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •