Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Wav files not deleting
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
HyperFlexed




PostPosted: Sat Nov 20, 2004 8:51 pm   Post subject: Wav files not deleting

I have written a program that will help me sort my .wav files.

code:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% PROGRAM NAME  : Sample Sorter
% AUTHOR        : Johnny F
% STARTED ON    : 20 Nov 04
%
% DESCRIPTION   : Sorts wav files. Delete or keep
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%( FUNCTIONS )%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Returns the number of wavs in a dir
fcn NoOfWavs : int
    var streamNo : int
    var wavCounter : int := 0
    var filesChecked : int
    var fileName : string
    streamNo := Dir.Open (".")
    loop
        fileName := Dir.Get (streamNo)
        if length (fileName) >= 4 and fileName (length (fileName) - 3 .. *) = ".wav" then
            wavCounter := wavCounter + 1
        end if
        exit when fileName = ""
    end loop
    result wavCounter
end NoOfWavs

% Returns a percent of one as per RGB value entered
fcn TrueRGB (rgb : int) : real
    result rgb * (1 / 256)
end TrueRGB

%%( PROCEDURES )%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Centers a line of text
proc CenterText (text : string, row : int)
    Text.Locate (row, (Text.maxcol div 2) - (length (text) div 2))
    put text
end CenterText

% Waits for a key to be pressed
proc PressAKey
    var anyKey : string (1)
    getch (anyKey)
end PressAKey

%%( GLOBAL VARIABLES )%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

var fileOnStage : string           % Stores path name of file being dealt with
var streamNo : int
var option : string (1)
var originalCount, filesDeleted : int := 0

%%( CODE )%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Set up environment constants
View.Set ("nobuttonbar")                                % Remove tacky buttons
View.Set ("graphics:640;480")                                        % Set Res
View.Set ("title:HF's Sample Sorter")                          % Set title bar
View.Set ("position:center;truemiddle")

% Initiate Program Colors
RGB.SetColor (200, TrueRGB (5), TrueRGB (5), TrueRGB (20))
RGB.SetColor (201, TrueRGB (163), TrueRGB (163), TrueRGB (170))
colorback (200)
color (201)
cls

% Intro
CenterText ("HF's Sample Sorter", 2)
put ""
if NoOfWavs = 0 then
    put "There are no '.wav' files in the current directory. Make sure the EXE"
    put "is in the folder that contains all of your samples."
    put ""
    put "Press any key to exit."
    PressAKey
    quit
else
    put "There are ", NoOfWavs, " samples in the current DIR. Press any key to continue."
    PressAKey
end if

% Mark original # of wavs
originalCount := NoOfWavs

% Open Director
streamNo := Dir.Open (".")

View.Set ("nocursor,noecho")

for i : 1 .. NoOfWavs
    cls
    CenterText ("HF's Sample Sorter", 2)

    % Get next file
    fileOnStage := Dir.Get (streamNo)

    loop
        if length (fileOnStage) >= 4 and fileOnStage (length (fileOnStage) - 3 .. *) = ".wav" then
            CenterText ("Current Sample : " + fileOnStage, 5)
            CenterText (intstr (i) + " out of " + intstr (originalCount), 6)

            CenterText ("Do not press a key until sample is done playing", 16)

            % Play File
            Music.PlayFile (fileOnStage)

            % Show Options
            Text.Locate (Text.maxrow - 1, 1)
            put "What would you like to do?"
            put "1 - Delete File  |  2 - Keep File  |  3 - Play Again" ..
            loop
                getch (option)
                case option of
                    label "1" :
                        File.Delete (fileOnStage)
                        filesDeleted += 1
                        exit
                    label "2" :
                        exit
                    label "3" :
                        Music.PlayFile (fileOnStage)
                    label :
                        CenterText ("INVALID INPUT!", Text.maxrow - 5)
                        delay (150)
                        CenterText ("              ", Text.maxrow - 5)
                end case
            end loop
            exit when fileOnStage (length (fileOnStage) - 3 .. *) = ".wav"
        else
            fileOnStage := Dir.Get (streamNo)
        end if
    end loop

end for

cls

CenterText ("REPORT", 2)

CenterText ("Original # of samples : " + intstr (originalCount), 5)
CenterText ("# of samples deleted : " + intstr (filesDeleted), 7)
CenterText ("% of samples remaining : " + realstr ((originalCount - filesDeleted) / (originalCount) * 100, 4) + "%", 9)


The program never crashes, but when the program is done running, the wavs are still there. I tried sticking in Error.LastMsg, and I got this.

"Unknown Error # 0"

anyone have any clue as to what may be causing this?
Sponsor
Sponsor
Sponsor
sponsor
HyperFlexed




PostPosted: Sat Nov 20, 2004 11:27 pm   Post subject: (No subject)

nvm, the program is fine. My wav files were read-only. Laughing

man do I feel dumb.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: