F5F Stay Refreshed Software Operating Systems Add "and" functionality to a BAT file for copying and renaming files.

Add "and" functionality to a BAT file for copying and renaming files.

Add "and" functionality to a BAT file for copying and renaming files.

E
elegantelmo
Junior Member
38
09-05-2016, 04:17 AM
#1
I really enjoy the Windows login screen pictures. I made a batch file to move them from one spot to another and rename them to "*jpg". It worked before PowerShell became essential—it ran smoothly in the command prompt. Now that PowerShell is more common, renaming files with a batch command isn't possible directly. I found another script that handles it differently, but I'm not sure how to merge both steps into one process. Would you like me to suggest an alternative approach?
E
elegantelmo
09-05-2016, 04:17 AM #1

I really enjoy the Windows login screen pictures. I made a batch file to move them from one spot to another and rename them to "*jpg". It worked before PowerShell became essential—it ran smoothly in the command prompt. Now that PowerShell is more common, renaming files with a batch command isn't possible directly. I found another script that handles it differently, but I'm not sure how to merge both steps into one process. Would you like me to suggest an alternative approach?

T
tigerbob7888
Member
60
09-06-2016, 07:08 AM
#2
This explanation outlines why a simple PHP program isn't being generated and what alternatives exist. It suggests running the script via command line or creating a shortcut, and mentions that a basic version could be written with minor corrections. The comments also note that the example code contains some syntax issues but is intended to illustrate functionality.
T
tigerbob7888
09-06-2016, 07:08 AM #2

This explanation outlines why a simple PHP program isn't being generated and what alternatives exist. It suggests running the script via command line or creating a shortcut, and mentions that a basic version could be written with minor corrections. The comments also note that the example code contains some syntax issues but is intended to illustrate functionality.

P
pegasusXman
Member
194
09-16-2016, 09:14 PM
#3
Hi, thank you for your message. I understand you're new to this and want to learn. To help you, you can copy the files from A to B and rename them. The script you described is similar, but your approach was using Notepad and a .BAT file. Your version should work if you follow the same steps. Let me know if you need more guidance!
P
pegasusXman
09-16-2016, 09:14 PM #3

Hi, thank you for your message. I understand you're new to this and want to learn. To help you, you can copy the files from A to B and rename them. The script you described is similar, but your approach was using Notepad and a .BAT file. Your version should work if you follow the same steps. Let me know if you need more guidance!

T
thefinalgamer7
Junior Member
2
09-29-2016, 04:25 PM
#4
Save your script with a .php extension. Execute it by providing the PHP executable as an argument, ensuring PHP is installed on Windows and placed in a designated directory—similar to how robocopy works. PHP parses the file and performs its intended actions before closing. The provided code contains numerous comments, indicating it processes a folder path. If the path matches, establish a connection to that folder. Begin reading file names or records until encountering an error; note that filenames may include dots or backslashes, which can complicate handling. It’s better to treat each record as a standalone item rather than a folder name. If a filename is valid and not a special path segment, copy it from the source folder to the destination, appending ".jpg". Always close the connection properly after operations.
T
thefinalgamer7
09-29-2016, 04:25 PM #4

Save your script with a .php extension. Execute it by providing the PHP executable as an argument, ensuring PHP is installed on Windows and placed in a designated directory—similar to how robocopy works. PHP parses the file and performs its intended actions before closing. The provided code contains numerous comments, indicating it processes a folder path. If the path matches, establish a connection to that folder. Begin reading file names or records until encountering an error; note that filenames may include dots or backslashes, which can complicate handling. It’s better to treat each record as a standalone item rather than a folder name. If a filename is valid and not a special path segment, copy it from the source folder to the destination, appending ".jpg". Always close the connection properly after operations.

A
Aceis2be
Junior Member
35
09-29-2016, 04:53 PM
#5
This requires installing software. The batch file I have works locally but not across systems. You can add instructions to run additional steps after the main task.
A
Aceis2be
09-29-2016, 04:53 PM #5

This requires installing software. The batch file I have works locally but not across systems. You can add instructions to run additional steps after the main task.

M
Mulchy420
Junior Member
8
09-30-2016, 03:16 PM
#6
Don't install anything... just extract the PHP folder. Jesus... visit https://windows.php.net/download/ and scroll to PHP 7.4 (version 8 is a bit early, not necessary for this simple task). Unzip the archive into a location like c:\temp\php or c:\php or c:\programs\php. In case you need it, also run the Visual C++ runtime since PHP is written in C++: https://aka.ms/vs/16/release/VC_redist.x64.exe. The goal is to avoid relying on external tools like robocopy or gci command. Instead of using commands, stick to your own code—functions like copy, opendir, readdir are built-in. Your script should work without them. As for the PHP files, check their documentation for functions that let you inspect images. For example, you could open each image, check its size (width x height), and skip anything smaller than 800x600 pixels. This way, you won’t end up copying irrelevant thumbnails or bad files—something batch scripts can’t do.
M
Mulchy420
09-30-2016, 03:16 PM #6

