Solved Check if there are files in a folder in a BAT file


1739221106634.webp



File not found in all cases
 

My Computer

System One

  • OS
    Windows 11 Home 23H2
    Computer type
    Laptop
    Manufacturer/Model
    *
    CPU
    *
    Motherboard
    *
    Memory
    *
    Graphics Card(s)
    *
    Sound Card
    *
    Monitor(s) Displays
    *
    Screen Resolution
    *
    Hard Drives
    *
    PSU
    *
    Case
    *
    Cooling
    *
    Keyboard
    *
    Mouse
    *
    Internet Speed
    *
    Browser
    *
    Antivirus
    *
    Other Info
    *
This is getting ridiculous. Móvil is not properly spelled in half of your examples. Pay attention to details!
 

My Computer

System One

  • OS
    Windows 7
Hello.

I want to check if a folder is empty or not.

- If true: message asking if I want to perform step 2.

- If false: message indicating that the folder is empty and closing the CMD window.

* IMPORTANT: when checking if a folder is empty or not, you must subtract two from the number of files, as there are two that always have to be there.

Thank you very much.

If you are using the English version of Windows, try the following. Replace "C:\Windows" with the folder you want searched. If you are using a different language version, please repost with that information.

@echo off

dir "C:\Windows" | find /i " 2 file(s)"
if %errorlevel%==0 (
echo No files found
pause
exit /b
)

echo.
echo Files found.
SET /p choice=Move files? [Y/N]:
 

My Computer

System One

  • OS
    Windows 10 Home
    Computer type
    Laptop
    Manufacturer/Model
    HP Elitebook 2530p
    CPU
    Intel Core 2 Duo L9400@1.86 GHz
    Memory
    2 GB
If you are using the English version of Windows, try the following. Replace "C:\Windows" with the folder you want searched. If you are using a different language version, please repost with that information.

@echo off

dir "C:\Windows" | find /i " 2 file(s)"
if %errorlevel%==0 (
echo No files found
pause
exit /b
)

echo.
echo Files found.
SET /p choice=Move files? [Y/N]:
I'm using Spanish version of windows

Folder I want to check it there are files D:\Bandeja de entrada\Móvil

I want to exclude, .sh and .txt, and files named Cuadre de cuentas.xlsm
 

My Computer

System One

  • OS
    Windows 11 Home 23H2
    Computer type
    Laptop
    Manufacturer/Model
    *
    CPU
    *
    Motherboard
    *
    Memory
    *
    Graphics Card(s)
    *
    Sound Card
    *
    Monitor(s) Displays
    *
    Screen Resolution
    *
    Hard Drives
    *
    PSU
    *
    Case
    *
    Cooling
    *
    Keyboard
    *
    Mouse
    *
    Internet Speed
    *
    Browser
    *
    Antivirus
    *
    Other Info
    *
Robocopy has an exclude files option(/xf). Specify your source and destination folders.

robocopy "source" "destination" /xf *.sh *.txt "Cuadre de cuentas.xlsm"
 

My Computer

System One

  • OS
    Windows 10 Home
    Computer type
    Laptop
    Manufacturer/Model
    HP Elitebook 2530p
    CPU
    Intel Core 2 Duo L9400@1.86 GHz
    Memory
    2 GB
Could I get number of files from a folder and its subfolder with robocoy????
 

My Computer

System One

  • OS
    Windows 11 Home 23H2
    Computer type
    Laptop
    Manufacturer/Model
    *
    CPU
    *
    Motherboard
    *
    Memory
    *
    Graphics Card(s)
    *
    Sound Card
    *
    Monitor(s) Displays
    *
    Screen Resolution
    *
    Hard Drives
    *
    PSU
    *
    Case
    *
    Cooling
    *
    Keyboard
    *
    Mouse
    *
    Internet Speed
    *
    Browser
    *
    Antivirus
    *
    Other Info
    *
Could I get number of files from a folder and its subfolder with robocoy????

If you mean a specific number of subfolders, yes. If you mean a specific number of files, probably not, but it can exclude files that have been changed, are newer, or are older than those on the destination folder, if that is helpful. If you are using the Spanish language version of Windows and looking for a way to avoid any action when the source folder contains exactly two files without knowing the file names, try the following in a batch file. Once again, you will have replace "C:\Windows" with the source folder name.

@echo off

dir "C:\Windows" | find /i " 2 archivos"
if %errorlevel%==0 (
echo No files found
pause
exit /b
)

echo.
echo Files found.
SET /p choice=Move files? [Y/N]:
 

My Computer

System One

  • OS
    Windows 10 Home
    Computer type
    Laptop
    Manufacturer/Model
    HP Elitebook 2530p
    CPU
    Intel Core 2 Duo L9400@1.86 GHz
    Memory
    2 GB
Ok, thanks, guys.

I've already solved what I looking for.
 

My Computer

System One

  • OS
    Windows 11 Home 23H2
    Computer type
    Laptop
    Manufacturer/Model
    *
    CPU
    *
    Motherboard
    *
    Memory
    *
    Graphics Card(s)
    *
    Sound Card
    *
    Monitor(s) Displays
    *
    Screen Resolution
    *
    Hard Drives
    *
    PSU
    *
    Case
    *
    Cooling
    *
    Keyboard
    *
    Mouse
    *
    Internet Speed
    *
    Browser
    *
    Antivirus
    *
    Other Info
    *

Latest Support Threads

Back
Top Bottom