

InterviewSolution
Saved Bookmarks
1. |
Solve : Problem with the folder name in a for command? |
Answer» <html><body><p>Hi,<br/><br/>If you can see in the lines below I am trying to rename all the txt files to the foldername.<br/><br/>exampel: this is now:<br/>c:/test/a123/test.txt<br/>c:/test/b123/test.txt<br/>c:/test/a b (2009)/test.txt<br/><br/>and it should be:<br/>c:/test/a123/a123.txt<br/>c:/test/b123/b123.txt<br/>c:/test/a b (2009)/a b (2009).txt<br/><br/>hours of searching and this is the closest thing I've got, only I can't figur out what I've to type with the<br/>FOLDERNAME.txt below:<br/><br/>-----------------<br/><br/>echo off<br/><br/>for /f "delims==" %%b in ('dir /b /s /on *.txt') do rename "%%~b" "FOLDERNAME.txt" & echo %%~b <br/><br/>pause<br/><br/>-----------------<br/><br/>I hope <a href="https://interviewquestions.tuteehub.com/tag/someone-25657" style="font-weight:bold;" target="_blank" title="Click to know more about SOMEONE">SOMEONE</a> can help me because I am trying to fix this from yesterday.<br/><br/>Kris Code: <a>[Select]</a>echo off<br/>set thisdir="%cd%"<br/>for /f "delims==" %%A in ('dir /b /s /ad') do if exist "%%A\*.txt" cd %%A & for %%B in (*.txt) do ren "%%~dpnxB" "%%~nA.txt"<br/>cd %thisdir%<br/>Hi,<br/><br/>Thank you this is what I was <a href="https://interviewquestions.tuteehub.com/tag/looking-1079184" style="font-weight:bold;" target="_blank" title="Click to know more about LOOKING">LOOKING</a> for!<br/><br/>It works <a href="https://interviewquestions.tuteehub.com/tag/quote-1175222" style="font-weight:bold;" target="_blank" title="Click to know more about QUOTE">QUOTE</a> from: squab on <a href="https://interviewquestions.tuteehub.com/tag/february-460109" style="font-weight:bold;" target="_blank" title="Click to know more about FEBRUARY">FEBRUARY</a> 20, <a href="https://interviewquestions.tuteehub.com/tag/2010-290294" style="font-weight:bold;" target="_blank" title="Click to know more about 2010">2010</a>, 07:10:53 AM</p><blockquote>It works <br/></blockquote> <br/>I know it works...<br/><br/>Glad to help.<br/><br/><br/><br/></body></html> | |