• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 204
  • Last Modified:

help converting bat to vbs or autoit

@echo off
rem Enter into top level folder, process it and go back to original folder
pushd x
call :processFolder
popd
goto :EOF

:processFolder
rem For each folder in this level
for /D   %%a in (*) do (
   rem Enter into it, process it and go back to original
   cd %%a
   call :processFolder
   cd ..
   rem If is the target folder, delete it
   if /I "%%a" == "downloads" (
      del  /Q "%%a"\*.* 
   )
)
exit /B

Open in new window


I need to convert this to a vbs or exe so I can run it in the background with scheduled task. AS of current, I can make it run but it shows the command window (black screen) and disrupts the users workflow.  I can not figure out how to hide it as there isn't an option.

Thanks!
0
bbimis
Asked:
bbimis
  • 5
  • 4
1 Solution
 
Steve KnightIT ConsultancyCommented:
Quick look but are you just trying to delete the contents of any folders called download?
0
 
bbimisAuthor Commented:
trying to delete the contents of the download folder but since there are several profiles on the computer the download directory is not always in the same spot could be like like
manager\downloads
manager.mydomain\downloads and so on

but yes any folder within the root path that is named downloads i want wiped.
0
 
bbimisAuthor Commented:
what my ultimate goal is to program a script/task that will purge the files that Outlook Web app downloads. This will prevent other users from viewing download history and seeing files other privilege users have opened.  I know this can be done with firefox settings  but i would prefer a script to do it so it doesn't get turned off/on..
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Steve KnightIT ConsultancyCommented:
How long does your current script take to run, and when does it run?  You could simplify it as follows, might only take a fraction of a second then?

@echo off
for /f "tokens=*" %%a in ('dir /b /s /ad "%userprofile%\..\downloads"') do ECHO del /Q "%%~a\*.*"

Remove the word ECHO once you are happy it is doing what you want.

Can write something similar in VBScript but if you scheduled the task right then it shouldn't appear anyway?  I just created a batch script and it ran ok by the log file it produced, showed cmd.exe in task list and no window, this is on Windows 7.

Create the task
"Run whether user is logged on or not"
"Run with the highest priveleges" - if appropriate as accessing other profiles etc.
Triggers = as needed
Actions = run your .cmd file
Would suggest adjusting the settings for "stop the task if it runs for longer than" since by default = 3 days - you can type in 5 mins for instance even though not in the drop down list.

Steve
0
 
bbimisAuthor Commented:
That will work thanks. I was originally taking and pushing it into memory and then running it trying to speed it up. but your method is way faster.  Thanks for the help.  AS for the task, they are in some cases still running xp. Anyway thanks again!
0
 
bbimisAuthor Commented:
one thing I notice in the script at times though
the directory name "whatever path it may be" is too long
0
 
Steve KnightIT ConsultancyCommented:
OK.  You could try converting to short names (old 8.3 format) to see if that will get around the length issue - does it do it if you leave ECHO In so in the dir/for part, or when it does the delete, which below will be shorter path.

for /f "tokens=*" %%A in ('dir /b /s /ad "%userprofile%\..\downloads"') do ECHO del /Q "%%~sA\*.*"

Steve
0
 
bbimisAuthor Commented:
The method you posted in terms of short names worked. it was at the delete that i was having the issue.
Thanks!
0
 
Steve KnightIT ConsultancyCommented:
glad to hear.
Steve
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now