1.

Solve : rename directory with wildcards?

Answer» <html><body><p>hi,<br/>i've got directory with names like hello world_1, hello world_2, hello world_3, hello world_(n+1)<br/><br/>how do i move and delete these directories?Your title says "rename", and the body of your post says "move" and "delete". Which one of these three things do you want to do?<br/> Quote from: nuttynibbles on July 01, 2010, 08:33:32 AM</p><blockquote><br/>I've got directory with names like hello world_1, hello world_2, hello world_3, hello world_(n+1)<br/><br/>How do delete these directories?<br/></blockquote> <br/><br/>C:\&amp;<a href="https://interviewquestions.tuteehub.com/tag/gt-249387" style="font-weight:bold;" target="_blank" title="Click to know more about GT">GT</a>;rd /?<br/>Removes (deletes) a directory.<br/><br/><a href="https://interviewquestions.tuteehub.com/tag/rmdir-2996271" style="font-weight:bold;" target="_blank" title="Click to know more about RMDIR">RMDIR</a> [/S] [/Q] [drive:]path<br/>RD [/S] [/Q] [drive:]path<br/><br/>    /S      Removes all directories and files in the specified directory<br/>            in addition to the directory itself.  Used to remove a directory<br/>            tree.<br/><br/>    /Q      Quiet mode, do not ask if ok to remove a directory tree with /S<br/><br/>C:\&gt;dir  /AD  /s  Hello*<br/><br/>C:\&gt;rd /S Hello*hey Salmon Trout,<br/><br/>im sorry, my bad.<br/><br/>i actually wanted to delete those files. but i assume deleting/rename or moving would be using similar approach.<br/><br/>one reason is because i wanted to rename the directory (hello world_1 to hello_world_1) before deleting. i thought it would be easier if i can delete a directory where the name has no spaces<br/>hi marvinengland,<br/><br/>i tried rd /S hello* but it returns "The filename, directory name, or volume label syntax is incorrect."<br/><br/>remembering that the directory name has a space in between (hello world_1, hello world_2...)<br/><br/>i did a search that it says ms dos do not accept wildcard. Quote from: nuttynibbles on July 01, 2010, 07:13:53 PM<blockquote>hi marvinengland,<br/><br/>i tried rd /S hello* but it returns "The filename, directory name, or volume label syntax is incorrect."<br/><br/>remembering that the directory name has a space in between (hello world_1, hello world_2...)<br/></blockquote> <br/>Use the dir command  and find the files  and then rd.  cd  to root  ( cd \ )<br/><br/>C:\test&gt;cd \<br/><br/>C:\&gt;<br/><br/>C:\&gt;dir /AD /s  Ho*<br/> Volume in drive C has no label.<br/> Volume Serial Number is 0652-E41D<br/><br/> Directory of C:\06-07-2010\JoanPic<br/><br/>01/02/2009  05:15 PM              <a href="https://interviewquestions.tuteehub.com/tag/hollen-7640865" style="font-weight:bold;" target="_blank" title="Click to know more about HOLLEN">HOLLEN</a> Trip 2005<br/>01/02/2009  05:15 PM              Hollen Trip 6 Mos<br/>               0 File(s)              0 bytes<br/><br/><br/>C:\&gt;rd /s  "hello world"<br/>hello world, Are you sure (Y/N)? y<br/>The system cannot find the file specified.im sorry marvinengland but i dun quite <a href="https://interviewquestions.tuteehub.com/tag/understand-720010" style="font-weight:bold;" target="_blank" title="Click to know more about UNDERSTAND">UNDERSTAND</a> your latest reply  Hi all,<br/><br/>i managed to delete the directories using a bat file with the following script:<br/> Code: <a>[Select]</a>echo off<br/>setlocal enableextensions enabledelayedexpansion<br/>set /a "x = 1"<br/>:while1<br/>    if %x% leq 331253 (<br/>    echo %x%<br/>        rmdir "E:\hello world_%x%"<br/>        set /a "x = x + 1"<br/>        goto :while1<br/>    )<br/>endlocal Quote from: nuttynibbles on July 02, 2010, 04:08:32 AM<blockquote>Hi all,<br/><br/>i managed to delete the directories using a bat file with the following script:<br/> Code: <a>[Select]</a>echo off<br/>setlocal enableextensions enabledelayedexpansion<br/>set /a "x = 1"<br/>:while1<br/>    if %x% leq 331253 (<br/>    echo %x%<br/>        rmdir "E:\hello world_%x%"<br/>        set /a "x = x + 1"<br/>        goto :while1<br/>    )<br/>endlocal</blockquote> <br/>excellent code.  Looks like code written by Sidewinder.<br/>If you wrote the code, you did not need help.<br/><br/><br/> Quote from: nuttynibbles on July 02, 2010, 04:08:32 AM<blockquote></blockquote> C:\test&gt;dir /AD  /b  hello*<br/>hello world1<br/>hello world2<br/>hello world3<br/>hello world4<br/><br/>C:\test&gt;type  nib.bat<br/>echo off<br/>set /a x=1<br/>:while1<br/>rem echo  "hello world%x%"<br/>dir   "hello world%x%" | findstr  "hello"<br/>rem rd  "hello world%x%"<br/>set /a x=%x% + 1<br/>if %x% LEQ 4 goto :while1<br/><br/>Output:<br/><br/>C:\test&gt;nib.bat<br/> Directory of C:\test\hello world1<br/> Directory of C:\test\hello world2<br/> Directory of C:\test\hello world3<br/> Directory of C:\test\hello world4<br/><br/>C:\test&gt;type  nib.bat<br/>echo off<br/>set /a x=1<br/>:while1<br/>rem echo  "hello world%x%"<br/>rem dir   "hello world%x%" | findstr  "hello"<br/>rd  "hello world%x%"<br/>set /a x=%x% + 1<br/>if %x% LEQ 4 goto :while1<br/><br/>Output:<br/><br/>C:\test&gt; nib.bat<br/>C:\test&gt;dir hello*<br/> Volume in drive C has no label.<br/> Volume Serial Number is 0652-E41D<br/><br/> Directory of C:\test<br/><br/>Directory  Not Found<br/><br/>C:\test&gt;that seems to work but it takes almost ten minutes<br/>this stops it after numeric folders no longer exist<br/><br/>echo off<br/>setlocal enableextensions enabledelayedexpansion<br/>set /a "x = 1"<br/>:while1<br/>    if %x% leq 331253 (<br/>          echo %x%<br/>        if not exist "E:\hello world_%x%\nul" goto exit<br/>        rmdir "E:\hello world_%x%"<br/>        set /a "x = x + 1"<br/>        goto :while1<br/>    )<br/>:exit<br/>endlocalOne <a href="https://interviewquestions.tuteehub.com/tag/line-239358" style="font-weight:bold;" target="_blank" title="Click to know more about LINE">LINE</a> of code.<br/><br/> Code: <a>[Select]</a>for /f "delims=" %%D in ('dir /b /ad "hello world_*"') do rd /s /q "%%D"</body></html>


Discussion

No Comment Found