| 1. |
Solve : delete unused folder and it subfolders? |
|
Answer» I have trouble to search for unused folders and delete it. The problem is not stated clearly.I forget to say these files are about 80 of them differend date and time. So script should find the latest one and if that file is older than 60 days than top folder and all under it should be deleted and also if there is none of that files in folder, it should delete top folder and all under it. LOGL_201902sr_200756.txt LOGL_201902sr_184156.txt LOGL_201902sr_183141.txt LOGL_201902sr_162522.txt LOGL_201902sr_150501.txt Is this for your job? Quote from: Salmon Trout on February 07, 2019, 09:51:54 AM Is this for your job?no this is private related, why?Sometimes we get "write me a script please" requests on here, and I am pretty sure some of them are for people who need it for their work, so we write the script and the OP gets paid for it. Anyhow, do you want to use the file creation date or last modified date? Quote from: Salmon Trout on February 07, 2019, 11:16:45 AM Sometimes we get "write me a script please" requests on here, and I am pretty sure some of them are for people who need it for their work, so we write the script and the OP gets paid for it. What a crap of people making money on people good will to help. I glady pay for a COFFE to anyone which helps me, but never think of selling this kind of someones else job. On my job I also never get paid for any scripts. Anyhow, do you want to use the file creation date or last modified date? You mean of these files? LOGL_201902sr_200756.txt these files are created and never modified, so it is file creation date.1. Can you run vbs scripts? 2. What should happen if logfiles subfolder is not there? Quote from: Salmon Trout on February 07, 2019, 11:38:34 AM 1. Can you run vbs scripts? if it is possible I rather run batch, because if I need I can change a bit as much my knowledge allow me. If there is no subfolder or file in it than also it should be deleted.I just want to use an external vbscript function to calculate the file age in days, because there is no native way of doing that in batch. You will see when I show you a test batch script in a short while. Please try this test script. It won't do anything to your files. It will create a file called agedays.vbs in the same folder as the batch. Put the batch in the top folder. See above, I put it in the top folder called test. For the test run there is a folder called Jerry with no logfiles.txt. Tell me if it gives results. echo off setlocal enabledelayedexpansion set maxdays=60 echo Max file age %maxdays% days set "thisfolder=%cd%" echo wscript.echo DateDiff("d",wscript.arguments(0), Now) > agedays.vbs for /f "delims=" %%A in ('dir /b /ad') do ( echo. set delfolder=NO echo check folder %%A if not exist "%%A\logfiles" echo NO LOGFILES FOLDER & set delfolder=YES cd "%%A" If exist "logfiles" ( cd "logfiles" for /f "delims=" %%B in ('dir LOG*.txt /b /a-d /od /tc') do ( set thisfile=%%B set thisdate=%%~tB for /f "delims=" %%C in ('cscript //nologo "%thisfolder%\agedays.vbs" "!thisdate!"') do set fileage=%%C ) echo newest file !thisdate! !thisfile! !fileage! days if !fileage! gtr %maxdays% set delfolder=YES ) if "!delfolder!"=="YES" echo DELETE FOLDER %%~dpnA & echo. cd /d "%thisfolder%" ) My output: Max file age 60 days check folder Jack newest file 17/01/2019 20:21 LOGL_201902sr45341M.txt 21 days check folder Jane newest file 03/02/2019 12:39 LOGL_201902sr19909M.txt 4 days check folder Jerry NO LOGFILES FOLDER DELETE FOLDER E:\test\Jerry check folder Jim newest file 03/02/2019 12:39 LOGL_201902sr23088M.txt 4 days check folder Joe newest file 13/11/2002 17:27 LOGL_201902sr35804M.txt 5930 days DELETE FOLDER E:\test\Joe check folder John newest file 03/02/2019 12:39 LOGL_201902sr16730M.txt 4 days Coffee ? ?...that's it ? ? ? |
|