Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

for /l .....

Apr
1,825
17
The following line:

Code:
[CODE]
cdd c:\backup
for /l %n in (1,1,100) for /a:-d /r %fn in (*) if not isfile "\ZZZ_Backup\%@upper[%@ext["%fn"]]_%@format[03,%n]\%fn" move /a: /dd /e /h /md /mda "%fn" "\ZZZ_Backup\%@upper[%@ext["%fn"]]_%@format[03,%n]\
[/CODE]

1) I am still being prompted if the file exists in the destination, an thoughts?

2) I would like to remove empty dirs in C:\backup - I know it would be a command grouping but unsure how to code it

TIA !!
 
2) I would like to remove empty dirs in C:\backup - I know it would be a command grouping but unsure how to code it

Here's one way:

Code:
del /s /e /x /y /z c:\backup\nul.*

Since you can't have any files matching nul.*, this doesn't delete any files; it just removes empty directories as it goes. Danger: If there are no files at all in c:\backup or below, then c:\backup itself will be removed! If this could be a problem, you can change the current directory to c:\backup first. You cannot remove the current directory.

Code:
pushd c:\backup && ( del /s /e /x /y /z nul.* & popd )
 
@Charles Dye - thank you,. But I still don't know why I am still being prompted if there is a file in the destination?
 
Not sure, but.... That inner FOR is recursing into subdirectories. I suspect that the IF NOT ISFILE is not expanding the way you think it is. Might try inserting an ECHO before the IF NOT ISFILE, see what it looks like after variable expansion.
 
COPY and DEL have a /Y option to suppress the prompt. MOVE uses /Y for something else, for compatibility with Brand X. It would be nice if MOVE also had such an option. Perhaps /R- ?
 
Code:
COMMENT

        :: RunMe.btm

ENDCOMMENT

Global /H /I /N /Q ( for %fn in (*) Gosub Dofile & del /a:d /s /e /x /y * )

QUIT

:Dofile
    set uExt=%@upper[%@ext["%fn"]]
    for /l %n in (1,1,9999) (
        iff not isfile "c:\ZZZ_Backup\%[uExt]_%@format[04,%n]\%fn" then
            move /a: /dd /e /h /md /mda "%fn" "c:\ZZZ_Backup\%[uExt]_%@format[04,%n]\"
        leavefor
        endiff
    )
    return
 
Back
Top