|
-
Dec 24th, 2004, 06:31 PM
#1
Thread Starter
Lively Member
ChangingFileExtension
Hello :
I have appr 15000 files on my computer written with the DOS-editor but
without a file extension.
My goal is to change all file extensions to .txt . How can I do this ?
I have a code which changes file extension from .txt to .doc or
.doc to .dat but it does not work without a file extension.
Thanks
Robert
-
Dec 24th, 2004, 06:37 PM
#2
Fanatic Member
Re: ChangingFileExtension
Actually this could be very easy...
1) Put a file1 list box on form.
2) Change property Pattern to say " *. " - this will only allow files with no extension to display in list.
3) Add a timer1 and text1 to form. Set timer interval to 3000. Set text to "0"
4) Add your renaming code (something like this)
VB Code:
Private Sub Timer1()
File1.ListIndex = CLng(Text1.Text)
Name "C:\Test\" & File1.Filename As "C:\Test\" & File1.Filename & ".txt"
Text1.Text = CDbl(Text1.Text) + 1
End Sub
What is happening is that each time the timer fires (3 sec) it looks for the number in the list box and uses it as the index number for the file1 list box.
You just rename the filename with your rename code.
The reason I would do it this way is because you can do this in a "For..Next" loop (its to fast though). But I would give windows enough time to process the name change.
Try that
Last edited by epixelman; Dec 24th, 2004 at 07:16 PM.
-
Dec 24th, 2004, 06:55 PM
#3
Re: ChangingFileExtension
Move all of your files that have no extentions into one easy to access folder and use the following sample:
VB Code:
Private Sub Command1_Click()
Dim sFile$, sPath$
sPath = "c:\temp\Test\"
sFile = Dir(sPath, vbNormal)
Do While sFile <> ""
If sFile <> "." And sFile <> ".." Then
Name sPath & sFile As sPath & sFile & ".txt"
End If
sFile = Dir
Loop
End Sub
-
Dec 24th, 2004, 07:00 PM
#4
Fanatic Member
Re: ChangingFileExtension
Cool.. RhinoBull
That will work too!!
-
Dec 24th, 2004, 08:46 PM
#5
Thread Starter
Lively Member
Re: ChangingFileExtension
Thanks for your reply. Unfortunately I got all kind of error messages
when I tried it out. ( Type missmatch etc etc )
However one file changed to what I wanted but somehow the "loop"
causes problems.
What I forgot : I am a beginner in VB6.
Thanks
RobertXYZ
 Originally Posted by epixelman
