Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: How to check if a directory is empty or not  (Read 3764 times)

0 Members and 1 Guest are viewing this topic.

donkey

  • Guest
How to check if a directory is empty or not
« on: August 03, 2005, 02:35:39 PM »
Hi there,

I would like to copy files from one directory to another directory. If the source directory is empty, I would like to print a warning message and skip the xcopy command. How to do it? Thank you.

J.

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: How to check if a directory is empty or not
« Reply #1 on: August 03, 2005, 03:26:42 PM »
If you test directory size in batch, it will always come up empty (restricted to files). XCOPY has the /s /e /t switches that may be able to do what you need (type XCOPY /? at a command prompt for details) although putting out a message could be problematic.

WinScript is always an option as  folders have a SIZE property you can test.

Check out The Windows Script Center and it's links for more info.

Hope this helps. 8)
« Last Edit: August 03, 2005, 03:28:32 PM by Sidewinder »
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

Dilbert

  • Moderator


  • Egghead

  • Welcome to ComputerHope!
  • Thanked: 44
    Re: How to check if a directory is empty or not
    « Reply #2 on: August 03, 2005, 09:40:25 PM »
    Hello,

    Just made a .BAT file that answers your problem neatly:

    @ECHO OFF

    IF NOT EXIST %1 GOTO Error

    XCOPY %1 %2
    GOTO End

    :Error
    ECHO Source does not exist.
    GOTO End

    :End


    Call it whatever you want; I call it ZXCOPY.BAT
    Good luck!
    « Last Edit: August 03, 2005, 10:01:17 PM by Timothy_Bennett »
    "The geek shall inherit the Earth."