Jump to content

Recommended Posts

Posted (edited)

Win XP Home SP.3 Using CMD.exe scripting.

1. If I want to rename a lot of files in the default directory by deleting the first three characters of each name I can use:

For /f "delims=*" %%A in ('dir /b') do (
set name=%%A
ren "%%A" "!name:~3!"
)

Can the intended result be achieved without using Set so that the code might look something like:

 for /f etc....
ren "%%A" "!%%A:~3!"
)

Is it possible to change the content of %%A in this or a similar manner? I've tried various command syntaxes without success.

2. Can batch scripting command(s) be used to edit a binary file? All I've managed to do is amend the hex display of the binary but have been unable to write the binary change to disk.

Example: A binary contains one byte 11111111 (decimal 255) which is displayed as hex FF which is to be changed to 11111110 (245) FE Resolved...

Thanks.

Edited by Valerie

Posted

Unfortunately not, you'll need to use 'Set'.

I'd just like to make a few observations.

  • Your script would need EnableDelayedExpansion
  • A confusion has occurred; Use either "Delims=" or "Tokens=*"
  • If you have the batch file in the same directory as your files to be renamed, you'd need to make sure that the batch file itself isn't renamed too!

Example without delayed expansion

@Echo off&Setlocal
For /f "delims=" %%A In ('Dir/b/o-n/a-d^|Findstr/vix "%~nx0"') Do (
Set "name=%%~nA"&Call Set "name=%%name:~3%%"
Call Ren "%%A" "%%name%%%%~xA")

Posted

Thank you Wise One, your advice and comments are appreciated.

I hadn't included my entire script, enabledelayedexpansion is achieved using the /v:on switch when cmd.exe is invoked and the script is run from an exclusive .bat directory, pushd is used to access the "default" directory containing files.

Again, many thanks.

V.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...