Link to home
Start Free TrialLog in
Avatar of angus_young_acdc
angus_young_acdcFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Get List of Specific Amount of Files From Directory

Hello Experts,

I have to copy 75GB worth of files from various sub folders in a directory, of course this would take a right ole age to actually complete, and as our companies network is notoriously bad the idea is to potentially copy X GB worth of the data at a time overnight.

My question is this, how exactly can I implement something to get X GB worth of files?  I've had a look at Directory.GetFiles and DirectoryInfo GetFiles methods, but neither of them appear to have a limit.  Ideally I would like something, similar to SQL, where I could just have (obviously in C# not SQL :-P ) SELECT TOP 10000 and get a set amount of data.

Is this possible?  And if so, how can I do it?
Avatar of Kamal Khaleefa
Kamal Khaleefa
Flag of Kuwait image

hi
i suggest on you to manually separate the files you have into many subfolders
and manually put in each folder amount of 10 GB for exampe
then in your code create an array of the paths to these folders
and make a loop through them

also
another solution is
writte a code to read file by file and store the length in a variable and when this variable is about 10 GB make a copy


some helpful code may be this


  Dim files() As String
          
                files = Directory.GetFiles("\\path to your files")
           

          

            For i As Integer = 0 To files.Count - 1
                Dim File_Name As String = ""
                File_Name = files(i).Remove(0, files(i).LastIndexOf("\") + 1)

                Dim beg As Integer = File_Name.IndexOf(".")
                Dim lngth As Integer = File_Name.Length
                If beg <> -1 Then
                    File_Name = File_Name.Remove(beg, lngth - beg)  

                 

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of ph_o_enix
ph_o_enix

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Lucian Constantin
If C# is not a requirement - you could use ROBOCOPY in 2 different ways:
1. One suggestion is to use the /MIR parameter (for mirroring that 2 "roots") and if "move" is needed you can delete the "source" folder when mirroring is complete
2. You cand copy files based on their "age" so you could move the files based on their "creation time" with /MAXAGE /MINAGE parameters

Or a 3rd approach - you can use ROBOCOPY with multiple passes to copy large files "over-night" and small files whenever you want so finally you'll have all the files on the new location...
>>but neither of them appear to have a limit.
So, you want a limit?
Limit input sample 75.1 GB,  because you want 75.GB
And after limit has reach, you want an alert?
Avatar of angus_young_acdc

ASKER

I just ended up copying them all, however this would appear to provide a solution in C#