First time here? Check out the FAQ!
x

Is there a way to remove a file(s) from a folder using Smalltalk?

+1 vote
99 views
Hi all,

I've built a sound using the multisample which includes this bit of code:

{'sampleFileName.wav' sampleFileNamesInSameFolder}

I'd like to keep most of the samples and remove a few. Obviously, I could just remove them from that folder altogether but that would mess up other sound designs where I want all those sounds together. Also, I know I can list the sample files individually in the parameter field but I'm looking for the most efficient way because I have dozens of samples in the folder that I want to keep and only a few I don't.

Is this possible to do with Smalltalk? If so, what's the code?

Thanks for any thoughts or suggestions!
asked Jan 17 in Capytalk & Smalltalk by will-klingenmeier (Adept) (1,100 points)

1 Answer

+2 votes
 
Best answer

One way you could try is this:

{'sampleFileName.wav' sampleFileNamesInSameFolder reject: [ :fn | fn = 'unwantedFileName']}

This would create a collection of all the fileNames in the folder minus the fileName you didn't want. This is just in the parameter field (it won't remove the file from the folder in any permanent way).

answered Jan 17 by ssc (Savant) (93,320 points)
selected Jan 20 by will-klingenmeier
Thank you, that's exactly what I'm looking for, however, I tried this code but it doesn't seem to quite be working in that way? Maybe I'm missing something? Another user up voted the answer so maybe they got it working?

I have this in the samples parameter field of the multisample:

{'Slinky 01' sampleFileNamesInSameFolder reject: [ :fn | fn = 'Slinky 02']}

Sonically, I still hear 'Slinky 02' and when I evaluate the expression it still shows in the OrderedCollection. It seems to me it would go away in the OrderedCollection if it was being rejected, right?
What does

    'Slinky 01' sampleFileNamesInSameFolder

return if you evaluate it?
'Slinky 01' sampleFileNamesInSameFolder

returns every sample in the folder which is 33 slinky samples. And the same thing happens with

{'Slinky 01' sampleFileNamesInSameFolder reject: [ :fn | fn = 'Slinky 02']}
Hi Will, I suspect Alan may have been asking what the actual strings were when you evaluate sampleFileNamesInSameFolder. For example, does it give you a full pathname? The reject: test has to be an exact match, so if the original collection gives you the full pathname, the reject: test should also give a full pathname.
Awesome! I wondered that- yes, thanks for the clarification, it does evaluate with the full pathname and once I use the full pathname in both places it works. It looks like this:

{'Macintosh HD:Users:WillKlingenmeier:Documents:Kyma 7 Folder:WJK Sound Library:WJK Samples:WJK Slinky:Slinky 01.wav' sampleFileNamesInSameFolder reject: [ :fn | fn = 'Macintosh HD:Users:WillKlingenmeier:Documents:Kyma 7 Folder:WJK Sound Library:WJK Samples:WJK Slinky:Slinky 02.wav']}

Also, I found this to be one way to reject more than one file:

{{'Macintosh HD:Users:WillKlingenmeier:Documents:Kyma 7 Folder:WJK Sound Library:WJK Samples:WJK Slinky:Slinky 01.wav' sampleFileNamesInSameFolder reject: [ :fn | fn = {'Macintosh HD:Users:WillKlingenmeier:Documents:Kyma 7 Folder:WJK Sound Library:WJK Samples:WJK Slinky:Slinky 02.wav'}]} reject: [ :fn | fn = {'Macintosh HD:Users:WillKlingenmeier:Documents:Kyma 7 Folder:WJK Sound Library:WJK Samples:WJK Slinky:Slinky 03.wav'}]}
...