Copy Folder

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 5968 Views - Last Post: 06 November 2012 - 08:27 AM Rate Topic: -----

#1 sgell  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 16-August 12

Copy Folder

Posted 03 November 2012 - 07:33 AM

I want to copy "c:\Data\Balf", which contains several sub folders to a new folder, "c:\Data\Backup".
I have used the following code:
fs.CopyFolder c:\Data\Balf, c:\Data\Backup
This copies all the sub folders but not c:\Data\Balf
Any hel pwould be much appreciated.
Stephen
Is This A Good Question/Topic? 0
  • +

Replies To: Copy Folder

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5571
  • View blog
  • Posts: 11,910
  • Joined: 02-June 10

Re: Copy Folder

Posted 03 November 2012 - 08:04 AM

Is this perhaps using VB.NET and not the ancient VB6?
http://www.dreaminco...his-is-old-vb6/

is fs.CopyFolder supposed to be FileSystemObject.CopyFolder?
http://msdn.microsof...x(v=VS.84).aspx

Are you aware that c:\Data\Balf is not the path to a folder? It is the path to a file.
c:\Data\Balf\ is the path to a folder. Note the ending \

If you read the documentation (link above) you'll notice that all the folder paths end with \

This post has been edited by tlhIn`toq: 03 November 2012 - 08:06 AM

Was This Post Helpful? 0
  • +
  • -

#3 sgell  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 16-August 12

Re: Copy Folder

Posted 03 November 2012 - 08:21 AM

Thank you for your very quicj reply:

Is this perhaps using VB.NET and not the ancient VB6? Using VB6

is fs.CopyFolder supposed to be FileSystemObject.CopyFolder?Yes - fs.CopyFolder SourcePath, DestinationPath

Are you aware that c:\Data\Balf is not the path to a folder? It is the path to a file.
Changed c:\Data\Balf to c:\Data\Balf\ and received error 76 P{ath not found.

Stephen
Was This Post Helpful? 0
  • +
  • -

#4 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5571
  • View blog
  • Posts: 11,910
  • Joined: 02-June 10

Re: Copy Folder

Posted 03 November 2012 - 09:59 AM

That's the end of my suggestions. Its a language way older than my experience. There might be a few people still alive that use it that might be able to help you.

Is there any reason you can't move forward 40 years and start learning VB.NET instead of VB6?
Was This Post Helpful? 0
  • +
  • -

#5 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: Copy Folder

Posted 03 November 2012 - 04:18 PM

then try adding a \ to C:\Data\Backup\, like that.
Was This Post Helpful? 0
  • +
  • -

#6 sgell  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 16-August 12

Re: Copy Folder

Posted 04 November 2012 - 03:47 AM

Thanks for your reply but still not fixed.

SourcePath ="c:\Data\Balf"
DestinationPath = "c:\Data\Backup"
fs.CopyFolder SourcePath, DestinationPath

This results in c:\Data\Backup being created with all the sub folders from c:\Data\Balf but I would like c:\Data\Backup
to contain the folder c:\Data\Balf with its subfolders.

I have tried adding a \ to source only, destination only and both paths but each results in a Path Not Found error.

If you can help it would be much appreciated.

Stephen
Was This Post Helpful? 0
  • +
  • -

#7 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 300
  • View blog
  • Posts: 1,781
  • Joined: 26-March 09

Re: Copy Folder

Posted 04 November 2012 - 04:19 AM

You're telling it to copy the contents of the Source folder to your destination folder, which is what it is doing.

Try changing it so that your Destination folder is C:\Data\Backup\Balf, that way you'll get the structure that you want including all the contents.

This post has been edited by maj3091: 04 November 2012 - 04:33 AM

Was This Post Helpful? 0
  • +
  • -

#8 sgell  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 16-August 12

Re: Copy Folder

Posted 04 November 2012 - 05:07 AM

View Postmaj3091, on 04 November 2012 - 04:19 AM, said:

You're telling it to copy the contents of the Source folder to your destination folder, which is what it is doing.

Try changing it so that your Destination folder is C:\Data\Backup\Balf, that way you'll get the structure that you want including all the contents.


Tried adding + "\Balfour" and + "\Balfour\"
both still result in a Path not found error.
Was This Post Helpful? 0
  • +
  • -

#9 sgell  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 16-August 12

Re: Copy Folder

Posted 04 November 2012 - 05:15 AM

View Postsgell, on 04 November 2012 - 05:07 AM, said:

View Postmaj3091, on 04 November 2012 - 04:19 AM, said:

You're telling it to copy the contents of the Source folder to your destination folder, which is what it is doing.

Try changing it so that your Destination folder is C:\Data\Backup\Balf, that way you'll get the structure that you want including all the contents.


Tried adding + "\Balfour" and + "\Balfour\"
both still result in a Path not found error.


Sorry meant
Tried adding + "\Balf" and + "\Balf\"
Was This Post Helpful? 0
  • +
  • -

#10 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5571
  • View blog
  • Posts: 11,910
  • Joined: 02-June 10

Re: Copy Folder

Posted 04 November 2012 - 07:11 AM

Did you try making the folder first?
I'm sorry if this sounds mean... but you seem quite helpless. It feels as if you try one thing, then come back here. You won't hurt your computer through experimentation. Trial and error. Put some breakpoints I your code and confirm the values (paths) you are using. This is pretty typical debugging and trial & error.

TIP: Don't replace lines of code that don't work. Instead comment them out and put your new attempts below that. This will keep you from re-trying the same ideas over and over. Also, when you come back to us saying "I've tried this 100 different ways and still can't get it", we can actually see what you tried. So often a failed attempt is very very close and just needs a little nudge in the right direction. So if we can say "See what you did in attempt 3... blah blah" it helps a lot

// Try #1 - May 1, 0900hrs
//    code
//    code  
//    code
// Try #2 - May 2, 1700hrs   Okay, plan B.  What if I do it *this* way
//    code
//    code  
//    code
// Try #14 - May 3, 0500hrs after 5 cans of RedBull.  Maybe I should get some sleep. I can't think of anything else but this last idea
    code
    code  
    code


If you are using Visual Studio you can select a block of lines and hit control+k control+c (Kode Comment) to comment it out. control+k control+u (Kode Uncomment) to uncomment a selected block.

FAQ: I do x and y happens which I didn't expect but I don't know how to figure out why. How do I debug and find my problem?
A:

This post has been edited by tlhIn`toq: 04 November 2012 - 07:13 AM

