So, I have a batch that runs through a file system, and checks the size of the files in it and renames them with a different extension if the size is zero bytes. That part was easy, but now I have to check to see if what's currently being looked at is a file or a folder.
here's my code so far.
SET FTPFOLDER="C:\temp"
rem this goes thru a folder system.
for /f %%f in ('dir /b %FTPFOLDER%') do (call :Search "%%f")
EXIT /B 0
REM GOES THRU EACH OF THE FILES IN EACH OF THE FOLDERS
:Search
for /f %%g in ('dir /b %FTPFOLDER%\%~1') do(call :checkType "%%g", "%FTPFOLDER%\%~1\%%g\", %%~ng )
pause
EXIT /B 0
:checkType
if exists %~1\* (call :Search %~1) else (call :checkSize %~2, %~3)
EXIT /B 0
REM CHECKS IF ZERO
:checkSize
set file=%~1
@echo %file%
for /f "usebackq" %%h in ('%file%') do set size=%%~zh
if %size% EQU 0 (call :Rename "%file%", %~2)
EXIT /B 0
REM - RENAMES FILE TO .EMPTY
:Rename
ren %~1 %~2.empty
EXIT /B 0
Nothing I've tried so far has worked. I am extremely new to batch, so any and all help would be appreciated, especially with explanations.
Edit: I feel that it's also important to mention that no file names or folder names will have spaces.
Edit: I have changed my code to remove the extra function, and do it in the for loop. My new code is as follows
SET FTPFOLDER="C:\Users\nmavis\Desktop\gndjufsb"
rem this goes thru a folder system.
for /f %%f in ('dir /b %FTPFOLDER%') do (call :Search "%%f")
EXIT /B 0
REM GOES THRU EACH OF THE FILES IN EACH OF THE FOLDERS
:Search
for /f %%g in ('dir /b %FTPFOLDER%\%~1') do (if exist %%~sg\NUL (echo dir) else (echo file))
pause
EXIT /B 0
REM CHECKS IF ZERO
:checkSize
set file=%~1
@echo %file%
for /f "usebackq" %%h in ('%file%') do set size=%%~zh
if %size% EQU 0 (call :Rename "%file%", %~2)
EXIT /B 0
REM - RENAMES FILE TO .EMPTY
:Rename
ren %~1 %~2.empty
EXIT /B 0
However, whenever I run it, no matter whether or not it is a file or a folder, it displays "File"