Custom Batch Scripts; Needing Help

WyattWhiteEagle

Member
Member
VIP
Local time
7:35 PM
Messages
181
Where's the best to post custom batch text asking for help to improve it's results?
 

My Computer My Computer

At a glance

Microsoft Windows 7 Home Premium 64-bit 7601 ...Intel(R) Core(TM) i3-N3054.00 GBStandard VGA Graphics Adapter
Computer type
Laptop
Computer Manufacturer/Model Number
LENOVO IdeaPad Slim 3 15IAN8
OS
Microsoft Windows 7 Home Premium 64-bit 7601 Multiprocessor Free Service Pack 1
CPU
Intel(R) Core(TM) i3-N305
Motherboard
Oracle Corporation VirtualBox
Memory
4.00 GB
Graphics Card(s)
Standard VGA Graphics Adapter
Sound Card
High Definition Audio Device
Hard Drives
VBOX HARDDISK ATA Device
here
 

My Computers My Computers

  • At a glance

    7 X64i5 84002x8gb 3200mhz
    Computer type
    PC/Desktop
    OS
    7 X64
    CPU
    i5 8400
    Motherboard
    gigabyte b365m ds3h
    Memory
    2x8gb 3200mhz
    Hard Drives
    various
    PSU
    pure power 11 400w cm
    Case
    Coolermaster
    Cooling
    cryorig m9i
  • At a glance

    7x64g54008gb ddr4 2400
    Computer type
    PC/Desktop
    OS
    7x64
    CPU
    g5400
    Motherboard
    ga b365m ds3h
    Memory
    8gb ddr4 2400
    PSU
    xfx pro 450w
From Google's AI Overview and mode.
It has a note attached to it saying, "AI can contain mistakes, so double-check responses."

Does the following "code" have anything missing or incorrect?

I searched for this and AI returned the code...
windows 7 64 bit move files recursively filter by specific file types into 100 megabytes limit per directory cmd batch
Code:
@echo off

cls

SETLOCAL ENABLEDELAYEDEXPANSION

:: --- CONFIGURATION ---
:: Path where your files currently are (no trailing slash)
SET "SourcePath=C:\Your\Source\Folder"

:: Path where you want the new folders to be created
SET "DestPath=C:\Your\Destination\Folder"

:: File extension filter (e.g., .mp4, .jpg, .pdf)
SET "ExtFilter=*.mp4"

:: Size limit per directory in bytes (100MB = 104,857,600 bytes)
SET /A MaxSizeBytes=104857600

:: --- SCRIPT EXECUTION ---
IF NOT EXIST "%DestPath%" MD "%DestPath%"
SET "CurrentFolderNum=1"
CALL :CREATE_NEW_DIR

:: Recursively find files and process them
FOR /R "%SourcePath%" %%F IN (%ExtFilter%) DO (
    IF "%%~aF" LSS "d" (
        SET "FileSize=%%~zF"
        
        :: Add current folder's size
        SET /A "TotalSize=!TotalSize! + FileSize"
        
        :: Check if adding the file exceeds the 100MB limit
        IF !TotalSize! GTR %MaxSizeBytes% (
            SET /A "CurrentFolderNum+=1"
            CALL :CREATE_NEW_DIR
            SET "TotalSize=!FileSize!"
        )
        
        ECHO Moving: "%%~nxF" to !CurrentFolder!
        MOVE "%%F" "!CurrentFolder!\"
    )
)

ECHO Task Completed!
PAUSE
EXIT /B

:CREATE_NEW_DIR
SET "CurrentFolder=%DestPath%\Group_!CurrentFolderNum!"
MD "%CurrentFolder%"
SET "TotalSize=0"
EXIT /B
 
Last edited:

My Computer My Computer

At a glance

Microsoft Windows 7 Home Premium 64-bit 7601 ...Intel(R) Core(TM) i3-N3054.00 GBStandard VGA Graphics Adapter
Computer type
Laptop
Computer Manufacturer/Model Number
LENOVO IdeaPad Slim 3 15IAN8
OS
Microsoft Windows 7 Home Premium 64-bit 7601 Multiprocessor Free Service Pack 1
CPU
Intel(R) Core(TM) i3-N305
Motherboard
Oracle Corporation VirtualBox
Memory
4.00 GB
Graphics Card(s)
Standard VGA Graphics Adapter
Sound Card
High Definition Audio Device
Hard Drives
VBOX HARDDISK ATA Device
Not exactly solved yet.
Making the needed changes, it works very well.
The optional changes work well also, such as

Code:
SET "CurrentFolder=%DestPath%\Group_!CurrentFolderNum!"

to

Code:
SET "CurrentFolder=%DestPath%\Txt_!CurrentFolderNum!"
 

My Computer My Computer

At a glance