Was This Post Helpful? 0
  • +
  • -

#11 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 300
  • View blog
  • Posts: 1,781
  • Joined: 26-March 09

Re: Copy Folder

Posted 04 November 2012 - 01:13 PM

The destination needs to exist!
Was This Post Helpful? 0
  • +
  • -

#12 sgell  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 16-August 12

Re: Copy Folder

Posted 05 November 2012 - 07:02 AM

View Postmaj3091, on 04 November 2012 - 01:13 PM, said:

The destination needs to exist!


Thanks for your comments however the code reads:
Dim fs As New Scripting.FileSystemObject
Set fs = New Scripting.FileSystemObject
fs.CopyFolder "c:\Balfour Data\Balfour", "C:\Balfour Data\Backup"
Set fs = Nothing

so I don't know where you think I should put breaks or read values!

This code correctly copies the subfolders of c:\Balfour Data\Balfour to C:\Balfour Data\Backup
whereas I want it to copy the folder (with the subfolders)

fs.CopyFolder "c:\Balfour Data\Balfour\", "C:\Balfour Data\Backup"
fs.CopyFolder "c:\Balfour Data\Balfour\", "C:\Balfour Data\Backup\"
fs.CopyFolder "c:\Balfour Data\Balfour", "C:\Balfour Data\Backup\"
all result in Error 76: Path not found

If I first create C:\Balfour Data\Backup it gives the same result as when the folder was not there.

Stephen
Was This Post Helpful? 0
  • +
  • -

#13 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 300
  • View blog
  • Posts: 1,781
  • Joined: 26-March 09

Re: Copy Folder

Posted 05 November 2012 - 09:34 AM

Strange, because it works for me.

You said you have a folder called C:\Data\Balf with subfolders and files in each level and you want to copy that folder, including the top level folder to C:\Data\Backup, so that you will end up with the following structure.

C:\Data\Backup\Balf
C:\Data\Backup\Balf\Sub1
C:\Data\Backup\Balf\Sub2
Etc.

so fs.CopyFolder "C:\Data\Balf", "C:\Data\Backup\Balf" will give you what you want.

Did you actually try my suggestion as your last post suggests you didn't?

This post has been edited by maj3091: 05 November 2012 - 09:34 AM

Was This Post Helpful? 0
  • +
  • -

#14 sgell  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 16-August 12

Re: Copy Folder

Posted 05 November 2012 - 09:47 AM

View Postmaj3091, on 05 November 2012 - 09:34 AM, said:

Strange, because it works for me.

You said you have a folder called C:\Data\Balf with subfolders and files in each level and you want to copy that folder, including the top level folder to C:\Data\Backup, so that you will end up with the following structure.

C:\Data\Backup\Balf
C:\Data\Backup\Balf\Sub1
C:\Data\Backup\Balf\Sub2
Etc.

so fs.CopyFolder "C:\Data\Balf", "C:\Data\Backup\Balf" will give you what you want.

Did you actually try my suggestion as your last post suggests you didn't?


I did create a new folder C:\Data\Backup but still only the subfolders copied.
Added \backup to the destination and still got Path Not Found.
The only line that does not produce an error is
fs.CopyFolder "C:\Data\Balf", "C:\Data\Backup" - this creates c:\DataBackup but only copies the subfolders.

Stephen
Was This Post Helpful? 0
  • +
  • -

#15 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 300
  • View blog
  • Posts: 1,781
  • Joined: 26-March 09

Re: Copy Folder

Posted 05 November 2012 - 12:28 PM

You need to re-read what I've written.

You need to create the folder C:\Data\Backup\Balf, then execute the command as I wrote it.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2