dcsimg
Results 1 to 7 of 7

Thread: VB and working with files

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2000
    Location
    MN
    Posts
    1

    Question

    I'm just learning VB, I use it a little in excel and with a compiler. I still haven't learned how to move, copy, delete, or get the name of files. A little help working with files would be great.
    Thanks,
    Shai1

  2. #2
    Hyperactive Member PITBULLCJR's Avatar
    Join Date
    Nov 1999
    Location
    New York
    Posts
    408
    to kill or not to kill
    sorry i had to say that
    heres how to delete a file

    Code:
    FileSystem.Kill "C:\my text.txt"
    U can shorten that to just:

    Code:
    Kill "C:\my text.txt"
    To copy a file to do this:

    Code:
    filesystem.FileCopy "C:\my text.txt", "C:\windows\my text.txt"
    that will move it from c:\ to c:\windows

    if you want to rename a file do the filecopy but change the second name

    Code:
    filesystem.FileCopy "C:\my text.txt", "C:\my new text.txt"
    or:

    move and rename

    Code:
    filesystem.FileCopy "C:\my text.txt", "C:\windows\my new text.txt"
    to cut a file what you have to do is copy it then delte the original

    Code:
    filesystem.FileCopy "C:\my text.txt", "C:\windows\my text.txt"
    FileSystem.Kill "C:\my text.txt"
    I hope this helps you out. ALl of that code can be shortened like the kill command. So you can use:


    Code:
    FileCopy "C:\my text.txt", "C:\windows\my text.txt"
    Kill "C:\my text.txt"
    hope this all helps you out.
    Sincerely,
    Chris


    Email: dark_wanderer13@hotmail.com
    AIM: KnightsOfTheMoon
    WebPage: http://kom.wicre.com
    ----------------
    VB6 Professional
    Abit ST6-RAID
    1000 MHZ
    512 MB PC133 Ram
    Nvidia GeForce 2 Ultra 64 MB
    Maxtor 81.9 Gig
    Win 98 SE

  3. #3
    Guest
    Working with files, for the things you want to do, use the FileCopy, Name, and Kill statements. I think it's the same for in Excel.

    Code:
    'FileCopy - Copy Files
    
    'FileCopy source, destination
    'FileCopy "C:\MyFile.txt", "C:\MyFolder\MyFile.txt"
    
    
    'Name - Move/Rename files
    
    'Name "C:\MyFile.txt", "C:\MyFolder\MyFile.txt"
    'Name "C:\MyFile.txt", "C:\YourFile.txt"
    
    
    'Kill - Delete files
    
    'Kill "C:\MyFile.txt"

  4. #4
    Fanatic Member VBKNIGHT's Avatar
    Join Date
    Oct 2000
    Location
    Port25
    Posts
    619
    To get the name of the files:

    code:
    ----------------------------------------------
    fname = dir(path & "*.*")
    do while fname <> ""
    msgbox fname
    fname = dir()
    loop
    ----------------------------------------------

    If a post has helped you then Please Rate it!

  5. #5
    Fanatic Member
    Join Date
    Feb 2000
    Location
    The Netherlands
    Posts
    715
    Originally posted by VBKNIGHT
    To get the name of the files:

    code:
    ----------------------------------------------
    fname = dir(path & "*.*")
    do while fname <> ""
    msgbox fname
    fname = dir()
    loop
    ----------------------------------------------
    Please format your code nice.

    Code:
    Dim FName As String
    FName = Dir(App.Path & "\*.*") 
    Do While FName <> ""
        MsgBox FName
        FName = Dir()
    Loop
    Btw, I found out how to make horizontal lines.
    [/code]
    [/code]
    [/code]
    [/code]
    [/code]
    [/code]
    [/code]
    [/code]
    Oetje
    oetje@home.nl
    93606776
    Visual Basic 6, Windows 2000

    Never pet a burning dog

  6. #6
    Fanatic Member VBKNIGHT's Avatar
    Join Date
    Oct 2000
    Location
    Port25
    Posts
    619
    how?

    If a post has helped you then Please Rate it!

  7. #7
    Fanatic Member
    Join Date
    Feb 2000
    Location
    The Netherlands
    Posts
    715
    Originally posted by VBKNIGHT
    how?
    To format code:
    [code]
    'code goes here...
    [/code]

    To make an horizontal line:
    [/code]
    or
    [/quote]
    Oetje
    oetje@home.nl
    93606776
    Visual Basic 6, Windows 2000

    Never pet a burning dog

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width