Microsoft Windows 7 Home Premium 64-bit 7601 ...Intel(R) Core(TM) i3-N3054.00 GBStandard VGA Graphics Adapter
Computer type
Laptop
Computer Manufacturer/Model Number
LENOVO IdeaPad Slim 3 15IAN8
OS
Microsoft Windows 7 Home Premium 64-bit 7601 Multiprocessor Free Service Pack 1
CPU
Intel(R) Core(TM) i3-N305
Motherboard
Oracle Corporation VirtualBox
Memory
4.00 GB
Graphics Card(s)
Standard VGA Graphics Adapter
Sound Card
High Definition Audio Device
Hard Drives
VBOX HARDDISK ATA Device
Next task: Do multiple file types in my batch file.

One possible downfall might be, "variable may not distinguish between the many different file type's."
Possible work-around may be to create the new variable's with numbers.
Useful for when repeating the command's for multiple file extensions within the script.

Example:
Code:
SET "ExtFilter=*.mp4"
to
Code:
SET "ExtFilter001=*.mp4"
 
Last edited:

My Computer My Computer

At a glance

Microsoft Windows 7 Home Premium 64-bit 7601 ...Intel(R) Core(TM) i3-N3054.00 GBStandard VGA Graphics Adapter
Computer type
Laptop
Computer Manufacturer/Model Number
LENOVO IdeaPad Slim 3 15IAN8
OS
Microsoft Windows 7 Home Premium 64-bit 7601 Multiprocessor Free Service Pack 1
CPU
Intel(R) Core(TM) i3-N305
Motherboard
Oracle Corporation VirtualBox
Memory
4.00 GB
Graphics Card(s)
Standard VGA Graphics Adapter
Sound Card
High Definition Audio Device
Hard Drives
VBOX HARDDISK ATA Device
After running the newly customized script, the recent 001 and designated file extensions to match didn't work...

Back to original script customizations

Marking my spot within the script.
Will continue my works after some much needed rest.:cool:
 
Last edited:

My Computer My Computer

At a glance

Microsoft Windows 7 Home Premium 64-bit 7601 ...Intel(R) Core(TM) i3-N3054.00 GBStandard VGA Graphics Adapter
Computer type
Laptop
Computer Manufacturer/Model Number
LENOVO IdeaPad Slim 3 15IAN8
OS
Microsoft Windows 7 Home Premium 64-bit 7601 Multiprocessor Free Service Pack 1
CPU
Intel(R) Core(TM) i3-N305
Motherboard
Oracle Corporation VirtualBox
Memory
4.00 GB
Graphics Card(s)
Standard VGA Graphics Adapter
Sound Card
High Definition Audio Device
Hard Drives
VBOX HARDDISK ATA Device
It's beginning to look like this kind of script isn't a "one-size-fits-all" kind of script.
It seems like what I'm trying to accomplish is better achieved from one script calling other scripts when each file extension is accomplished.

Community, how might this script call another script?
 
Last edited:

My Computer My Computer

At a glance

Microsoft Windows 7 Home Premium 64-bit 7601 ...Intel(R) Core(TM) i3-N3054.00 GBStandard VGA Graphics Adapter
Computer type
Laptop
Computer Manufacturer/Model Number
LENOVO IdeaPad Slim 3 15IAN8
OS
Microsoft Windows 7 Home Premium 64-bit 7601 Multiprocessor Free Service Pack 1
CPU
Intel(R) Core(TM) i3-N305
Motherboard
Oracle Corporation VirtualBox
Memory
4.00 GB
Graphics Card(s)
Standard VGA Graphics Adapter
Sound Card
High Definition Audio Device
Hard Drives
VBOX HARDDISK ATA Device
This might help:
Another AI response...

To call another batch file from a main batch file in Windows 7 (64-bit), you must use the CALL command. [1, 2]
If you try to run the second batch file by simply typing its name without CALL, the first batch file will stop entirely, and control will never return to it. [3, 4, 5]

Run Sequentially (Wait for it to finish)​

Use CALL to pause the main script, run the second script, and then return to the main script. [1, 2]
Code:
@echo off
echo Starting the main script...

:: Call the second batch file
call "C:\path\to\second_file.bat"

echo Returned to the main script!
pause

⚠️ Important Windows 7 (64-bit) Caveats​



  • The Admin Path Trap:If your main script is running with Administrator privileges, Windows 7 changes the default working directory to C:\Windows\System32. If the second batch file is in the same folder as the first, it will fail with a "file not found" error. Fix this by adding a change-directory line to the top of your scripts:
    Code:
    cd /d "%~dp0"
    (That forces CMD to look in the folder where the script actually lives). [9, 10, 11]
  • Passing Parameters: You can pass arguments to the second file by adding them after the file name (e.g., call "file.bat" argument1 argument2). The second file can read them using %1 and %2. [1, 12, 13, 14, 15]

