I have multiple files in a directory, ending with the same name *.html.html, I'm looking for a way to get their names and change them to just *.html using the rename()
function in c or c++ or any other way to solve this problem
Asked
Active
Viewed 187 times
0

taras
- 6,566
- 10
- 39
- 50

Sanusi hassan
- 181
- 8
-
"*or any other way to solve this problem*" which platform are you on? – alk Jan 21 '19 at 13:56
-
4Why do you want to do that in C? Your OS is likely to have a command for doing that – Support Ukraine Jan 21 '19 at 13:56
-
1Use a shell script. It would be a lot easier. What OS are you using? – lurker Jan 21 '19 at 13:57
-
1Related: https://unix.stackexchange.com/q/102647/10947 – alk Jan 21 '19 at 13:59
-
I'm using Windows 10, I've tried to do that in cmd but it's not working the way I like – Sanusi hassan Jan 21 '19 at 14:02
-
Have you tried: `rename *.html.html *.` – Support Ukraine Jan 21 '19 at 14:14
1 Answers
-1
In command line, simply use:
ren *.html.html *.html
Or, in PowerShell:
Dir *.html.html | rename-item -newname { [io.path]::ChangeExtension($_.name, "html") }
Shell would be the simplest option and the most sensate to use. Using C would be overkilling it. Any scripting language (python, php) would be a simpler solution.
If you really really just want to do it in C, you can have a look at this SO question: How do I loop through all files in a folder using C?

brunorey
- 2,135
- 1
- 18
- 26
-
-
cmd and PowerShell are not working for me,my file name is ending with ".html" and has .html extension, I want to get rid of the additional .html to end up with just one .html – Sanusi hassan Jan 21 '19 at 19:39