1.

Solve : rename directory with wildcards?

Answer»

hi,
i've got directory with names like hello world_1, hello world_2, hello world_3, hello world_(n+1)

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?
Quote from: nuttynibbles on July 01, 2010, 08:33:32 AM


I've got directory with names like hello world_1, hello world_2, hello world_3, hello world_(n+1)

How do delete these directories?


C:\>rd /?
Removes (deletes) a directory.

RMDIR [/S] [/Q] [drive:]path
RD [/S] [/Q] [drive:]path

    /S      Removes all directories and files in the specified directory
            in addition to the directory itself.  Used to remove a directory
            tree.

    /Q      Quiet mode, do not ask if ok to remove a directory tree with /S

C:\>dir  /AD  /s  Hello*

C:\>rd /S Hello*hey Salmon Trout,

im sorry, my bad.

i actually wanted to delete those files. but i assume deleting/rename or moving would be using similar approach.

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
hi marvinengland,

i tried rd /S hello* but it returns "The filename, directory name, or volume label syntax is incorrect."

remembering that the directory name has a space in between (hello world_1, hello world_2...)

i did a search that it says ms dos do not accept wildcard. Quote from: nuttynibbles on July 01, 2010, 07:13:53 PM
hi marvinengland,

i tried rd /S hello* but it returns "The filename, directory name, or volume label syntax is incorrect."

remembering that the directory name has a space in between (hello world_1, hello world_2...)

Use the dir command  and find the files  and then rd.  cd  to root  ( cd \ )

C:\test>cd \

C:\>

C:\>dir /AD /s  Ho*
 Volume in drive C has no label.
 Volume Serial Number is 0652-E41D

 Directory of C:\06-07-2010\JoanPic

01/02/2009  05:15 PM              HOLLEN Trip 2005
01/02/2009  05:15 PM              Hollen Trip 6 Mos
               0 File(s)              0 bytes


C:\>rd /s  "hello world"
hello world, Are you sure (Y/N)? y
The system cannot find the file specified.im sorry marvinengland but i dun quite UNDERSTAND your latest reply  Hi all,

i managed to delete the directories using a bat file with the following script:
Code: [Select]echo off
setlocal enableextensions enabledelayedexpansion
set /a "x = 1"
:while1
    if %x% leq 331253 (
    echo %x%
        rmdir "E:\hello world_%x%"
        set /a "x = x + 1"
        goto :while1
    )
endlocal Quote from: nuttynibbles on July 02, 2010, 04:08:32 AM
Hi all,

i managed to delete the directories using a bat file with the following script:
Code: [Select]echo off
setlocal enableextensions enabledelayedexpansion
set /a "x = 1"
:while1
    if %x% leq 331253 (
    echo %x%
        rmdir "E:\hello world_%x%"
        set /a "x = x + 1"
        goto :while1
    )
endlocal

excellent code.  Looks like code written by Sidewinder.
If you wrote the code, you did not need help.


Quote from: nuttynibbles on July 02, 2010, 04:08:32 AM
C:\test>dir /AD  /b  hello*
hello world1
hello world2
hello world3
hello world4

C:\test>type  nib.bat
echo off
set /a x=1
:while1
rem echo  "hello world%x%"
dir   "hello world%x%" | findstr  "hello"
rem rd  "hello world%x%"
set /a x=%x% + 1
if %x% LEQ 4 goto :while1

Output:

C:\test>nib.bat
 Directory of C:\test\hello world1
 Directory of C:\test\hello world2
 Directory of C:\test\hello world3
 Directory of C:\test\hello world4

C:\test>type  nib.bat
echo off
set /a x=1
:while1
rem echo  "hello world%x%"
rem dir   "hello world%x%" | findstr  "hello"
rd  "hello world%x%"
set /a x=%x% + 1
if %x% LEQ 4 goto :while1

Output:

C:\test> nib.bat
C:\test>dir hello*
 Volume in drive C has no label.
 Volume Serial Number is 0652-E41D

 Directory of C:\test

Directory  Not Found

C:\test>that seems to work but it takes almost ten minutes
this stops it after numeric folders no longer exist

echo off
setlocal enableextensions enabledelayedexpansion
set /a "x = 1"
:while1
    if %x% leq 331253 (
          echo %x%
        if not exist "E:\hello world_%x%\nul" goto exit
        rmdir "E:\hello world_%x%"
        set /a "x = x + 1"
        goto :while1
    )
:exit
endlocalOne LINE of code.

Code: [Select]for /f "delims=" %%D in ('dir /b /ad "hello world_*"') do rd /s /q "%%D"


Discussion

No Comment Found