Jump to content

Script for deleting the directories


balubeto

Recommended Posts

HI

I would need a script that it deletes all the subdirectories (with their contents) except those mentioned by me. These subdirectories and their files may have any attribute. This script must run on Windows PE 2.1 32/64 bit and on Windows Vista SP1 32/64 bit.

THANKS

BYE

Link to comment
Share on other sites


http://www.microsoft.com/resources/documen...r.mspx?mfr=true

example: rmdir c:\temp\*.* /s /q

You'll have to play with it, as the above example deletes the files but leaves the folders. I use this in one of my scripts but never bothered fixing it.

Perhaps you have not understood well:

I want a script that works with Windows PE 2.1 32/64 bit and with Vista SP1 32/64 bit and that is a command line so I can simply write "script-name directory\list-subdirectories-from-NOT-deleting" (so that it automatically deletes the remaining subdirectories and their files with any attribute).

THANKS

BYE

Edited by balubeto
Link to comment
Share on other sites

In other words, if I have the structure:

Folder1

--- SubFolder1

--- SubFolder2

--- SubFolder3

--- SubFolder4

I would need to write, from the command line:

"delete-script / Folder1 / SubFolder1 / SubFolder2" and, therefore, the resulting structure should be:

Folder1 -

--- SubFolder1

--- SubFolder2

Now, you have realized What is my problem? So how can I do this script?

THANKS

BYE

Link to comment
Share on other sites

I understood what you meant before and I can imagine the flow of such a program. However I haven't the time to develop a program for you. Sooner or later you are going to have to learn how to write scripts yourself, you make it very far if you refuse to learn this.

My recommendation would be to start looking at AutoIT or KIXtart, which are both fairly easy scripting languages. AutoIT should be able to accomplish this, but going onto their forum and requesting them to write you a program might not work out well either.

Link to comment
Share on other sites

I understood what you meant before and I can imagine the flow of such a program. However I haven't the time to develop a program for you. Sooner or later you are going to have to learn how to write scripts yourself, you make it very far if you refuse to learn this.

My recommendation would be to start looking at AutoIT or KIXtart, which are both fairly easy scripting languages. AutoIT should be able to accomplish this, but going onto their forum and requesting them to write you a program might not work out well either.

I did a cmd script that should delete all the directories on a hard drive except the subdirectories of the Users\[Name-user-accounts] directory.

This script is:

pushd "%1"

for %%I in (C D E F G H I J K L M N O P Q R S T U V W Y Z) do if exist %%I:\Users set DVDDrive=%%I

for /D %%f in (%DVDDrive%\*) do ( if /i not "%%f" == "%DVDDrive%\Users\*" rd /s /q "%%f" )

popd

This script, run in Windows PE 2.1 on the virtual drive X, do not cancel, however, the system or hidden directories. So how do I change this script to delete these directories?

THANKS

BYE

Edited by balubeto
Link to comment
Share on other sites

HI

Putting in X virtual disk of Windows PE 2.1 this script, it should delete all files and all directories of an NTFS partition in which there is the \Users directory except this directory and its subdirectories.

@echo off 

for %%I in (C D E F G H I J K L M N O P Q R S T U V W Y Z) do (
if exist %%I:\Users set DVDDrive=%%I else (
echo not exist the %%I:\Users directory.
pause
goto :EOF)
)

pushd X:\Windows\System32

for /R %%f in (%DVDDrive%\) do (
if not "%%f" == "%DVDDrive%\Users" (attrib -rhsi *.* /s
del /s /q *.*)
)

popd

Right or should I make some correction?

THANKS

BYE

Edited by Tripredacus
Merged topics
Link to comment
Share on other sites

I recommend using a ? to separate the list of subfolders instead of /. This will allow you to enhance the script later to work at any level of directories. Here is a script in biterscripting.

# Script delete.txt
# Input arguments
var str dir # Directory fro where to delete
var str dont # List of subfolders not to delete, separated by ?

# Get a list of all subfolders in $dir.
var str list; lf -n "*" $dir ($ftype=="d") > $list

# Process each subfolder one by one
while ($list <> "")
do
# Get the next subfolder from the list.
var str subfolder; lex "1" $list > $subfolder # $subfolder now contains the full path of subfolder
var list name; stex -p "^/^l[" $subfolder > $name # $name contains only the name of the subfolder

# Is this name in the list of not-to-delete $list ?
if ( { sen ("^"+$name+"^") $dont } <= 0 )
# This subfolder is not in the list of not-to-delete subfolders. Delete it.
system delete ("\""+$subfolder+"\"")
endif
done

This script will work in all Windows versions. I haven't tested it, so test it first. To test,

1. Save the script in, say, C:\delete.txt.

2. Install biterscripting from http://www.biterscripting.com or any other site you can google up. It's free.

3. Start biterscripting. Run the delete.txt script with the following command.

script "C:\delete.txt"

That's it.

Sen

Link to comment
Share on other sites

I recommend using a ? to separate the list of subfolders instead of /. This will allow you to enhance the script later to work at any level of directories. Here is a script in biterscripting.

# Script delete.txt
# Input arguments
var str dir # Directory fro where to delete
var str dont # List of subfolders not to delete, separated by ?

# Get a list of all subfolders in $dir.
var str list; lf -n "*" $dir ($ftype=="d") > $list

# Process each subfolder one by one
while ($list <> "")
do
# Get the next subfolder from the list.
var str subfolder; lex "1" $list > $subfolder # $subfolder now contains the full path of subfolder
var list name; stex -p "^/^l[" $subfolder > $name # $name contains only the name of the subfolder

# Is this name in the list of not-to-delete $list ?
if ( { sen ("^"+$name+"^") $dont } <= 0 )
# This subfolder is not in the list of not-to-delete subfolders. Delete it.
system delete ("\""+$subfolder+"\"")
endif
done

This script will work in all Windows versions. I haven't tested it, so test it first. To test,

1. Save the script in, say, C:\delete.txt.

2. Install biterscripting from http://www.biterscripting.com or any other site you can google up. It's free.

3. Start biterscripting. Run the delete.txt script with the following command.

script "C:\delete.txt"

That's it.

Sen

Can I convert this script into a cmd script so that Vista can run it directly? If so, how do I do this?

THANKS

BYE

Link to comment
Share on other sites

  • 5 months later...
Can I convert this script into a cmd script so that Vista can run it directly? If so, how do I do this?

Yes, you can run the script directly from Vista command prompt by entering the following command at the command prompt.

"C:\biterScripting\biterScripting.exe" "C:\delete.txt"

You can also schedule this same command in task scheduler if needed.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...