467,168 Members | 985 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,168 developers. It's quick & easy.

Loop to create new folder

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????
Mar 12 '07 #1
  • viewed: 1140

Post your reply

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

Similar topics

4 posts views Thread by AndrewM | last post: by
1 post views Thread by Vagabond Software | last post: by
4 posts views Thread by I_AM_DON_AND_YOU? | last post: by
2 posts views Thread by kristopher.erickson@gmail.com | last post: by
4 posts views Thread by joaotsetsemoita@gmail.com | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.