[1] https://ss64.com
[2] https://jpsoft.com
[3] https://stackoverflow.com
[4] https://df.lth.se
[5] https://opensource.com
[9] https://stackoverflow.com
[10] https://stackoverflow.com
[11] https://encyclopedia.pub
[12] https://superuser.com
[13] https://learn.microsoft.com
[14] https://superuser.com
[15] https://superuser.com
 
Last edited:

My Computer My Computer

At a glance

Microsoft Windows 7 Home Premium 64-bit 7601 ...Intel(R) Core(TM) i3-N3054.00 GBStandard VGA Graphics Adapter
Computer type
Laptop
Computer Manufacturer/Model Number
LENOVO IdeaPad Slim 3 15IAN8
OS
Microsoft Windows 7 Home Premium 64-bit 7601 Multiprocessor Free Service Pack 1
CPU
Intel(R) Core(TM) i3-N305
Motherboard
Oracle Corporation VirtualBox
Memory
4.00 GB
Graphics Card(s)
Standard VGA Graphics Adapter
Sound Card
High Definition Audio Device
Hard Drives
VBOX HARDDISK ATA Device
ok...I found how it is accomplished using the call command.
I'm just unsure where these need to be within my script in post 3 above.
Any idea's?
Code:
call file-1.bat
call file-2.bat
call file-3.bat
 

My Computer My Computer

At a glance

Microsoft Windows 7 Home Premium 64-bit 7601 ...Intel(R) Core(TM) i3-N3054.00 GBStandard VGA Graphics Adapter
Computer type
Laptop
Computer Manufacturer/Model Number
LENOVO IdeaPad Slim 3 15IAN8
OS
Microsoft Windows 7 Home Premium 64-bit 7601 Multiprocessor Free Service Pack 1
CPU
Intel(R) Core(TM) i3-N305
Motherboard
Oracle Corporation VirtualBox
Memory
4.00 GB
Graphics Card(s)
Standard VGA Graphics Adapter
Sound Card
High Definition Audio Device
Hard Drives
VBOX HARDDISK ATA Device
In my searching I found the following post.

See if this is what you are looking for:

First batch file

@echo off<br>::Batch File One (bat1.cmd)<br>cls<br>dir *.tmp<br>echo Calling Second Batch File...<br>pause<br><br>call bat2.cmd 1<br>echo Back to First Batch File...<br>echo Calling Second Batch File...<br>pause<br><br>call bat2.cmd 2<br>echo Back to First Batch File...

Second batch file

@echo off<br>::Batch File two (bat2.cmd)<br>cls<br>if "%1" EQU "" goto :eof<br>call :%1<br>goto :eof<br><br>:1<br>Echo Running commands from second batch file passing 1 as parameter...<br>pause<br>dir *.txt<br>goto :eof<br><br>:2<br>Echo Running commands from second batch file passing 2 as parameter...<br>pause<br>dir *.doc<br>goto :eof

The second batch file will do nothing unless a parameter is passed to it on the command line. This can be changed if needed, but should give you the idea of calling one batch file from another, running a specified sub-routine, and then return to the calling batch file.

Scr1ptW1zard
 
Last edited:

My Computer My Computer

At a glance

Microsoft Windows 7 Home Premium 64-bit 7601 ...Intel(R) Core(TM) i3-N3054.00 GBStandard VGA Graphics Adapter
Computer type
Laptop
Computer Manufacturer/Model Number
LENOVO IdeaPad Slim 3 15IAN8
OS
Microsoft Windows 7 Home Premium 64-bit 7601 Multiprocessor Free Service Pack 1
CPU
Intel(R) Core(TM) i3-N305
Motherboard
Oracle Corporation VirtualBox
Memory
4.00 GB
Graphics Card(s)
Standard VGA Graphics Adapter
Sound Card
High Definition Audio Device
Hard Drives
VBOX HARDDISK ATA Device
I'm actually wanting just one cmd batch file (*.bat) to sort multiple "file.ext" into 100mb limited directories labeled "*.Exe-1, Exe-2, Txt-1, Txt-2 Doc-1, Doc-2, etc."
These File's are saved from years and years of work.
I need them in 100mb directories before compressing to uplaod them to a cloud storage database.

Now to sift through these recent few postings, I might be able to see how it might fit together :cool:
 
Last edited:

My Computer My Computer

At a glance

Microsoft Windows 7 Home Premium 64-bit 7601 ...Intel(R) Core(TM) i3-N3054.00 GBStandard VGA Graphics Adapter
Computer type
Laptop
Computer Manufacturer/Model Number
LENOVO IdeaPad Slim 3 15IAN8
OS
Microsoft Windows 7 Home Premium 64-bit 7601 Multiprocessor Free Service Pack 1
CPU
Intel(R) Core(TM) i3-N305
Motherboard
Oracle Corporation VirtualBox
Memory
4.00 GB
Graphics Card(s)
Standard VGA Graphics Adapter
Sound Card
High Definition Audio Device
Hard Drives
VBOX HARDDISK ATA Device
Back
Top