using counter to name folder

users launch app and asked are they generating folder or file the user selects what they want. the users then enter a name of a folder or file. I am need to number these folders or files via a counter(counter amount also entered by user)

i.e. userfolder_01, userfolder_02 etc.

hello?

a loop with a counter

something like

[code]for i as integer 0 o to userEnteredCount

  dim newName as string = "userfolder_" + format(i,"000")

 create the new folder - I assume you have code for this ?

next
[/code]

Sorry my first post got wacky…

This is an example of my a screen shot of a canvas and tehn asks you to save it as a file. The auto generation in the name of the file is made by the timestamp string.
HTH

  Dim pict As Picture
  Dim d as new Date
  // Create Timestamp for ScreenCapture Save Name
  Dim timeStamp as string =  str(d.Minute) + str(d.Second)
  Dim f as FolderItem = GetSaveFolderItem("image/png","ScreenCapture_" + timeStamp + ".png")
  
  If f <> Nil then
    //CREATE PICTURE OBJECT, SELF IS THE FORM WINDOW
    pict = New Picture(self.Width, self.Height, 32)
    //CREATE A PICTURE OF THE CURRENT WINDOW
    Self.DrawInto pict.Graphics, 0, 0
    // Save the image out to the file
    pict.Save(f, Picture.SaveAsPNG)
  end if

Yes, everything is done except the rename of the folder.

Will try the above… this is part of what I am working on. Thanks for the help… i am getting quite frustrated with my inability to grasp the simple. As you can see… i do get a msgbox… this is how i am able to tell the loop is correct and that it is adding the count at the end of the folder or file name.

Dim dlg as New SaveAsDialog
dim f, p as FolderItem
//dim p as FolderItem
//Dim nf as FolderItem
Dim currentFolder as FolderItem
dlg.InitialDirectory=SpecialFolder.Mount
dlg.SuggestedFileName= “TET14_000”
dlg.promptText=“Please enter the Project Number”
Dim counter As Integer = val (TextField1.Text)
f=dlg.ShowModal()
p=f
dim n as integer
For n = 1 to counter
f=p

MsgBox f.AbsolutePath + "_" + str(n)

f.CreateAsFolder

Make sure you put code in code blocks (there’s a button t the upper right when you type some in)
it helps format it nicer

Dim dlg as New SaveAsDialog
dim parent as FolderItem
Dim currentFolder as FolderItem
dlg.InitialDirectory=SpecialFolder.Mount
dlg.SuggestedFileName= "TET14_000"
dlg.promptText = "Please enter the Project Number"
Dim counter As Integer = val (TextField1.Text) // not sure where this comes from ????
parent = dlg.ShowModal()

if parent is nil then return // this means they hit cancel

// parent is either a new folder OR one they selected 

For n as integer  = 1 to counter

  // we want to create folders INSIDE the one they select 
  dim thisChild as FolderItem = parent.Child( str(n) )
 
  thisChild.CreateAsFolder

next

made the changes above and getting an exception error on thisChild.CreateAsFolder

will try to put things into code blocks.

thank you

I wrote mine in the reply only so there certain can be bugs :stuck_out_tongue:
It was more “something like this but you’ll probably have to tweak it”

Gotcha… Thanks Norman!

I have an app that needs to create a folder incrementally numbered from any that already exist with the same name, even if it is at a later running of the app. The way I solved it was by, after determining the folder’s base name, I ran an incrementing loop testing if the file already exists. Then, when that test returned FALSE I knew what to append to the base name.

[code] Dim DestStr as String
Dim Dest as FolderItem

DestStr = “MyFileBaseName”
i = 0
do
Dest = WorkingFolder.Child(DestStr)
if Dest.Exists then
i = i + 1
DestStr = “MyFileBaseName” + str(i)
else
Dest.CreateAsFolder
exit
end if
Loop
[/code]
Not the best code but it works.

C’mon Dale - Can’t you find a more elegant solution?

Couldn’t resist :wink:

thanks all! it’s all together and working… loops, counter and returning the folder name!
embarrassing since things end up being far more easy than i make it… all i needed was
f=parent.Name

wow… that little thing hung me up for a while…

cheers!