Creating folders from a file list

I want to read a list of names and create a file for each name without dialogs.

I’ve tried the following code to test the concept. It runs without any errors, but does not create the ‘TestPic’ file. (In my real program I would use the names read in from the list in place of TestPic).

Dim oFolder as FolderItem
Dim f1Path as string

f1Path = Folder1.parent.absolutePath

Dim eSuggestedFileName AS String = f1Path+“TestPic”
oFolder = GetFolderItem(eSuggestedFileName, FolderItem.PathTypeAbsolute)

if oFolder = nil then
MsgBox “oFolder not found”
end if

Thanks in advance for any suggestions.

What are you trying to do? The testPic file can’t be created here because you only have a reference to the file. You then need to do a binarystream to actually create the file.

Please don’t use absolutepath. You also don’t have to write such convoluted code with GetFolderItem.

oFolder = Folder1.child("TestPic") dim theBin as BinaryStream = BinaryStream.create(oFolder) theBin.write("some text")

Code is from memory and doesn’t have error handling.

And if you want to create subfolders then you can do

oFolder = Folder1.child("TestPic") if not oFolder.exists then oFolder.CreateFolder

My goal is to read in a file containing each line of which has the name of the output folder and a picture file to be moved into the newly created folder. At this point I’m just testing the ability to create the folders. Once I con do that I’ll write the part which finds and moves the pictures.


At first I thought your code worked, but it creates a file, not a folder.


Dave, are you successfully creating the folder? If not, you need to do that first. Use CreateAsFolder to do that. Something like the untested code below.

oFolder = GetFolderItem (f1Path, FolderItem.PathTypeNative) If Not f.Exists Then oFolder.CreateAsFolder End If

At this point you can move the other file(s) into the folder. If you need to create a new file in the folder, you can do it with something like…

oFolder = oFolder.Child("TestPic")  ' Note this does not create the file, just the folderitem that will point to it

You would then create a file of whatever type you need it to be.