user22782271
user22782271

Reputation: 1

The problem of variables not working in the nested for loop

your textHello your textI have a folder that contains a series of files. The file inside is added every day your textNow, I wanted to write a command that every time I run it, it will check the files in this folder your textone by one and transfer the files whose creation date has been over 2 months to another folder. your textThank you for your guidance

your textset ta=%date% your textset mah_now=%date:~4,2% your textset src=d:\sour_folder your textset dest=d:\des_folder your textfor /f "skip=5 tokens=1,2,4,5* delims= " %%a in ('dir %src% /a:-d /o:d /t:c') do ( your textif "%%~c" NEQ "bytes" ( your text@echo file name: %%~d your text@echo creation date: %%~a your textfor /f " tokens=1,2 delims=/" %%j in ("%%a") do ( your textset /a taf_mah=%mah_now% - %%~j your textif %taf_mah% GTR 2 ( your textmove %src%%%~d %dest% your text)
your text) your text) your text)

Upvotes: 0

Views: 27

Answers (2)

user22782271
user22782271

Reputation: 1

@echo off
set ta=%date%
set mah_now=%date:~4,2%
set src=d:\sour_folder
set dest=d:\des_folder
for /f "skip=5 tokens=1,2,4,5* delims= " %%a in ('dir %src%  /a:-d /o:d /t:c') do (
    if "%%~c" NEQ "bytes" (
        @echo file name:     %%~d
        @echo creation date: %%~a
            for /f " tokens=1,2 delims=/" %%j in ("%%a") do (
                set /a taf_mah=%mah_now% - %%~j
                if %taf_mah% GTR 2 (
                    move %src%\%%~d %dest%
                )       
            ) 
    ) 
)

Upvotes: 0

user22782271
user22782271

Reputation: 1

I have a folder that contains a series of files. The file inside is added every day Now, I wanted to write a command that every time I run it, it will check the files in this folder one by one and transfer the files whose creation date has been over 2 months to another folder. The commands I wrote are below, but they don't work Thank you for your guidance

Upvotes: 0

Related Questions