Solved

help converting bat to vbs or autoit

Posted on 2015-02-10
9
185 Views
Last Modified: 2015-02-12
@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
Comment
Question by:bbimis
  • 5
  • 4
9 Comments
 
LVL 43

Expert Comment

by:Steve Knight
ID: 40601811
Quick look but are you just trying to delete the contents of any folders called download?
0
 

Author Comment

by:bbimis
ID: 40601821
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
 

Author Comment

by:bbimis
ID: 40601830
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 43

Accepted Solution

by:
Steve Knight earned 500 total points
ID: 40602031
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
 

Author Comment

by:bbimis
ID: 40603188
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
 

Author Comment

by:bbimis
ID: 40603472
one thing I notice in the script at times though
the directory name "whatever path it may be" is too long
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 40604557
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
 

Author Comment

by:bbimis
ID: 40605562
The method you posted in terms of short names worked. it was at the delete that i was having the issue.
Thanks!
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 40605582
glad to hear.
Steve
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

805 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question