Copying a file to a random directory
Copying a file to a random directory
Copying a file to a random directory
Copying a file to a random directory
Copying a file to a random directory
Copying a file to a random directory Copying a file to a random directory Copying a file to a random directory Copying a file to a random directory Copying a file to a random directory Copying a file to a random directory Copying a file to a random directory Copying a file to a random directory
Copying a file to a random directory Copying a file to a random directory
Copying a file to a random directory
Go Back  Xtreme Visual Basic Talk > > > Copying a file to a random directory


Reply
 
Thread Tools Display Modes
  #1  
Old 08-17-2009, 01:05 PM
HarrisonGT HarrisonGT is offline
Newcomer
 
Join Date: Aug 2009
Posts: 1
Question Copying a file to a random directory


I signed-up to this website to have this question answered because it has been bugging me for like a week now....
I have searched the forums on countless sites and found nothing...
So now I need your help...
This is what I am trying to do...

I am trying to make a program to teach people about cyber security using a game-like atmosphere (In VB 2008 Express Edition)...
The program itself copyies another exe file (a fake virus) from the "C:\" directory to a random (yet valid) directory and runs the program...The program then shows some hints based on the "virus's" name and location...Different difficulties giving different amounts of info...
The user then trys to find the "virus" in the file system and delete it...When they are finished the program records the time it took them to complete the challenge...

I have the timing system and the difficulty setting (with hint system) created as well as the "virus" iteself (the "virus" simply being a form that won't close) but I can't figure out how to copy the "virus" to a random folder in the file system...

Thank you very much for reading...
Reply With Quote
  #2  
Old 08-17-2009, 11:31 PM
stumper66 stumper66 is offline
Regular
 
Join Date: Jul 2005
Location: Seattle, Washington, USA
Posts: 86
Default

I would enumerate all folders into an array, then generate a random number.

For example:
Code:
        Dim d As New DirectoryInfo("c:\")

        Dim DIs As DirectoryInfo() = d.GetDirectories("*.", SearchOption.AllDirectories)
        Dim NumOfDirs = DIs.Length

        Dim DirectoryNames(NumOfDirs) As String

        For i As Integer = 0 To NumOfDirs
            DirectoryNames(i) = DIs(i).FullName
        Next
        DIs = Nothing

        Dim rand As New Random()

        'Get random directory
        Dim num As Integer = rand.Next(0, NumOfDirs)
        MessageBox.Show(DirectoryNames(num))
However, the above code will fail when it runs into a access denied folder, such as it did when I tested it. Since the only solution I can think of is to go to each folder, enumerate all folders, then create a directory info for each one, then do the same for all child folders, using a try/catch block for each enumeration so you can skip that folder if you are denied access.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Copying a file to a random directory
Copying a file to a random directory
Copying a file to a random directory Copying a file to a random directory
Copying a file to a random directory
Copying a file to a random directory
Copying a file to a random directory Copying a file to a random directory Copying a file to a random directory Copying a file to a random directory Copying a file to a random directory Copying a file to a random directory Copying a file to a random directory
Copying a file to a random directory
Copying a file to a random directory
 
Copying a file to a random directory
Copying a file to a random directory
 
-->