Sign in to follow this  
Followers 0
eJan

How to check if folder doesn't contain any other

7 posts in this topic

I'm trying to make script which will check if "@AppDataCommonDir (\001)" doesn't contain any file or subfolder except "\001" which contain files and subfolders inside and delete @AppDataCommonDir if no other files or folders exists.

Share this post


Link to post
Share on other sites



$empty = 1
$savedpath = @WorkingDir
FileChangeDir(@AppDataCommonDir)

$search = FileFindFirstFile("*.*")
While $empty
    $file = FileFindNextFile($search) 
    If @error Then ExitLoop
    if $file = "." OR $file = ".." OR $file = "001" then continueloop
    $empty = 0
WEnd

FileChangeDir($savedpath)

Cheers

Kurt


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

Thanks Kurt, but I couldn't get it to work, this is what it looks like:Posted Image

My point is to extract files B:\Documents and Settings\All Users\Application Data\001 to RamDrive, to use files for some time then delete 001 and @AppDataCommonDir if any other folder or file doesn't exist inside @AppDataCommonDir. On RamDrive @AppDataCommonDir doesn't exist by default.

Share this post


Link to post
Share on other sites

#include <Constants.au3>

$dirs = Run(@ComSpec & " /c dir /AD /B", @AppDataCommonDir, @SW_HIDE, $STDOUT_CHILD)
$alldirs = ""

While 1
$alldirs = $alldirs & StdoutRead($dirs)
 If @error = -1 Then ExitLoop
Wend

MsgBox(0, @AppDataCommonDir, $alldirs)

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Thanks Kurt, but I couldn't get it to work, this is what it looks

what exactly does not work? My code checks if @AppDataCommonDir holds only \001. If so, the variable $empty will be set to 1. If there is anything else in @AppDataCommonDir, then the variable will be set to 0. You will have to write your own code to delte or copy files based on that information.

BTW: The screenshot does not match your textual description. Is that intentional?

Cheers

Kurt

Edited by /dev/null

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

Have a look at my _FileFindAll() function

It returns a list of files that match a mask and an attribute filter. This usage:

_FileFindAll(@AppDataCommonDir, '*', 'D')

will return an array containing the names of folders in @AppDataCommonDir. If the first element isn't '001' or the array is bigger than one, then you know there are more folders out there.

Share this post


Link to post
Share on other sites

what exactly does not work? My code checks if @AppDataCommonDir holds only \001. If so, the variable $empty will be set to 1. If there is anything else in @AppDataCommonDir, then the variable will be set to 0. You will have to write your own code to delte or copy files based on that information.

I have tried this way:

$empty = 1
$savedpath = @WorkingDir
FileChangeDir("D:\ZZ")

$search = FileFindFirstFile("*.*")
While $empty
    $file = FileFindNextFile($search)
    If @error Then ExitLoop
    If $file = "." Or $file = ".." Or $file = "001" Then
        DirRemove("D:\ZZ\001", 1)
    Else
        DirRemove("D:\ZZ", 1); does not remove dir (only content)
    EndIf
    $empty = 0
WEnd

FileChangeDir($savedpath)
Everything goes fine until Else, where DirRemove delete only files and folders inside "ZZ" but does not remove complete dir [DirRemove("D:\ZZ", 1)].

Share this post


Link to post
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
Sign in to follow this  
Followers 0