Windows 7 desktop.ini shared folder removal script bug

1.2k views Asked by At

Bit of a batch file question. I imagine lots of people are having fun with shared folders appearing as "My Documents" in windows explorer.

I look after several schools, where we have the pupil home folders set in a folder called say C:\data\pupils\yeargroup...

The teachers then have access to the pupils folder on a share & can review the pupils work. With the onset of Windows 7, whereas before Yeargroup folders have had a list of the pupils names with their mydocs inside, you now see a whole load of folders reporting to be "My Documents" due to the desktop.ini located inside of them.

So, I wrote this little batch file & have been running it in c:\data on a 15 minute automated task which has done a nice job or restoring law & order:

FOR /f "delims=" %%i IN ('dir /s /b /a-d "desktop.ini"') DO attrib -s -h %%i >nul 2>nul
FOR /f "delims=" %%i IN ('dir /s /b /a-d "desktop.ini"') DO del %%i >nul 2>nul

The has worked fine up until deployment at a new site that I've just got involved with. Whereas I set up all folders without spaces:

C:\data\pupils\yeargroupx\joebloggs

the folder names at this site are something like this:

C:\data\pupils\yeargroup x\joe bloggs

I have tested running the commands manually & seem to have to run the following (from within the folder location):

  1. dir /ash
  2. attrib -s -h
  3. del desktop.ini

As there are 100s of users, I obviously want to automate this. Any ideas as to how I would tweak my script? I want to do dir /ash for every folder before I change the attribute of the ini file, otherwise cmd cannot see it.

I got that script running through fudging about rather than any in depth knowledge, so some assistance would be greatly appreciated?

1

There are 1 answers

4
foxidrive On BEST ANSWER

Use "%%i" in the command tails and then spaces and & will not be a problem.