By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,717 Members | 2,069 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,717 IT Pros & Developers. It's quick & easy.

Loop to create new folder

P: 8
I need to create a new folder every time the upload folder has 10 files uploaded to it. So when folder1 has 10 files, folder2 is created and becomes the upload folder, and when it has 10 files uploaded to it folder3 is created and so on.....

Problem is that my code creates all the next folders all at once. I need it to create the next folder when it is required. i.e. when the previous folder has reached 10 files.

If anyone can explain where I am going wrong I would appreciate it. txs.

Expand|Select|Wrap|Line Numbers
  1. 'Get number of files in current dir
  2. Dim CurrentDir() As String = Directory.GetFiles(Server.MapPath("UploadedPictures/subfolder1/"))
  3. 'If current directory has 10 files, then create new directory, else save it to current dir
  4.    If CurrentDir.Length > 10 Then
  5.        Dim a As Integer
  6.         For a = 1 To 10 (or infinite)
  7.        Dim dir As New DirectoryInfo(Server.MapPath("UploadedPicturesThb/" & a & "subFolder" & "/"))
  8.             If dir.Exists = True Then
  9.                     Dim fi() As FileInfo = dir.GetFiles("*.jpg")
  10.                     If fi.Length <= 10 Then
  11.                         ' save jpg to folder
  12.                     End If
  13.                 Else
  14.                     di.Create()
  15.                    ' save jpg to folder
  16.                 End If
  17.             Next
  18.         Else
  19.             ' save jpg to folder
  20.         End If
  21. 'Need to get name of current upload directory so that I can add it to the database????
  22.  
Mar 12 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.