Qbasicnews.com

Full Version: copying files
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
hi
im trying to make some backuip software that will allow me to select some files or directories,add them to a listbox,and then when i click the cmd button it will make a copy of the files,in the direcory that the user has entered in a textbox,i am just having trouble trying to make it copy the files from the listbox, i dont know how to make it take the files and copy them, sorry if you dont understand.
I can't help you with the ListBox control, I'm not well versed in VB. However, I can help ya with the copying.
Well, I'm sure Nath or Loosecaboose or Neo will come alone and say this method is slow, but:
Code:
DIM byte AS STRING *1
OPEN "fileToCopy.txt" FOR BINARY AS #1
OPEN "destinationFile.txt" FOR BINARY AS #2
WHILE NOT EOF(1)
GET #1,,byte
PUT #2,,byte
LOOP
CLOSE #1,#2
There's nothing wrong with your sollution, Zack, but the typo (#1 should be #2 in the second Open), but to perform OS stuff it is better to rely on the OS. You have the filesystem class.

In this snippet I've created a File list box called File1. folderName is a string containing the source path and destFolderName is another string containing the destination path.

Code:
Dim fs, f
        Set fs = CreateObject("Scripting.FileSystemObject")

        File1.path = folderName
        File1.Refresh
                
        l2 = File1.ListCount
        For j = 0 To l2 - 1
            Set f = fs.GetFile(folderName & "\" & File1.List(j))
            f.Copy destFolderName & "\" & File1.List(j)
        Next j
do i replace

Quote: File1.path = folderName
folder name with the folder i want it to back up to or from

and
Quote:Set f = fs.GetFile(folderName & "\" & File1.List(j))
f.Copy destFolderName & "\" & File1.List(j)
where it says destfoldername do i need to put the foldername in or is that done already

thanks guys thats great of you lot.
Just give correct values to folderName and destFolderName, they are string variables Smile
because what the user must do is first , add the files he wants a backup made of , add them to the list box then in another text box type the path of where the files should be copied to, such as c:/cheese and then when s/he clicks the cmd it transfers them ,so is this exactly what the code does??

sorry, i have been learnign qbasic up until now and thought i would try vb6, so i thought i could learn by making,im using the vb black book,great book that!
My code just takes a file list (which has a path property, if you look in MSDN) and copies all the files inside to a new location.

You should modify my code to have it reading from your list box instead, thus removing the use of folderName, being sure that the files are added to the list box with full path info.
Oops, Nath, thanks for pointing that out...I edited it. Smile
I think what he wants to do is. Backup files from different location.

Dougnut, look up filelistbox, dirlistbox and drivelistbox. When the user selects multiple files in the file list box and clicks a button just loop through all the members in the filelistbox and save the complete path of the selected members in a string array. When the user finishes selecting all the files from various folders just loop through the array again and this time run the copy command from the path stored in the array(source) to the backup folder which the user has selected(destination).

Look up all the controls i have mentioned in the MSDN they must have given a working example for each of them.

P.S: I dont have VB installed on this computer so i cant provide you with working code =P.
hmm let me put it a bit more easier to understand,

-There is a textbox in which you type the folder or file you want to back up

-once you have typed the full path in C:\whatever you click a cmd button

-one you click it the path is added to a list box, you then click a new cmd button and it backs up the files to a location specified in textbox2

i dont know if this is even possible,im just trying to make it easier for me to back up my files.
Pages: 1 2 3