removing specific character from lots of filenames - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

removing specific character from lots of filenames

Tim3000Tim3000 Posts: 21Member
[b][red]This message was edited by Tim3000 at 2005-7-11 13:56:12[/red][/b][hr]
[b][red]This message was edited by Tim3000 at 2005-7-11 13:38:8[/red][/b][hr]
[b][red]This message was edited by Tim3000 at 2005-7-11 12:58:26[/red][/b][hr]
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

FOLDERindex1.html
FOLDERorder1.html
FOLDERmainpage1.html
FOLDERpage1.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

FOLDERindex.html
FOLDERorder.html
FOLDERmainpage.html
FOLDERpage.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 !






Comments

  • zibadianzibadian Posts: 6,349Member
    : [b][red]This message was edited by Tim3000 at 2005-7-11 12:58:26[/red][/b][hr]
    : 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
    :
    : FOLDERindex1.html
    : FOLDERorder1.html
    : FOLDERmainpage1.html
    : FOLDERpage1.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.

  • Tim3000Tim3000 Posts: 21Member
    [b][red]This message was edited by Tim3000 at 2005-7-11 13:26:29[/red][/b][hr]
    [b][red]This message was edited by Tim3000 at 2005-7-11 13:24:58[/red][/b][hr]
    : : [b][red]This message was edited by Tim3000 at 2005-7-11 12:58:26[/red][/b][hr]
    : : 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
    : :
    : : FOLDERindex1.html
    : : FOLDERorder1.html
    : : FOLDERmainpage1.html
    : : FOLDERpage1.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 .



  • jamesb800jamesb800 Posts: 105Member
    : : 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....
    [code]
    if FileExists('test.txt') then
    RenameFile('test.txt','test1.txt');
    [/code]

    James
  • zibadianzibadian Posts: 6,349Member
    : [b][red]This message was edited by Tim3000 at 2005-7-11 13:26:29[/red][/b][hr]
    : [b][red]This message was edited by Tim3000 at 2005-7-11 13:24:58[/red][/b][hr]
    : : : [b][red]This message was edited by Tim3000 at 2005-7-11 12:58:26[/red][/b][hr]
    : : : 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
    : : :
    : : : FOLDERindex1.html
    : : : FOLDERorder1.html
    : : : FOLDERmainpage1.html
    : : : FOLDERpage1.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:
    [code]
    if FindFirst() = 0 then repeat
    Add filename to stringlist
    until FindNext()
    FindClose();
    for i := 0 to stringlist.Count-1 do
    RenameFile(stringlist[i], StringReplace());
    [/code]
  • Tim3000Tim3000 Posts: 21Member
    : : [b][red]This message was edited by Tim3000 at 2005-7-11 13:26:29[/red][/b][hr]
    : : [b][red]This message was edited by Tim3000 at 2005-7-11 13:24:58[/red][/b][hr]
    : : : : [b][red]This message was edited by Tim3000 at 2005-7-11 12:58:26[/red][/b][hr]
    : : : : 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
    : : : :
    : : : : FOLDERindex1.html
    : : : : FOLDERorder1.html
    : : : : FOLDERmainpage1.html
    : : : : FOLDERpage1.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:
    : [code]
    : if FindFirst() = 0 then repeat
    : Add filename to stringlist
    : until FindNext()
    : FindClose();
    : for i := 0 to stringlist.Count-1 do
    : RenameFile(stringlist[i], StringReplace());
    : [/code]
    :


    Thanks a lot this helps :) now I can do it probably
Sign In or Register to comment.