Delphi and Kylix

Moderators: pritaeas
Number of threads: 7264
Number of posts: 19073

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
removing specific character from lots of filenames Posted by Tim3000 on 11 Jul 2005 at 12:14 PM
This message was edited by Tim3000 at 2005-7-11 13:56:12

This message was edited by Tim3000 at 2005-7-11 13:38:8

This message was edited by Tim3000 at 2005-7-11 12:58:26

HI ,

I was trying to create an aplication that removes an specific character from a lot of diffent files in one map. but its not so easy as I thought it should be... perhaps someone from here know how to do it.. I try this using Delphi 2005 to make this clear

FOLDER\index1.html
FOLDER\order1.html
FOLDER\mainpage1.html
FOLDER\page1.html

So lets say from these filenames it should automaticly delete the character 1 so after I have run my aplication all the files have now same file name EXEPT the character 1

FOLDER\index.html
FOLDER\order.html
FOLDER\mainpage.html
FOLDER\page.html

so it needs to do it automaticly and I can't name the NEW filenames in my code cause then my aplication would be useless ..I have an feeling that Renamefile function can't do this.. any ideas please? Thank you !






Report
Re: removing specific character from lots of files Posted by zibadian on 11 Jul 2005 at 1:04 PM
: This message was edited by Tim3000 at 2005-7-11 12:58:26

: HI ,
:
: I was trying to create an aplication that removes an specific character from a lot of diffent files in one map. but its not so easy as I thought it should be... perhaps someone from here know how to do it.. I try this using Delphi 2005 to make this clear
:
: FOLDER\index1.html
: FOLDER\order1.html
: FOLDER\mainpage1.html
: FOLDER\page1.html
:
: So lets say from these filenames it should automaticly delete the character 1
:
: so it needs to do it automaticly and I can't name the NEW filenames in my code cause then my aplication would be useless ..I have an feeling that Renamefile function can't do this.. any ideas please? Thank you !
:
:
You can use the FindFirst(), FindNext(), and FindClose() procedure to iterate through all the files in a directory. Because each for the files are basically text files, I would use a TStrings object to store the file's contents and StringReplace() to remove the characters.

Report
Re: removing specific character from lots of files Posted by Tim3000 on 11 Jul 2005 at 1:24 PM
This message was edited by Tim3000 at 2005-7-11 13:26:29

This message was edited by Tim3000 at 2005-7-11 13:24:58

: : This message was edited by Tim3000 at 2005-7-11 12:58:26

: : HI ,
: :
: : I was trying to create an aplication that removes an specific character from a lot of diffent files in one map. but its not so easy as I thought it should be... perhaps someone from here know how to do it.. I try this using Delphi 2005 to make this clear
: :
: : FOLDER\index1.html
: : FOLDER\order1.html
: : FOLDER\mainpage1.html
: : FOLDER\page1.html
: :
: : So lets say from these filenames it should automaticly delete the character 1
: :
: : so it needs to do it automaticly and I can't name the NEW filenames in my code cause then my aplication would be useless ..I have an feeling that Renamefile function can't do this.. any ideas please? Thank you !
: :
: :
: You can use the FindFirst(), FindNext(), and FindClose() procedure to iterate through all the files in a directory. Because each for the files are basically text files, I would use a TStrings object to store the file's contents and StringReplace() to remove the characters.
:
:
Thank you for replying ,

but with StringReplace function isn't that for replacing characters that are stored in the file? ,I need an function to delete an specific character of the Filenames .



Report
Re: removing specific character from lots of files Posted by jamesb800 on 12 Jul 2005 at 12:32 AM
: : You can use the FindFirst(), FindNext(), and FindClose() procedure to iterate through all the files in a directory. Because each for the files are basically text files, I would use a TStrings object to store the file's contents and StringReplace() to remove the characters.
: :
: :
: Thank you for replying ,
:
: but with StringReplace function isn't that for replacing characters that are stored in the file? ,I need an function to delete an specific character of the Filenames .

