saving files without getSaveFolderitem 
Author Message
 saving files without getSaveFolderitem

I'm trying to open (one at a time) a folder full of binary files and
then save them as that file + "a" at the end of the file name or
something like that.

I can do it but only if I use

FromFile = f.openAsBinaryFile(False)
f= getSaveFolderItem("","")
ToFile = f.createBinaryFile("audio/x-wav")
// Copy stuff here

But then it prompts me for a name every time.
how do I get it to just use the name of FromFile and add a character?

Stuff like this really makes me feel silly, 'cause I'm sure it's simple.

Thanks



Thu, 27 Oct 2005 07:11:14 GMT  
 saving files without getSaveFolderitem
Once you have your file FolderItem (in let's say f), do the following:

// Creates a new folderitem with new name
f2 = f.Parent.Child(f.name + "a")
if f2.exists then
  // if there is already a file with that name, do something different...
else
  // OK we can duplicate the file
  f.CopyFileTo f2

  // Finished!
  // You have f pointing to the original file
  // You have f2 pointing to a copy of the original file,
  // with its name being original one + "a"
end if

Well, I'm not sure it's exactly what you planned to do, but you may find
all the pieces there to do what you want!

If you want to rename the file, just do f.name = f.name+"a".

Daniel.


Quote:

> I'm trying to open (one at a time) a folder full of binary files and
> then save them as that file + "a" at the end of the file name or
> something like that.

> I can do it but only if I use

> FromFile = f.openAsBinaryFile(False)
> f= getSaveFolderItem("","")
> ToFile = f.createBinaryFile("audio/x-wav")
> // Copy stuff here

> But then it prompts me for a name every time.
> how do I get it to just use the name of FromFile and add a character?

> Stuff like this really makes me feel silly, 'cause I'm sure it's simple.

> Thanks



Thu, 27 Oct 2005 17:07:59 GMT  
 saving files without getSaveFolderitem

Quote:

> Once you have your file FolderItem (in let's say f), do the following:

> // Creates a new folderitem with new name
> f2 = f.Parent.Child(f.name + "a")
> if f2.exists then
>   // if there is already a file with that name, do something different...
> else
>   // OK we can duplicate the file
>   f.CopyFileTo f2

>   // Finished!
>   // You have f pointing to the original file
>   // You have f2 pointing to a copy of the original file,
>   // with its name being original one + "a"
> end if

> Well, I'm not sure it's exactly what you planned to do, but you may find
> all the pieces there to do what you want!

> If you want to rename the file, just do f.name = f.name+"a".

Hey Daniel thanks but, Copy File to won't work for me. I need to add
data to the files I'm copying so I have to use Binary Stream write &
read.

It looks like something like this will work,
      f = ff.Parent.Child(f.name + "a")
      ToFile = f.createBinaryFile("audio/x-wav")

But now I have to figure out how to keep my for loop from going thru
and duplicatin the duplicate I just made.

Thanks



Thu, 27 Oct 2005 23:36:16 GMT  
 saving files without getSaveFolderitem
Well, an easy way to do such thing could be do build first an array with
the folderitems, and then use that array:

Dim folderItemArray(-1) as FolderItem
Dim f as FolderItem
Dim i,nb as Integer

// You'll have to check if the loop is 0-based or 1-based...
// But I think it's 1-based
nb = theFolder.Count
for i=1 to nb
  // Aliaess are resolved, be careful if you do f.Parent.child(x) later,
  // you may create your new file at a wrong place!
  // If you don't want to resolve aliases, use TrueItem(i), and check to
  // see if it's a alias later
  f = theFolder.Item(i)

  // maybe some checks can be put there to know if the file is eligible,
  // like checking that it's a right file for your job
  if not f.Directory then
    folderItemArray.Append f
  end if
next

// OK, we have the list of FolderItems - let's parse it!
// for each can be replaced by a loop on the array if you are not 5.0
for each f in folderItemArray
  // f points to one file, you can handle it!
  // <your code there>
next

Bye,
Daniel.

-------------------------------------------------------------------------


Quote:



> > Once you have your file FolderItem (in let's say f), do the following:

> > // Creates a new folderitem with new name
> > f2 = f.Parent.Child(f.name + "a")
> > if f2.exists then
> >   // if there is already a file with that name, do something different...
> > else
> >   // OK we can duplicate the file
> >   f.CopyFileTo f2

> >   // Finished!
> >   // You have f pointing to the original file
> >   // You have f2 pointing to a copy of the original file,
> >   // with its name being original one + "a"
> > end if

> > Well, I'm not sure it's exactly what you planned to do, but you may find
> > all the pieces there to do what you want!

> > If you want to rename the file, just do f.name = f.name+"a".

> Hey Daniel thanks but, Copy File to won't work for me. I need to add
> data to the files I'm copying so I have to use Binary Stream write &
> read.

> It looks like something like this will work,
>       f = ff.Parent.Child(f.name + "a")
>       ToFile = f.createBinaryFile("audio/x-wav")

> But now I have to figure out how to keep my for loop from going thru
> and duplicatin the duplicate I just made.

> Thanks



Fri, 28 Oct 2005 02:50:16 GMT  
 saving files without getSaveFolderitem

Quote:

> Once you have your file FolderItem (in let's say f), do the following:

> // Creates a new folderitem with new name
> f2 = f.Parent.Child(f.name + "a")
> if f2.exists then
>   // if there is already a file with that name, do something different...
> else
>   // OK we can duplicate the file
>   f.CopyFileTo f2

Ok here's how I did it.

  ff = f // a copy of this folderitem
  FromFile = f.openAsBinaryFile(False) //open the file we're reading
from
  if left(f.name,1) <> "."Then //incase it's a .DS_store file
    If f <> nil then
      If f.parent.child("new").exists = false then //it the "new folder
doesn't exist
        ff =f.parent.child("new")
        ff.createAsFolder //create it
      end if
      f= f.Parent.child("new").Child(f.name + "a") //tell f to create
new files in the
      //"new" folder
      ToFile = f.createBinaryFile("any") //make a new file

this is called recursively by another function goes through a directory.

FolderItem is by far the most confusing method to me, probably beacuse
it does so many things.

Thanks



Fri, 28 Oct 2005 10:19:28 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Saving images to file without display

2. Saving a file -> Save as type

3. exportPicture function without save dialog ?

4. Cancel a form without SAVE RECORD Box HELP

5. Problem with VIs saved without the diagram when loaded from the controls palette

6. Answer: Leaving a LogoWriter page without saving it

7. Q re logowriter - quiting page without saving it

8. Exit LabView without saving SubVI's

9. Saving Browser State without Cookies

10. Can't Close Word Instance without Save Changes Dlg Box

11. Write to 2 file from pipe without using temp file

12. Writing two equal files without creating two files in dct

 

 
Powered by phpBB® Forum Software