16 Replies Latest reply on Jul 27, 2010 10:12 AM by whitestar7

    delete unwanted files using BuddyAPI

    whitestar7

      Hi all,

       

      me again :-)

       

      I am trying to write some code which searchs through the main projector folder and all sub directories to find files which begin with "._"

       

      I have written the following code but not having much luck

       

      pictureFolder = _movie.path & "_images"

      picturePath = "\ext_images\" & pictureFolder & "\" & "gallery"

      picturePics = baFileList(picturePath, "*.jpg"

       

      OK = baDeleteXFiles (_movei.path & picturePics, "._*.jpg")

       

      this is not finding or deleting any of the files, I think I have gone wrong in how I am telling it to look for the files and where to look, but am not sure. Please help.

       

      WS7

       

      ps: working on D11.5 on WXP

        • 1. Re: delete unwanted files using BuddyAPI
          Mike Blaustein Level 4

          That code will not work for many reasons.  Try putting a few "put" statements in the code to see what the pathnames look like.

           

          pictureFolder = _movie.path & "_images"

          put pictureFolder

          -- "c:\path\to\file\_images"


          picturePath = "\ext_images\" & pictureFolder & "\" & "gallery"

          put picturePath

          -- "\ext_images\c:\path\to\file\_images"

          1 person found this helpful
          • 2. Re: delete unwanted files using BuddyAPI
            whitestar7 Level 1

            do you think the main issue would be the paths? as when I have hard coded the path name it has delted the files

            • 3. Re: delete unwanted files using BuddyAPI
              Mike Blaustein Level 4

              That is exactly what I'm saying.  Your picturePath is nonsensical.  Look at it.  There is not such location,

              and the formatting isn't even correct.  It is not deleting aything because you are telling it to delete fil

              es from a place that does not exist.


              • 4. Re: delete unwanted files using BuddyAPI
                whitestar7 Level 1

                ouch, sorry dude, am trying my best :-)

                • 5. Re: delete unwanted files using BuddyAPI
                  Sean_Wilson Adobe Community Professional

                  I agree with Mike that you need to start by fixing your path. It;'s hard to tell from what you posted where you are trying to

                  locate files, but it might be something like:

                  pictureFolder = _movie.path & "ext_images\_images\gallery\"


                  The next thing is that the baFileList command collects files based on their extension, not the first couple of characters of their filename. You will need to grab every file (using a wildcard match) and then check them all individually, deleting those that are unwanted:

                  lFiles = baFileList(pictureFolder, "*.*")
                  repeat with aFile in lFiles
                    if ( aFile starts "._" ) then
                      OK = baDeleteFile(pictureFolder & aFile)
                      if ( OK = 0 ) then
                        alert "Error deleting file:" &RETURN& pictureFolder & aFile
                      end if
                    end if
                  end repeat
                  
                  1 person found this helpful
                  • 6. Re: delete unwanted files using BuddyAPI
                    whitestar7 Level 1

                    thanks for this Sean,

                     

                    I was using a line of code which defines different paths elsewhere in the project, obviously I got it pretty wrong. Just wanted to try and do it myself rather than take the easy route :-)

                     

                    Thanks again for all your help, will try this out.

                    • 7. Re: delete unwanted files using BuddyAPI
                      whitestar7 Level 1

                      Hi Sean,

                       

                       

                      will this search within sub-directories or just the defined directory

                      • 8. Re: delete unwanted files using BuddyAPI
                        Sean_Wilson Adobe Community Professional

                        It will only search in the folder defined by 'pictureFolder'. If you want it to search through subfolders you need to make it recursive, perhaps like so:

                        on mDeleteFiles aFolder
                          -- make sure folder ends with folder delimiter character "\"
                          sDelim = the last char of the moviePath
                          if the last char of aFolder <> sDelim then aFolder = aFolder & sDelim
                          
                          -- look for folders in current folder and check them for files to delete
                          lFolders = baFolderList(aFolder)
                          repeat with tFolder in lFolders
                            mDeleteFiles(aFolder & tFolder)
                          end repeat
                          
                          -- delete any files that meet match criterion
                          lFiles = baFileList(aFolder, "*.*")
                          repeat with aFile in lFiles
                            if ( aFile starts "._" ) then
                              OK = baDeleteFile(aFolder & aFile)
                              if ( OK = 0 ) then
                                alert "Error deleting file:" &RETURN& aFolder & aFile
                              end if
                            end if
                          end repeat
                        end
                        
                        • 9. Re: delete unwanted files using BuddyAPI
                          whitestar7 Level 1

                          Hi Sean,

                           

                          thanks for the code, but should mDeleteFiles be assigned a value, or have I misunderstood..again :-)

                          • 10. Re: delete unwanted files using BuddyAPI
                            Mike Blaustein Level 4

                            The declaration of the function is:

                             

                            on mDeleteFiles aFolder

                             

                            That means that you do need to send a parameter to the function.  The parameter it wants is named aFolder.  It wants you to tell it which folder you want to delete the files from.  Specifically, the root folder that the script will recurse through when it searches for and deletes those files.  So you would do something like this:

                             

                            mDeleteFiles(pictureFolder)

                             

                            (assuming that pictureFolder is the correct place where you are deleting things from, and assuming that pictureFolder ends with a "\")

                            • 11. Re: delete unwanted files using BuddyAPI
                              whitestar7 Level 1

                              hi guys,

                               

                              sorry about this, but the files are not deleting, I am certain I have got the path right as I have tested that in the message window and debugger, not getting any script errors, but no files are being deleted either, thisis what I have in a movie script

                               

                              global pictureFolder,mDeleteFiles,tFolders,lFolders,lFiles,aFile,sDelim

                               

                              pictureFolder = _movie.path & "ext_images\"


                              on mDeleteFiles pictureFolder
                                --make sure the folder ends with folder deliminator "\"
                                sDelim = the last char of the _movie.path
                                if the last char of pictureFolder <> sDelim then pictureFolder = pictureFolder
                               
                                --look for folders in current folder and check them for file
                                lFolders = baFolderList(pictureFolder)
                                repeat with tFolder in lFolders
                                  mDeleteFiles(pictureFolder & tFolders)
                                end repeat
                               
                                --delete files which meet criteria
                                lFiles = baFileList(pictureFolder, "*.*")
                                repeat with aFile in lFiles
                                  if ( aFile starts "._" ) then
                                    OK = baDeleteFile(pictureFolder & aFile)
                                    if ( OK = 0 ) then
                                      alert "Error deleting file" &RETURN& pictureFolder & aFile
                                    end if
                                  end if
                                end repeat

                               

                              I think I got something wrong in the delete file part of the script but not sure what, thanks again

                              • 12. Re: delete unwanted files using BuddyAPI
                                Mike Blaustein Level 4

                                Try dropping in a few 'put' statements (I'm sounding like a broken record, huh?).  S

                                ome appropriate places would be in the last code block...

                                 

                                put lFiles

                                -- see if the correct files are found

                                 

                                after the deleteFile command:

                                 

                                put OK

                                -- this will give you a number... look up that number in the documentation for BuddyAPI and it till tell you what is going wrong

                                 

                                 

                                etc.

                                 

                                Also, you do not need that line where you set the value of pictureFolder.  Remove that.  You pass the value to the function when you call it, like this:

                                 

                                mDeleteFiles(_movie.path & "ext_images\")

                                • 13. Re: delete unwanted files using BuddyAPI
                                  Sean_Wilson Adobe Community Professional

                                  I see where you have declared the handler (pasted the code I provided) and added some global variables. What I don't see is anywhere you call this handler.

                                   

                                  I have no idea how your application is structured, but the code I provided might go into a #movie script (so that it's "globally" available) and you might attach a behavior to a button that calls this handler, something like:

                                  on mouseUp me
                                    mDeleteFiles(_movie.path & "ext_images\")
                                  end
                                  
                                  • 14. Re: delete unwanted files using BuddyAPI
                                    whitestar7 Level 1

                                    hi guys,

                                     

                                    not having much luck with this, I am abit confused as the script Sean wrote said to include

                                     

                                    picturefolder = _movie.path & "ext_images\"

                                     

                                    but Mike you are saying I don't need to have that line there, when I use

                                     

                                    on mDeleteFiles (_movie.path & "ext_images\")

                                     

                                    I get a script error saying "comma expected"

                                     

                                    also I have tried the put command in the message window for:

                                    aFile

                                    lFiles

                                     

                                    and they are both "void"

                                     

                                     

                                     

                                    Also I have placed this script in a moviescript and am calling the handler mDeleteFiles on the first frame of the movie

                                     

                                    Thanks again

                                    • 15. Re: delete unwanted files using BuddyAPI
                                      Mike Blaustein Level 4

                                      Step 1) Copy Seans code.

                                      Step 2) Paste it into a #movie script

                                      Step 3) DO NOT EDIT IT OR MAKE ANY CHANGES TO IT WHATSOEVER

                                      Step 4) In your code, wherever you want the files to be deleted, add this line:

                                       

                                      mDeleteFiles(_movie.path & "ext_images\")

                                       

                                      Feel free to adjust that pathname as needed so that it points to the root folder where you want the deletions to happen.

                                       

                                      Step 5) There is no step 5

                                      • 16. Re: delete unwanted files using BuddyAPI
                                        whitestar7 Level 1

                                        Step 5 is:

                                         

                                         

                                        SUCCESS!!! Thank you both very much for helping me out, really appreciate it.

                                         

                                        I am now gonna look harder to see where I went wrong with it