1. Hey Guest Did you know you can win an Honor 10 phone worth ₹33,000 and an additional ₹70,000 in paytm vouchers, just by replying to some threads and taking part in the discussions happening in the Honor Hub?

    What are you waiting for? Start commenting and start winning! Remember to read the instructions posted here.

    Dismiss Notice

How to handle files in VB?

Discussion in 'QnA (read only)' started by naikosen, Feb 8, 2006.

Thread Status:
Not open for further replies.
  1. naikosen

    naikosen New Member

    Joined:
    Sep 2, 2005
    Messages:
    28
    Likes Received:
    0
    Trophy Points:
    0
    I want to use DOS commands like as COPY, MD, DEL, MOVE and so on in Visual Basic.
    How can I do that?
     
  2. siriusb

    siriusb New Member

    Joined:
    May 12, 2005
    Messages:
    1,171
    Likes Received:
    1
    Trophy Points:
    0
    Location:
    Chennai, India, Asia, the Earth, the Solar system,
    You can do those things and more to a file/folder/drive easily using the File System Object model. To enable that, go Project->References and check "Microsoft Scripting Runtime". Now you can do any thing with the files and folders. Example,
    Code:
    Dim fso As New FileSystemObject
    
    fso.CopyFile "c:\syslog.txt", "d:\", True
    fso.CreateFolder "d:\new folder"
    fso.MoveFile "c:\rubbish.txt", "d:\"
    fso.DeleteFile "d:\rubbish.txt", True
    
    Set fso = Nothing
    
     
  3. OP
    OP
    naikosen

    naikosen New Member

    Joined:
    Sep 2, 2005
    Messages:
    28
    Likes Received:
    0
    Trophy Points:
    0
    Thank you very much 'siriusb'

    I'am gonna give it a try.

    Thank you again.
     
  4. Eager_Beever

    Eager_Beever New Member

    Joined:
    May 7, 2004
    Messages:
    19
    Likes Received:
    0
    Trophy Points:
    0
    naikosen, to execute ANY DOS commands within VisualBasic code, try the following :

    varX = Shell("Command.com /c <place the full DOS command here>", vbMinimizedFocus)

    e.g.

    varX = Shell("Command.com /c Type D:\Reports\Bill.Txt", vbMinimizedFocus)
     
  5. Eager_Beever

    Eager_Beever New Member

    Joined:
    May 7, 2004
    Messages:
    19
    Likes Received:
    0
    Trophy Points:
    0
    naikosen, to execute ANY DOS commands within VisualBasic code, try the following :

    varX = Shell("Command.com /c <place the full DOS command here>", vbMinimizedFocus)

    e.g.

    varX = Shell("Command.com /c Type D:\Reports\Bill.Txt", vbMinimizedFocus)
     
  6. vinaypatel

    vinaypatel New Member

    Joined:
    Oct 30, 2004
    Messages:
    227
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Visnagar
    u can use shell also
     
  7. OP
    OP
    naikosen

    naikosen New Member

    Joined:
    Sep 2, 2005
    Messages:
    28
    Likes Received:
    0
    Trophy Points:
    0
    Is there any way to delete a locked file?
    What is the best way to search a file?
    Rar file can delete even a locked file before extraction.
     
  8. siriusb

    siriusb New Member

    Joined:
    May 12, 2005
    Messages:
    1,171
    Likes Received:
    1
    Trophy Points:
    0
    Location:
    Chennai, India, Asia, the Earth, the Solar system,
    I've never tried deleting a locked file. You will want to run your program before windows starts to delete such files. But there's a VC++ example for a forcedel at codeguru.com that claims to do it. Maybe you can port it VB.

    Like I said, use one of these methods:
    1. Use the SearchPath API
    2. Use the FindFirstFile with the FindNextFile APIs
    3. Use the built-in Dir() function
    4. Use the Drivelistbox, Dirlistbox and Filelistbox controls to walk through each directory in every drive to find the file.
    5. Use the FSO drives,folders and files collection to do the same in (4).

    The best way would be to use any of the API methods as they are much faster.
     
  9. OP
    OP
    naikosen

    naikosen New Member

    Joined:
    Sep 2, 2005
    Messages:
    28
    Likes Received:
    0
    Trophy Points:
    0
    Thank you very much again "siriusb"
     
Thread Status:
Not open for further replies.

Share This Page