You can use this....
if FileExists('test.txt') then
RenameFile('test.txt','test1.txt');


James
Report
Re: removing specific character from lots of files Posted by zibadian on 12 Jul 2005 at 1:06 AM
: This message was edited by Tim3000 at 2005-7-11 13:26:29

: This message was edited by Tim3000 at 2005-7-11 13:24:58

: : : This message was edited by Tim3000 at 2005-7-11 12:58:26

: : : HI ,
: : :
: : : I was trying to create an aplication that removes an specific character from a lot of diffent files in one map. but its not so easy as I thought it should be... perhaps someone from here know how to do it.. I try this using Delphi 2005 to make this clear
: : :
: : : FOLDER\index1.html
: : : FOLDER\order1.html
: : : FOLDER\mainpage1.html
: : : FOLDER\page1.html
: : :
: : : So lets say from these filenames it should automaticly delete the character 1
: : :
: : : so it needs to do it automaticly and I can't name the NEW filenames in my code cause then my aplication would be useless ..I have an feeling that Renamefile function can't do this.. any ideas please? Thank you !
: : :
: : :
: : You can use the FindFirst(), FindNext(), and FindClose() procedure to iterate through all the files in a directory. Because each for the files are basically text files, I would use a TStrings object to store the file's contents and StringReplace() to remove the characters.
: :
: :
: Thank you for replying ,
:
: but with StringReplace function isn't that for replacing characters that are stored in the file? ,I need an function to delete an specific character of the Filenames .
:
:
:
:
Then you should use the FindXXXX() procedures and a TStrings object to make a list of all the files within the folder. After you have such a list, you can use RenameFile() within a for-do loop to perform the renaming. StringReplace() can be used to remove the characters. Here is a pseudocode as a starting point:
  if FindFirst() = 0 then repeat
    Add filename to stringlist
  until FindNext()
  FindClose();
  for i := 0 to stringlist.Count-1 do
    RenameFile(stringlist[i], StringReplace());

Report
Re: removing specific character from lots of files Posted by Tim3000 on 12 Jul 2005 at 6:52 AM
: : This message was edited by Tim3000 at 2005-7-11 13:26:29

: : This message was edited by Tim3000 at 2005-7-11 13:24:58

: : : : This message was edited by Tim3000 at 2005-7-11 12:58:26

: : : : HI ,
: : : :
: : : : I was trying to create an aplication that removes an specific character from a lot of diffent files in one map. but its not so easy as I thought it should be... perhaps someone from here know how to do it.. I try this using Delphi 2005 to make this clear
: : : :
: : : : FOLDER\index1.html
: : : : FOLDER\order1.html
: : : : FOLDER\mainpage1.html
: : : : FOLDER\page1.html
: : : :
: : : : So lets say from these filenames it should automaticly delete the character 1
: : : :
: : : : so it needs to do it automaticly and I can't name the NEW filenames in my code cause then my aplication would be useless ..I have an feeling that Renamefile function can't do this.. any ideas please? Thank you !
: : : :
: : : :
: : : You can use the FindFirst(), FindNext(), and FindClose() procedure to iterate through all the files in a directory. Because each for the files are basically text files, I would use a TStrings object to store the file's contents and StringReplace() to remove the characters.
: : :
: : :
: : Thank you for replying ,
: :
: : but with StringReplace function isn't that for replacing characters that are stored in the file? ,I need an function to delete an specific character of the Filenames .
: :
: :
: :
: :
: Then you should use the FindXXXX() procedures and a TStrings object to make a list of all the files within the folder. After you have such a list, you can use RenameFile() within a for-do loop to perform the renaming. StringReplace() can be used to remove the characters. Here is a pseudocode as a starting point:
:
:   if FindFirst() = 0 then repeat
:     Add filename to stringlist
:   until FindNext()
:   FindClose();
:   for i := 0 to stringlist.Count-1 do
:     RenameFile(stringlist[i], StringReplace());
: 

:


Thanks a lot this helps :) now I can do it probably



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.