Need help with File.GetSize

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • RizlaUK
    Indigo Rose Customer
    • May 2006
    • 5478

    Need help with File.GetSize

    Hi Guys, i need a little help with some code to get the file size from a list of files

    i have a txt file wich contains the path to to the files on each on a new line, im useing this code

    PHP Code:
    sel ListBox.GetSelected("lbSavedPlaylist");
    if 
    sel then
    sPlayListFilePath 
    ListBox.GetItemData("lbSavedPlaylist"tSelected[1]);
    tSelectedPlayList TextFile.ReadToTable(sPlayListFilePath);
    nTable Table.Count(tSelectedPlayList);
        for 
    i=1,nTable do
                
    sPath tSelectedPlayList[i];
            if 
    sPath == "" then
                   Table
    .Remove(tSelectedPlayListi)
               else
                   
    tFileParts String.SplitPath(sPath);
                   
    files File.Find(tFileParts.Drive..tFileParts.Folder"*.mp3"truefalsenilnil);
                
    fSize File.GetSize(sPath);
                
    Label.SetText("laFsize"fSize);
            
    end
        end
    end 
    now, the code works but it rolls through the file sizes and ends up only displaying the size of the last file in the list, how would i go about adding all the file sizes togeather and display the final result in the label object

    iv been on this for about 3 hours and this is as far as iv got
    Embrace change in your life, you never know, it could all work out for the best
  • Roboblue
    Forum Member
    • Dec 2003
    • 892

    #2
    A Label object is not accumulative. It will only display the last variable received.
    Use a Paragraph or even an Input with multiline enabled

    Comment

    • RizlaUK
      Indigo Rose Customer
      • May 2006
      • 5478

      #3
      i tryed both and its still doing the same thing

      Paragraph.SetText("Paragraph1", fSize.."\r\n");
      and it dosent make a new line either just keeps wiping over, i think im just gonner leave it for now (unless anyone has a suggestion)
      Embrace change in your life, you never know, it could all work out for the best

      Comment

      • Roboblue
        Forum Member
        • Dec 2003
        • 892

        #4
        Man, I haven't had a drink in over 3 months. I guess I need one now.
        Paragraph and Inputs are like the Label, not append able. I need to think before I reply.
        Here is what I would do
        Code:
        sel = ListBox.GetSelected("lbSavedPlaylist");
        if sel then
        sPlayListFilePath = ListBox.GetItemData("lbSavedPlaylist", tSelected[1]);
        tSelectedPlayList = TextFile.ReadToTable(sPlayListFilePath);
        nTable = Table.Count(tSelectedPlayList);
            for i=1,nTable do
                    sPath = tSelectedPlayList[i];
                if sPath == "" then
                       Table.Remove(tSelectedPlayList, i)
                   else
                       tFileParts = String.SplitPath(sPath);
                       files = File.Find(tFileParts.Drive..tFileParts.Folder, "*.mp3", true, false, nil, nil);
                    fSize = File.GetSize(sPath);
                   TextFile.WriteFromString("C:\\MyFile.txt", fSize, true);
                end
            end
        sFileSize = TextFile.ReadToString("C:\\MyFile.txt")
        Paragraph.SetText("Para1", sFileSize);
        File.Delete("C:\\MyFile.txt", false, false, false, nil);
        end
        You could substitute a muliline enabled input box for the para (I like input box's)

        I am now driving the 16 miles round trip to go get two six packs of Samuel Adam's Boston Lager.

        Comment

        • Dermot
          Indigo Rose Customer
          • Apr 2004
          • 1790

          #5
          That's because you are replacing the text on each loop. You need to append the text to a variable on each loop and then at the end set the paragraph text.

          PHP Code:
          sel ListBox.GetSelected("lbSavedPlaylist"); 
          FileSizes ""
          if sel then 
          sPlayListFilePath 
          ListBox.GetItemData("lbSavedPlaylist"tSelected[1]); 
          tSelectedPlayList TextFile.ReadToTable(sPlayListFilePath); 
          nTable Table.Count(tSelectedPlayList); 
              for 
          i=1,nTable do 
                      
          sPath tSelectedPlayList[i]; 
                  if 
          sPath == "" then 
                         Table
          .Remove(tSelectedPlayListi
                     else 
                         
          tFileParts String.SplitPath(sPath); 
                         
          files File.Find(tFileParts.Drive..tFileParts.Folder"*.mp3"truefalsenilnil); 
                      
          fSize File.GetSize(sPath); 
                      
          FileSizes FileSizes .. fSize .. "\r\n"
                  
          end 
              end 

          Paragraph
          .SetText("Paragraph1"FileSizes)
          end 
          Dermot

          I am so out of here :yes

          Comment

          • Dermot
            Indigo Rose Customer
            • Apr 2004
            • 1790

            #6
            You beat me to it. Although my method does not require writing to and reading a text file.

            If you want the paragraph to update during the loop then change it to this.

            PHP Code:
            sel ListBox.GetSelected("lbSavedPlaylist");  
            FileSizes "" 
            if sel then  
            sPlayListFilePath 
            ListBox.GetItemData("lbSavedPlaylist"tSelected[1]);  
            tSelectedPlayList TextFile.ReadToTable(sPlayListFilePath);  
            nTable Table.Count(tSelectedPlayList);  
                for 
            i=1,nTable do  
                        
            sPath tSelectedPlayList[i];  
                    if 
            sPath == "" then  
                           Table
            .Remove(tSelectedPlayListi)  
                       else  
                           
            tFileParts String.SplitPath(sPath);  
                           
            files File.Find(tFileParts.Drive..tFileParts.Folder"*.mp3"truefalsenilnil);  
                        
            fSize File.GetSize(sPath);  
                        
            FileSizes FileSizes .. fSize .. "\r\n" 
                        
            Paragraph.SetText("Paragraph1"FileSizes
                    
            end  
                end  

            end 
            Dermot

            I am so out of here :yes

            Comment

            • Roboblue
              Forum Member
              • Dec 2003
              • 892

              #7
              Dermot
              Definitely a more elegant way of doing it.
              I really need to get out of this Text File mode and step up to "real" programing.
              I've been trying. I think I am at step 6 of 12.

              Comment

              • RizlaUK
                Indigo Rose Customer
                • May 2006
                • 5478

                #8
                thats perfect Dermot, thanks :yes

                now on the the next chapter, read to a table, add togeather and get the end result......guess ill go read up on String.ToNumber, lol
                Embrace change in your life, you never know, it could all work out for the best

                Comment

                • Dermot
                  Indigo Rose Customer
                  • Apr 2004
                  • 1790

                  #9
                  Something like this.


                  PHP Code:
                  sel ListBox.GetSelected("lbSavedPlaylist");   
                  FileSizes ""  
                  TotalSize 0
                  if sel then   
                  sPlayListFilePath 
                  ListBox.GetItemData("lbSavedPlaylist"tSelected[1]);   
                  tSelectedPlayList TextFile.ReadToTable(sPlayListFilePath);   
                  nTable Table.Count(tSelectedPlayList);   
                      for 
                  i=1,nTable do   
                              
                  sPath tSelectedPlayList[i];   
                          if 
                  sPath == "" then   
                                 Table
                  .Remove(tSelectedPlayListi)   
                             else   
                                 
                  tFileParts String.SplitPath(sPath);   
                                 
                  files File.Find(tFileParts.Drive..tFileParts.Folder"*.mp3"truefalsenilnil);   
                              
                  fSize File.GetSize(sPath);   
                              
                  FileSizes FileSizes .. fSize .. "\r\n"  
                              
                  TotalSize TotalSize fSize
                              Paragraph
                  .SetText("Paragraph1"FileSizes)  
                          
                  end   
                      end   

                  FileSizes 
                  FileSizes .. "Total: "..TotalSize
                  Paragraph
                  .SetText("Paragraph1"FileSizes)  

                  end 
                  Last edited by Dermot; 01-18-2007, 02:51 PM.
                  Dermot

                  I am so out of here :yes

                  Comment

                  • RizlaUK
                    Indigo Rose Customer
                    • May 2006
                    • 5478

                    #10
                    Dermot, you are a life saver, i tought it would take loads of math to sort out


                    Thanks....Again :yes

                    i realy need to get my head round assigning custon variables, now i look at i can understand it, but just to pop out code like that is beyound me
                    Embrace change in your life, you never know, it could all work out for the best

                    Comment

                    Working...
                    X