Don't install anything... just extract the PHP folder. Jesus... visit https://windows.php.net/download/ and scroll to PHP 7.4 (version 8 is a bit early, not necessary for this simple task). Unzip the archive into a location like c:\temp\php or c:\php or c:\programs\php. In case you need it, also run the Visual C++ runtime since PHP is written in C++: https://aka.ms/vs/16/release/VC_redist.x64.exe. The goal is to avoid relying on external tools like robocopy or gci command. Instead of using commands, stick to your own code—functions like copy, opendir, readdir are built-in. Your script should work without them. As for the PHP files, check their documentation for functions that let you inspect images. For example, you could open each image, check its size (width x height), and skip anything smaller than 800x600 pixels. This way, you won’t end up copying irrelevant thumbnails or bad files—something batch scripts can’t do.

E
Epsylon16
Member
209
09-30-2016, 05:00 PM
#7
Thank you for your patience. I understand you're having trouble with the script and need guidance on adjusting image resolution below 800x800 pixels. The comments you saw only mention resizing, so I'll help you incorporate the resolution settings into your code.
E
Epsylon16
09-30-2016, 05:00 PM #7

Thank you for your patience. I understand you're having trouble with the script and need guidance on adjusting image resolution below 800x800 pixels. The comments you saw only mention resizing, so I'll help you incorporate the resolution settings into your code.

T
THE_BEAST_25
Junior Member
37
10-01-2016, 12:30 PM
#8
These are tools in the coding environment, used to interact with them. You begin by calling functions to handle data. For instance, you start by fetching a photo into memory using a proper method. For JPEG files, PHP offers imagecreatefromjpeg: https://www.php.net/manual/en/function.i...omjpeg.php. This tool takes the file path and returns an ID, acting like a label for the image. You use this to manipulate the picture from then on. Next, you can fetch details such as size with functions like imagesx and imagesy, which show width and height. You can store these values in variables and act only when they fit your criteria. To define a value in memory, simply prefix a word with a dollar sign. Here’s how you’d load a file at C:\temp/picture.jpg and check its size: <?php $filename = 'c:/temp/picture.jpg'; // Load the image into memory $pic = imagecreatefromjpeg($filename); if ($pic === FALSE) { echo "Error opening image."; die(); } $x = imagesx($pic); $y = imagesy($pic); if ($x >= 1024 && $x <= 1920 && $y >= 600 && $y <= 1080) { echo "Resolution is valid."; } else { echo "Size out of range."; } ?> This script will only proceed if the image meets your size requirements.
T
THE_BEAST_25
10-01-2016, 12:30 PM #8

These are tools in the coding environment, used to interact with them. You begin by calling functions to handle data. For instance, you start by fetching a photo into memory using a proper method. For JPEG files, PHP offers imagecreatefromjpeg: https://www.php.net/manual/en/function.i...omjpeg.php. This tool takes the file path and returns an ID, acting like a label for the image. You use this to manipulate the picture from then on. Next, you can fetch details such as size with functions like imagesx and imagesy, which show width and height. You can store these values in variables and act only when they fit your criteria. To define a value in memory, simply prefix a word with a dollar sign. Here’s how you’d load a file at C:\temp/picture.jpg and check its size: <?php $filename = 'c:/temp/picture.jpg'; // Load the image into memory $pic = imagecreatefromjpeg($filename); if ($pic === FALSE) { echo "Error opening image."; die(); } $x = imagesx($pic); $y = imagesy($pic); if ($x >= 1024 && $x <= 1920 && $y >= 600 && $y <= 1080) { echo "Resolution is valid."; } else { echo "Size out of range."; } ?> This script will only proceed if the image meets your size requirements.

S
56
10-01-2016, 05:43 PM
#9
You're wondering how to select entire folders instead of individual files. Since using just the path like "C/testpicture.jpg" doesn't let you type names manually, you can tell the script to scan the directory and check dimensions. To combine both scripts, you can adjust the logic to handle multiple files at once.
S
Sleepwalker667
10-01-2016, 05:43 PM #9

You're wondering how to select entire folders instead of individual files. Since using just the path like "C/testpicture.jpg" doesn't let you type names manually, you can tell the script to scan the directory and check dimensions. To combine both scripts, you can adjust the logic to handle multiple files at once.

G
GewoonRomano
Member
195
10-02-2016, 07:38 AM
#10
I demonstrated the code where all processing happens within a function named is_good_picture that receives a full file path as input and returns TRUE or FALSE. This section spans from the function definition up to the closing brace. The input you provide—your complete file name with its location—is stored in the $filename variable, regardless of what you label it (like $a, $input, or $picture). You can insert this block anywhere in your script and reuse it wherever needed. Inside the block, you can evaluate conditions such as resolution and dimensions, and decide whether to copy the file. You also have access to built-in tools that extract folder details, name, and extension from a path, making it easier to filter files by type or format.
G
GewoonRomano
10-02-2016, 07:38 AM #10

I demonstrated the code where all processing happens within a function named is_good_picture that receives a full file path as input and returns TRUE or FALSE. This section spans from the function definition up to the closing brace. The input you provide—your complete file name with its location—is stored in the $filename variable, regardless of what you label it (like $a, $input, or $picture). You can insert this block anywhere in your script and reuse it wherever needed. Inside the block, you can evaluate conditions such as resolution and dimensions, and decide whether to copy the file. You also have access to built-in tools that extract folder details, name, and extension from a path, making it easier to filter files by type or format.