|
-
Jan 15th, 2005, 01:14 PM
#1
Thread Starter
Hyperactive Member
Removing files
I have code for copying files to a folder using commondialog.
would it be much different to implement a similar feature to allow users to remove files. Heres the code used for adding.
VB Code:
Private Sub Command2_Click()
Dim f1 As Integer, songpath As String, xmlpath As String, songname As String, mp3path As String, f2 As Integer, i As Integer
xmlpath = "C:\Program Files\mgamerz\"
mp3path = "C:\Program Files\mgamerz\my_mp3s\"
f2 = FreeFile
Open mp3path & "mp3.txt" For Output As #f2 ' if you don't need mp3.txt take out
f1 = FreeFile
Open xmlpath & "audiolist.xml" For Output As #f1
Print #f1, "<?xml version=""1.0""?>"
Print #f1, "<songs>"
songname = Dir(mp3path & "\*.mp3") ' get first track
i = 1
While Not Len(songname) = 0
songpath = "<song path=""" & mp3path & songname & """ title=""" & songname & """/> "
Print #f1, songpath
Print #f2, songname ' for mp3.txt
Sleep 100 ' slight pause, needed
songname = Dir ' get next track
Wend
Print #f1, "</songs>"
Close
End Sub
Thanks Rob
-
Jan 15th, 2005, 02:28 PM
#2
Re: Removing files
do you want to delete the song from the drive, or just delete the song from your list?
-
Jan 15th, 2005, 02:33 PM
#3
Thread Starter
Hyperactive Member
Re: Removing files
well I would like the user to be able to click a command button (remove files) and then the folder where they are stored will open and they can select either one track or multiple - click ok and they will be gone.
Cheers for replying
Rob
-
Jan 15th, 2005, 04:25 PM
#4
Thread Starter
Hyperactive Member
Re: Removing files
I posted the wrong code this is what I'm using to open files
VB Code:
Private Sub Command1_Click()
Dim strFile() As String, strPath As String
Dim n As Long, nCount As Long
On Error Resume Next
With CommonDialog1
.Flags = cdlOFNAllowMultiselect + cdlOFNExplorer
.CancelError = True
.InitDir = "C:\"
.DialogTitle = "Select File"
.ShowOpen
If Err.Number <> cdlCancel Then
strFile = Split(.FileName, vbNullChar)
nCount = UBound(strFile)
If nCount = 0 Then
'Only one file is selected so split up the path and the filename
ReDim strFile(1)
strFile(0) = Left$(.FileName, InStrRev(.FileName, "\"))
strFile(1) = Mid$(.FileName, InStrRev(.FileName, "\") + 1)
nCount = 1
End If
strPath = strFile(0)
If Right$(strPath, 1) <> "\" Then
strPath = strPath & "\"
End If
For n = 1 To nCount
If Len(Dir(FAVORITES_FOLDER & strFile(n))) = 0 Then
FileCopy strPath & strFile(n), FAVORITES_FOLDER & strFile(n)
End If
Next
End If
End With
End Sub
Can I adjust this to work in reverse so to speak?
-
Jan 15th, 2005, 04:57 PM
#5
Re: Removing files
where is it going to be deleted from, the list, the folder, or both?
-
Jan 15th, 2005, 04:59 PM
#6
Thread Starter
Hyperactive Member
Re: Removing files
I just want the user to be able to click a command button and then be taken to the my_mp3s folder where the mp3 files are stored. Then when they are there I want them to be able to either select a single file or select multiple files by holding shift etc and that will delete the file. I thought this might have been quite easy as I have it set up so they can add files.
-
Jan 15th, 2005, 05:01 PM
#7
Thread Starter
Hyperactive Member
Re: Removing files
As for the list this will be adjusted via a command button that I have on the form that creates/updates an xml file by what is in the my_mp3s folder.
Sorry if I didn't make myself clear before.
Rob
-
Jan 15th, 2005, 05:07 PM
#8
Re: Removing files
so the list will get rebuilt based on the files that are present. I am not sure about the common dialog. I'm sure that there is a multiselect to select more than one file, but not sure how to reference what is returned. I would load the filenames into a listbox, and then delete them that way, but there is probably a better way to use the common dialog.
If you used the listbox, you could delete the ones that you don't want, which would move them into an array to delete. if you can get that same list from the cd, then it would be easy.
-
Jan 15th, 2005, 05:16 PM
#9
Thread Starter
Hyperactive Member
Re: Removing files
I just thought that I would be able to reverse the code that adds the files if you know what I mean but I'm just a beginner lol
-
Jan 15th, 2005, 05:24 PM
#10
Re: Removing files
try changing this:
Code:
For n = 1 To nCount
If Len(Dir(FAVORITES_FOLDER & strFile(n))) = 0 Then
FileCopy strPath & strFile(n), FAVORITES_FOLDER & strFile(n)
End If
Next
to this:
Code:
For n = 1 To nCount
Kill strPath & strFile(n)
Next
You would have to get the right directory.
-
Jan 15th, 2005, 05:28 PM
#11
Thread Starter
Hyperactive Member
Re: Removing files
Hey - Brilliant that deleted the files. It allowed me to either delete a single file or delete multiple
Great thanks
-
Jan 15th, 2005, 05:30 PM
#12
Thread Starter
Hyperactive Member
Re: Removing files
just one thing when I select the file the command button is labeled open - can I change this to delete?
-
Jan 15th, 2005, 05:50 PM
#13
Re: Removing files
Sure. Just declare a flag in the general section, so that it retains its value while the program is running. Dim ActionFlag as Boolean
Then set it to one or the other. ActionFlag=True ' Can be for OPEN
Then in the click event for the button, if actionflag=true then 'do the open routine, else, do the delete routine.
You'd also want to change the caption based on the flag value, so I'd use
if ActionFlag=true then
btnAction.Caption = "Open"
else
btnAction.Caption="Delete"
endif
You may want to put that in the form activate event or form load.
You could have it automatically switch to delete when the folder is read.
-
Jan 15th, 2005, 05:58 PM
#14
Thread Starter
Hyperactive Member
Re: Removing files
Not sure what you mean would I set the action flag to true in my button code for example would I put it in this code.
VB Code:
Private Sub Command5_Click()
Dim strFile() As String, strPath As String
Dim n As Long, nCount As Long
On Error Resume Next
With CommonDialog1
.Flags = cdlOFNAllowMultiselect + cdlOFNExplorer
.CancelError = True
.InitDir = "C:\program files\mgamerz\my_mp3s"
.DialogTitle = "Select File To Delete"
.ShowOpen
If Err.Number <> cdlCancel Then
strFile = Split(.FileName, vbNullChar)
nCount = UBound(strFile)
If nCount = 0 Then
'Only one file is selected so split up the path and the filename
ReDim strFile(1)
strFile(0) = Left$(.FileName, InStrRev(.FileName, "\"))
strFile(1) = Mid$(.FileName, InStrRev(.FileName, "\") + 1)
nCount = 1
End If
strPath = strFile(0)
If Right$(strPath, 1) <> "\" Then
strPath = strPath & "\"
End If
For n = 1 To nCount
Kill strPath & strFile(n)
Next
End If
End With
End Sub
-
Jan 15th, 2005, 06:08 PM
#15
Re: Removing files
Code:
Private Sub Command5_Click()
If ActionFlag = "True" Then
call OpenFiles
Else
call DeleteFiles
endif
and make one routine Open, and the other Delete. at the bottom of the Open, you could set the ActionFlag to False, and the caption, so that the button becomes "Delete."
-
Jan 15th, 2005, 06:11 PM
#16
Thread Starter
Hyperactive Member
Re: Removing files
Still a bit lost with this?? not sure what you mena by openFiles and delete files?
-
Jan 15th, 2005, 06:25 PM
#17
Re: Removing files
I thought that you wanted to have the same button be Open and Delete.
That's why you need the flag, to tell the program which routine to use.
If all you want to do is change the button caption, use
btnName.Caption= "Delete"
-
Jan 15th, 2005, 06:30 PM
#18
Thread Starter
Hyperactive Member
Re: Removing files
sorry what I meant when the window opens to choose the files to open the caption on the button next to the file name is labeled open and when I delete a file it is also set to open. I wondered if I could change this to delete. You know the one above cancel? Hope I've explained properly
-
Jan 15th, 2005, 06:48 PM
#19
Re: Removing files
Oh, I know what you mean. You want to change the caption in the Common Dialog control? I don't think that is possible. You would have to call two different versions of the CD control. What I have done is create a CD control on a form by it self, and call it frmCommonDialog. Here is some of my code:
Code:
Dim oCDBForm As New frmCommonDialog
x = lblSetup(1).Left + lblSetup(1).Width
y = lblSetup(1).Top
oCDBForm.Move x, y
With oCDBForm.CommonDialog1
.DialogTitle = "Select BackUp File To use"
.InitDir = App.Path
.Filter = "BackUp Files (*.old)|BU*.old|All " & _
"Files (*.*)|*.*"
.Flags = _
cdlOFNFileMustExist + _
cdlOFNHideReadOnly + _
cdlOFNLongNames + _
cdlOFNExplorer
.CancelError = False ' Change To trap cancel True
.ShowOpen
txtBackUp.Text = .FileName
End With
Unload oCDBForm
Set oCDBForm = Nothing
I can then display it wherever I want, and use any action that I want to use. I use the same one for Printer dialog. it just has different parameters.
-
Jan 15th, 2005, 07:04 PM
#20
Thread Starter
Hyperactive Member
Re: Removing files
I dont understnad how I would do that it sounds a bit complicated for me that lol
-
Jan 15th, 2005, 07:06 PM
#21
Re: Removing files
Much better than using multiple forms that each have a CD control. Plus, I re-use the form in other projects.
-
Jan 15th, 2005, 07:08 PM
#22
Re: Removing files
the commondialog control has its own caption
VB Code:
Cd1.DialogTitle = "test"
Cd1.ShowOpen
regards pete
-
Jan 15th, 2005, 08:41 PM
#23
Re: Removing files
it s not easy to change the button caption in the common dialog, it may be possible to do it using sendmessage to the commondialog, but you can change the dialog caption as per my last post,
as an extra precaution you could set
VB Code:
Cd1.FileName = "Select files for delete"
which will change as soon as they select a file, but just gives an extra warning message
p.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|