• 0

Copying Files


Question

I am new to VB so I need a little help getting started. I need a script that will take an XP system and copy all users My Documents folder to a single file on the C: drive. I would like the files copied to a folder called "Docs" but have the username as a folder inside of the Docs folder. For example users are Bob and Joe I would like the folder to look like this C:\Docs\Bob\My Documents or C:\Docs\Joe\My Documents To throw another wrench into it I will not know how many users there are on a machine. Any Suggestions?

Thanks

-clueless

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

im rather surprised nobody has answered this yet.....

i looked at this this morning but didnt have time to respond

one way of doing this (in reality the only way, its just a matter of how you impliment it) is to recursively recurse the directory and copy each file/directory...

you can do this via pure VB code using Dir(), but personally i prefer the FileSystemObject (in Microsoft Scripting Runtime reference) ... you dont specify VB6 or .NET so im assuming VB6...... if it is NET then you can access the same type of feature within the Microsoft.VisualBasic.FileSystem namespace ( i think it was )

youll set a starting directory like this (vb6) .... and this is a very basic example

dim fso as new filesystemobject

dim f as folder

set f = fso.getfolder("c:\documents and settings")

now, youll have to play with this yourself... but basically youll want to do 2 things

1) store all the directories that are present in f.folders to a collection or an array or whatever you want to use so that you can recurse them

then check for files in the current directory with f.files

rough example:

dim fi as file

for each fi in f.files

fso.filecopy fi.path, <new path>

next

then go through the collection of directories you have searching for more files, also while adding any sub folders to that collection..... this way you process every sub directory and every file

as far as creating a folder based on the user name...... well once you start with the first directory, there are only a handful of system-named directories, such as LocalService, NetworkService......the rest will be user account folders.. so you can create the folder based on that..... process each individually even so the files get in the right place...

hope this help. im going to bed.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.