nav2567
asked on
check if a folder exists script.
I have a big size P:\USERS folder in my WIN2K8 server which has a lot of subfolders.
I need to write a script to check each subfolder and report the name of the subfolder if the config folder is missing inside. Hence, there is a C:\USERS\USERX\CONFIG folder for each user.
Please advise.
Thanks.
I need to write a script to check each subfolder and report the name of the subfolder if the config folder is missing inside. Hence, there is a C:\USERS\USERX\CONFIG folder for each user.
Please advise.
Thanks.
What language do you want the script in?
Try this batch script if this works for you.
@ECHO OFF
IF EXIST "C:\NoConfigUsers.txt" DEL "C:\NoConfigUsers.txt"
FOR /F "delims=" %%F IN ('DIR /AD /B C:\Users') DO (
ECHO Checking %%F
IF NOT EXIST "C:\Users\%%F\Config" ECHO %%F>>C:\NoConfigUsers.txt)
Start "" Notepad C:\NoConfigUsers.txt
ASKER
Thanks a lot ; )
Under each user subfolder, there is a file called "devicetree.txt". We want to export the subfolder names which has this file's last modified date more than a year.
Would modify your script?
Thanks again.
Under each user subfolder, there is a file called "devicetree.txt". We want to export the subfolder names which has this file's last modified date more than a year.
Would modify your script?
Thanks again.
ASKER
Hi,
I tried to use the following right before the "if not exist" command", but it is still having error.
forfiles /m devicetree.txt /c "cmd /c echo %%F>>noconfigusers.txt" /D -365
Would you advise again?
Thanks.
I tried to use the following right before the "if not exist" command", but it is still having error.
forfiles /m devicetree.txt /c "cmd /c echo %%F>>noconfigusers.txt" /D -365
Would you advise again?
Thanks.
So you want a report that shows both conditions? (1) If the CONFIG folder is missing, and then also (2) if the devicetree.txt file is older than a year?
Also, if you go to a DOS prompt and enter the following command, what does it display?
ECHO %DATE%
~bp
Also, if you go to a DOS prompt and enter the following command, what does it display?
ECHO %DATE%
~bp
With regard to the FORFILES approach, I think your line would need to be:
forfiles /p "c:\users\%%~F" /m devicetree.txt /d -365 /c "cmd /c echo @file>>noconfigusers.txt"
so the whole thing might look like:
forfiles /p "c:\users\%%~F" /m devicetree.txt /d -365 /c "cmd /c echo @file>>noconfigusers.txt"
so the whole thing might look like:
@echo off
setlocal
set BaseDir=C:\Users
set CheckFolder=Config
set CheckFile=devicetree.txt
set ReportFile=%TEMP%\report.txt
(
for /f "delims=" %%F in ('dir /ad /b "%BaseDir%"') do (
if not exist "%BaseDir%\%%F\%CheckFolder%\" echo Missing folder: [%BaseDir%\%%~F\%CheckFolder%]
forfiles /p "%BaseDir%\%%~F" /m "%CheckFile%" /d -365 /c "cmd /c echo Missing file: [@file]"
) > "%ReportFile%"
start notepad "%ReportFile%"
~bp
ASKER
It is getting closed......
I have
for /f "delims=" %%F in ('dir /ad /b "%BaseDir%"') do (
forfiles /p "%BaseDir%\%%~F" /m "%CheckFile%" /d -365
) >> "%ReportFile%"
all I see is a list of "devicetree.txt" in the %reportfile%. Can the script displays only the user folders (%%F) that contains the devicetree.txt older than 365 days only??
I have
for /f "delims=" %%F in ('dir /ad /b "%BaseDir%"') do (
forfiles /p "%BaseDir%\%%~F" /m "%CheckFile%" /d -365
) >> "%ReportFile%"
all I see is a list of "devicetree.txt" in the %reportfile%. Can the script displays only the user folders (%%F) that contains the devicetree.txt older than 365 days only??
Give this a try, I did a bit of testing here. It only displays the full path to the user folder when an "error" is logged. We could easily make this just the user name rather than the full path if that was useful?
@echo off
setlocal
set BaseDir=C:\Users
set CheckFolder=Config
set CheckFile=devicetree.txt
set ReportFile=%TEMP%\report.txt
(
for /f "delims=" %%F in ('dir /ad /b "%BaseDir%"') do (
if not exist "%BaseDir%\%%F\%CheckFolder%\" echo Missing config folder in: [%BaseDir%\%%~F]
if exist "%BaseDir%\%%~F\%CheckFile%" (
forfiles /p "%BaseDir%\%%~F" /m "%CheckFile%" /d -365 /c "cmd /c echo Old device file in: [%BaseDir%\%%~F]" 2>NUL
) else (
echo Missing device file in: [%BaseDir%\%%~F]"
)
)
) > "%ReportFile%"
start notepad "%ReportFile%"
~bp
ASKER
Thank you.
Would you change the script to export(echo) ONLY the name of the subfolders in USERS that contains the old devicetree.txt file to the %reportfile%?
Would you change the script to export(echo) ONLY the name of the subfolders in USERS that contains the old devicetree.txt file to the %reportfile%?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I would like my %reportfile% only contains the following:
User-3
User-4
as those folders contain devicetree.txt file older than 365 days.
User-3
User-4
as those folders contain devicetree.txt file older than 365 days.
ASKER
Bill, I think I can use your output as it is detail.
I will try this out this morning and let you know.
Thanks again for all you have done and sorry for the trouble.
I will try this out this morning and let you know.
Thanks again for all you have done and sorry for the trouble.
Okay, let me know.
~bp
~bp