Actually this could be very easy...
1) Put a file1 list box on form.
2) Change property Pattern to say " *. " - this will only allow files with no extension to display in list.
3) Add a timer1 and text1 to form. Set timer interval to 3000. Set text to "0"
4) Add your renaming code (something like this)
VB Code:
Private Sub Timer1()
File1.ListIndex = CLng(Text1.Text)
Name "C:\Test\" & File1.Filename As "C:\Test\" & File1.Filename & ".txt"
Text1.Text = CDbl(Text1.Text) + 1
End Sub
What is happening is that each time the timer fires (3 sec) it looks for the number in the list box and uses it as the index number for the file1 list box.
You just rename the filename with your rename code.
The reason I would do it this way is because you can do this in a "For..Next" loop (its to fast though). But I would give windows enough time to process the name change.
Try that
-
Dec 24th, 2004, 09:06 PM
#6
Re: ChangingFileExtension
Just follow my intructions and you'll be ok.
-
Dec 25th, 2004, 07:31 AM
#7
Fanatic Member
Re: ChangingFileExtension
What I gave you was only a basic sample.
Here is what I have that works... (be sure to put your "no extention files in the same folder as your program)
Type mismatch?? The only place that I see where you would be getting that is if you have "0" in the textbox instead of 0 (do not use quotes)
VB Code:
Private Sub Command1_Click()
'set speed and turn on timer
Timer1.Interval = 500
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
'select the file based on index number in textbox
File1.ListIndex = CLng(Text1.Text)
'rename file
Name App.Path & "\" & File1.FileName As App.Path & "\" & File1.FileName & ".txt"
'up the text box count
Text1.Text = CDbl(Text1.Text) + 1
'check and see if we have reached end of list
If Text1.Text = File1.ListCount Then
'trun timer off
Timer1.Enabled = False
'tell user we are done
MsgBox "Done", 48, "Complete"
'refresh file box to show new filenames
File1.Pattern = "*.txt"
File1.Refresh
End If
End Sub
That works for me. Checking the end of the list should solve the loop error.
Did you try RhinoBulls? His works too!
-
Dec 25th, 2004, 10:21 AM
#8
Thread Starter
Lively Member
Re: ChangingFileExtension
 Originally Posted by epixelman
What I gave you was only a basic sample.
Here is what I have that works... (be sure to put your "no extention files in the same folder as your program)
Type mismatch?? The only place that I see where you would be getting that is if you have "0" in the textbox instead of 0 (do not use quotes)
VB Code:
Private Sub Command1_Click()
'set speed and turn on timer
Timer1.Interval = 500
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
'select the file based on index number in textbox
File1.ListIndex = CLng(Text1.Text)
'rename file
Name App.Path & "\" & File1.FileName As App.Path & "\" & File1.FileName & ".txt"
'up the text box count
Text1.Text = CDbl(Text1.Text) + 1
'check and see if we have reached end of list
If Text1.Text = File1.ListCount Then
'trun timer off
Timer1.Enabled = False
'tell user we are done
MsgBox "Done", 48, "Complete"
'refresh file box to show new filenames
File1.Pattern = "*.txt"
File1.Refresh
End If
End Sub
That works for me. Checking the end of the list should solve the loop error.
Did you try RhinoBulls? His works too!
Thanks for your efforts but I must still be missing something because
when I click on Command1 I obtain an error message ( beside the line
File1.ListIndex = CLng(Text1.Text) ---> Type mismatch
To recap :
My program is in c:\Folder1 and all my files with no extensions are in
c:\Folder1 as well.
I typed the code as you proposed.
On Form-Load I entered Text1.Text = ""
What do I do wrong ?
Thanks
RobertXYZ
-
Dec 25th, 2004, 10:40 AM
#9
Re: ChangingFileExtension
Just out of curiousity: did you RobertXYZ at least try to run that sample I've posted for YOU ? I am not saying that you must use mine but if something isn't working out then you need to try anothoer approach, isn't it?
Cheers.
-
Dec 25th, 2004, 10:53 AM
#10
Thread Starter
Lively Member
Re: ChangingFileExtension
Hi RhinoBull
Yes,I tried you suggested code but must miss something as it did not work.
Still trying.Will keep you posted.
In the meantime thanks.
RobertXYZ
 Originally Posted by RhinoBull
Just out of curiousity: did you RobertXYZ at least try to run that sample I've posted for YOU ? I am not saying that you must use mine but if something isn't working out then you need to try anothoer approach, isn't it?
Cheers.
-
Dec 25th, 2004, 10:54 AM
#11
Fanatic Member
Re: ChangingFileExtension
Robert...
I set my text1 text in the properties panel using ... 0
If you are setting it using code then....
Text1.Text = "0"
The type mismatch could be because the text box is blank. It has to have a value in it.
Try that
-
Dec 25th, 2004, 10:56 AM
#12
Re: ChangingFileExtension
Which part didn't work ??????????????
All you had to do was only set proper Path to your files and that's it.
sPath = "c:\Folder1\" if that's the correct path to all of your files.
Although, no dirlistboxes, filelistboxes, etc are needed except for a single command button.
-
Dec 25th, 2004, 11:24 AM
#13
Thread Starter
Lively Member
Re: ChangingFileExtension
Attn: RhinoBull
My mistake,it works now. I typed in sPath "c:\Folder1" instead of
"c:\Folder1\"
Your help is appreciated.Thanks again
RobertXYZ
 Originally Posted by RhinoBull
Which part didn't work ??????????????
All you had to do was only set proper Path to your files and that's it.
sPath = "c:\Folder1\" if that's the correct path to all of your files.
Although, no dirlistboxes, filelistboxes, etc are needed except for a single command button.
-
Dec 25th, 2004, 11:28 AM
#14
Re: ChangingFileExtension
Not at all. Glad you did sort it out.
-
Dec 25th, 2004, 07:41 PM
#15
Thread Starter
Lively Member
Re: ChangingFileExtension
Hi :
I ran your code and it works ok.Thanks a lot for your help.What
amazes me is that the problem can be solved with different codes because
the one from Rhino works as well.
As a complete beginner in VB6 I tought any particular problem can only
have one solution...
Where do you learn these things by the way.From books ? Experience ?
I am sure I could have searched for ever and would not find the code.
Thanks
RobertXYZ
 Originally Posted by epixelman
What I gave you was only a basic sample.
Here is what I have that works... (be sure to put your "no extention files in the same folder as your program)
Type mismatch?? The only place that I see where you would be getting that is if you have "0" in the textbox instead of 0 (do not use quotes)
VB Code:
Private Sub Command1_Click()
'set speed and turn on timer
Timer1.Interval = 500
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
'select the file based on index number in textbox
File1.ListIndex = CLng(Text1.Text)
'rename file
Name App.Path & "\" & File1.FileName As App.Path & "\" & File1.FileName & ".txt"
'up the text box count
Text1.Text = CDbl(Text1.Text) + 1
'check and see if we have reached end of list
If Text1.Text = File1.ListCount Then
'trun timer off
Timer1.Enabled = False
'tell user we are done
MsgBox "Done", 48, "Complete"
'refresh file box to show new filenames
File1.Pattern = "*.txt"
File1.Refresh
End If
End Sub
That works for me. Checking the end of the list should solve the loop error.
Did you try RhinoBulls? His works too!
-
Dec 25th, 2004, 07:56 PM
#16
Re: ChangingFileExtension
LOL ...
Books ? Yes, they are very helpfull, no doubt about that. But mostly it's all about every day work, practice, every day work, practice, every day work, practice for past few dozen of years ... That's about it ...
-
Dec 25th, 2004, 09:01 PM
#17
Re: ChangingFileExtension
there are un-limited solutions to any given problem. some are easier to implement than others, while some are easier to read (and maintain) then others. any one may be used, as long as it gets the job done.
while it is good to learn proper technique, you could just as easily develop your own style of code, and do quite well.
the problem comes in when others have to maintain your code. if they are familar with the technique that you used, then they will be able to maintain it a lot easier than if they're not.
we use good techniques, and constantly pick up better techniques from the code that we see. if you want to see excellent examples, visit the code bank. these programs shine in their ability to solve any given problem.
-
Dec 26th, 2004, 08:13 AM
#18
Fanatic Member
Re: ChangingFileExtension
Many solutions is part of the game.
The reason I suggested my solution is because I like to see the "solution" work before my eyes as it is happening. The solution I posted here, I have in a much larger scale where you can customize the extensions visually.
I like RhinoBull's solution (which is quick and to the point) too because that code can be used in the background with out the user knowing it.
It all depends on how you want to present your function to the user and more importantly how clean, manageable and easy to custmize a particular solution can be handled
As they say... "all roads lead to Rome"... but some may have more curves than the other.
Happy Learning!!
-
Feb 7th, 2005, 10:47 PM
#19
this sounds like a one off thing - if this is the case u could always run this from the command prompt :
rename *. *.txt
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
|