folderitem name change

  1. 2 weeks ago
    Edited 2 weeks ago

    Hi, This routine works the first time but after that it just renames the files that is already saved.

    Am taking the file and altering the name such as name.txt to name-bak.txt then saving it in a different folder to store them for future retrieval

    I would like to change the destination.name without renaming the previous file.

    Am using xojo 2018 v1.1 so cannot use some of the more modern options.

    Any help would be appreciated

    am using

    source = selectfolder
    destination = selectfolder

    then using

    listfiles(source)

    to populate listbox1

    for i = 0 to key-1
    source.name = listbox1.list(i)
    destination.name = source.name
    if myroutine(source,destination) then
    msgbox(" OK "
    end if
    next i

    if DESTINATION.NAME is changed then it changes the name of the last file I have processed.

    Dont change it.
    Copy original to a new file that has .bak on the end

    if you can come up with a way of me reading a list of file in a folder ...and then saves it under a different folder and name.

    Thats this:

    //loop through the files in FolderA
    try
    Folderb.child(Foldera.child(x).name + ".bak").delete  //in case it exists
    catch
    end try
    Foldera.child(x).copyfileto   Folderb.child(Foldera.child(x).name + ".bak")
    //end loop

    also altering the file contents

    You didnt mention altering the contents at first.
    So perhaps:

    //loop through the files in FolderA
    try
    Folderb.child(Foldera.child(x).name + ".bak").delete  //in case it exists
    catch
    end try
    Foldera.child(x).copyfileto   Folderb.child(Foldera.child(x).name + ".bak")
    
    //amend after the copy
    Call Alter_contents_of_the_new_file(  Folderb.child(Foldera.child(x).name + ".bak")   )
    
    //end loop
  2. Norman P

    Mar 19 Pre-Release Testers, Xojo Pro outside enjoying the fresh air

    need to see how you get source and destination

  3. Jeff T

    Mar 19 Pre-Release Testers Midlands of England, Europe

    Seems very long winded.
    if you are making an actual backup in a backup folder, do you even need to rename?

    eg You are basically duplicating the contents of Folder A into Folder B
    That would do even if not renamed

    Instead of filling a listbox, work through the files in Folder A
    and for each,

    //loop through the files in FolderA
    try
    Folderb.child(Foldera.child(x).name + ".bak").delete  //in case it exists
    catch
    end try
    Foldera.child(x).copyfileto   Folderb.child(Foldera.child(x).name + ".bak")
    //end loop
  4. Sorry seems I have not explained myself properly..

    Its not the copying thats a problem but if DESTINATION.NAME is changed then it changes the name of the last file I have processed.

    i wish to change the DESTINATION.NAME without it doing this.

    Have tried many things but seems the is no way to do this,

    So if you can come up with a way of me reading a list of file in a folder and folders within that folder as with listfiles and then
    pass the folder.nativepath to a routine that processes the file and then saves it under a different folder and name.
    amd also altering the file contents so is not just a rename and copy.

    As i said I can do it once but then it gores wrong.
    if this is not clear please ask.

    Thanks for your help and I know that there must be a way to do this
    but am not good enough as am getting old and decrepid......

    Ian

  5. Norman P

    Mar 20 Pre-Release Testers, Xojo Pro outside enjoying the fresh air

    @Norman P need to see how you get source and destination

    it sounds like what you have done, at some point, is something like

    destination = source

    and not created a NEW folderitem
    by doing this they both refer to the SAME file and changing one will appear to change the other

  6. Edited 2 weeks ago

    Hi Norman thanks for that but when I try it it comes up with these results

    Destination_store holds the original folder name selected

    destination = new folderitem(destination_store, FolderItem.PathTypeAbsolute)

    Returns c:\copyfilestest\debugcopy-files-test\destination folder\testfile.exe

    destination = new folderitem(destination_store, FolderItem.PathTypenative)

    returns the same result

    I need it to be c:\destination folder\testfile.exe

    Ian

  7. Jeff T

    Mar 20 Pre-Release Testers Answer Midlands of England, Europe
    Edited 2 weeks ago

    if DESTINATION.NAME is changed then it changes the name of the last file I have processed.

    Dont change it.
    Copy original to a new file that has .bak on the end

    if you can come up with a way of me reading a list of file in a folder ...and then saves it under a different folder and name.

    Thats this:

    //loop through the files in FolderA
    try
    Folderb.child(Foldera.child(x).name + ".bak").delete  //in case it exists
    catch
    end try
    Foldera.child(x).copyfileto   Folderb.child(Foldera.child(x).name + ".bak")
    //end loop

    also altering the file contents

    You didnt mention altering the contents at first.
    So perhaps:

    //loop through the files in FolderA
    try
    Folderb.child(Foldera.child(x).name + ".bak").delete  //in case it exists
    catch
    end try
    Foldera.child(x).copyfileto   Folderb.child(Foldera.child(x).name + ".bak")
    
    //amend after the copy
    Call Alter_contents_of_the_new_file(  Folderb.child(Foldera.child(x).name + ".bak")   )
    
    //end loop
  8. sorry but you lost me with that one.
    says x is does not exist and not sure what value it is suppose to have.

    I will give short explaination of what i want to achieve.

    user sets the source and destination folders

    i take each and send it to my routine which alters the file and saves it in the destination folder.(it alters the file)
    routine saves using original name + "bak"
    it then repeats this for all the files and files in folders in source folder but puts files in destination folder without there original folders they might have been in.

    any questions let me know.

    Thank You

  9. Tim H

    Mar 20 Pre-Release Testers Portland, OR USA

    The key point here is that each file - source and destination - has to have its own unique FolderItem object. You can't reuse folderitems.

  10. Done it using folderitem.child finally worked it out copytofileorfolder by adding my routine in instead of the copy routine.

    Thanks for your help.

    Think I had better save up and buy the latest version for windows

    Ian.

or Sign Up to reply!