So any time you see any kind of coding in any script ps1 or bat and so forth, you consider them malicious ? It may sound harsh, but you better learn to program, sit in a computer science 101 at a university. You don't need to pass the entrance test, just get the class schedule to find the classroom and go sit down. Most professors allow that. Malware detection Requires one to understand code a little bit.
I just upload the source code to chat gpt but, still shows it's risky.
Short answer:
risky — unless you run it only in a controlled test folder after doing a dry-run and a backup.
Why I call it risky
- It blindly renames every matched entry
*.*
in the current directory. That can include important files (documents, executables, config files) and may produce unwanted .txt
suffixes.
- Files already ending in
.txt
will become .txt.txt
.
- Name collisions: if
foo.doc
→ foo.doc.txt
but foo.doc.txt
already exists, ren
will fail or cause unexpected behavior.
- The batch file itself (or other scripts) can be targeted and renamed while running — fragile and confusing.
- No checks for read-only or system/hidden attributes, no logging, no dry-run.
- Could break other programs that expect original filenames (software, scripts, indexes, backups).
- Permissions or antivirus may stop or partially complete the job, leaving an inconsistent state.
When it can be considered safe
- You run it in an empty or disposable test folder (e.g., created only for this task).
- You run a dry-run first and verify the results.
- You have a backup or versioned copy of the files.
Safer version (adds dry-run, skips
.txt
, skips the script itself, avoids overwriting existing targets, logs)
Code:
@echo off
setlocal enabledelayedexpansion
set "LOG=rename_log.txt"
echo Rename run at %DATE% %TIME% > "%LOG%"
rem Dry-run mode: change DRYRUN=1 to DRYRUN=0 to actually perform renames
set "DRYRUN=1"
for %%F in (*.*) do (
rem skip directories (if they have a trailing \ check)
if not exist "%%~fF\" (
rem skip files already .txt
if /I not "%%~xF"==".txt" (
rem skip the script itself
if /I not "%%~nxF"=="%~nx0" (
set "src=%%F"
set "dst=%%~nF%%~xF.txt"
if exist "!dst!" (
echo SKIP (target exists): "%%F" -> "!dst!" >> "%LOG%"
echo Skipping "%%F" (target exists)
) else (
echo Planned: ren "%%F" "!dst!" >> "%LOG%"
if "!DRYRUN!"=="0" ren "%%F" "!dst!"
)
) else (
echo SKIP (script): "%%F" >> "%LOG%"
)
) else (
echo SKIP (.txt already): "%%F" >> "%LOG%"
)
)
)
endlocal
- Start with
DRYRUN=1
to print/log planned actions; set to 0
only after you verify the log.
- Run in the folder where you want the action and not in system folders.
Prefer PowerShell for safety and clarity
Code:
Get-ChildItem -File | Where-Object { $_.Extension -ne '.txt' -and $_.Name -ne $MyInvocation.MyCommand.Name } |
ForEach-Object {
$new = $_.Name + '.txt'
if (-not (Test-Path $new)) {
Write-Output "Rename: $($_.Name) -> $new"
# Rename-Item -LiteralPath $_.FullName -NewName $new # remove comment to apply
} else {
Write-Output "Skip (exists): $new"
}
}
- Use
-WhatIf
or comment out Rename-Item
while testing.
Quick checklist before running anything that renames many files
- Work in a test folder first.
- Run a dry-run and inspect the planned changes (log).
- Make a backup or snapshot.
- Exclude
.txt
, the script itself, and any important system folders.
- Ensure you understand how name collisions will be handled.
- If many files, test a small subset first.
1) Simple example — how names change (expected, immediate problem)
Start with this folder contents (example):
Code:
report.doc
photo.jpg
notes.txt
program.exe
script.bat
archive.tar.gz
README
Your script runs:
Code:
for %%f in (*.*) do (
ren "%%f" "%%~nxf.txt"
)
%%~nxf
expands to the original
name + extension, so the renames attempted are:
report.doc
→ report.doc.txt
(probably fine)
photo.jpg
→ photo.jpg.txt
notes.txt
→ notes.txt.txt
(now doubled)
program.exe
→ program.exe.txt
(no longer executable)
script.bat
→ script.bat.txt
(the batch file itself matches and will be targeted)
archive.tar.gz
→ archive.tar.gz.txt
README
— no dot: does not match *.*
, so it is skipped
Concrete proof: see how
.exe
and
.bat
now have
.txt
appended — that immediately breaks executability and scripts that expect those names.
2) Name-collision example (actual failure)
If a file with the
target name already exists, the rename will fail for that file.
Start with:
Code:
foo.doc
foo.doc.txt <-- already exists
Attempted operation:
Code:
ren "foo.doc" "foo.doc.txt"
Result: the command fails because the target name already exists. Outcome:
foo.doc
remains unchanged while the user expected it to be renamed. If your script runs on hundreds of files, you get a chaotic partial state (some renamed, some failed) —
inconsistent file set.
3) Breakage of programs / services (real-world consequence)
If you run the script in a folder that contains application files:
program.exe
→ program.exe.txt
: program will not run (double-click tries to open it as text).
lib.dll
→ lib.dll.txt
: dependent applications will fail to load that DLL and may crash.
config.json
→ config.json.txt
: services expecting config.json
will not find it and may fail to start or revert to defaults.
- Scheduled tasks/scripts that reference exact filenames will break.
These are not theoretical — renaming file extensions changes how Windows identifies and handles files.
4) The batch file itself can be targeted (confusing/unreliable)
Your script uses
*.*
so if the batch file (say
rename.bat
) lives in the same folder it will be included and an attempt will be made to rename it to
rename.bat.txt
. Even if renaming an executing script is allowed on some systems, this leads to confusing states: the script’s filename changed on disk while it was running; future calls to the same filename will fail; maintenance becomes harder. It’s poor practice and can produce unexpected behavior.
Note: OS behavior about renaming an open/running file can vary; whether Windows allows renaming an executing batch file is environment-dependent. Regardless, trying to rename your running script is undesirable and risky.
5) Hidden/system files, backups, and permission errors
- If the directory contains read-only, system, or in-use files, some
ren
operations will fail, producing a mixture of successful and failed renames.
- Antivirus or policy software may block or quarantine files mid-run, again leaving the folder inconsistent.
- If you run the script in a system folder (or a folder used by backups, version control, or services), you can corrupt backups or break those services.
6) Demonstration you can run safely (dry-run)
Here’s a safe
dry-run test you can run in a disposable folder (create a test folder first):
Batch dry-run simulation (do
not run the real ren command — just show planned actions):
Code:
@echo off
echo Dry-run: planned renames
for %%f in (*.*) do (
echo ren "%%f" "%%~nxf.txt"
)
This prints every
ren
command the script would execute — inspect the output and you’ll see all the problem cases (e.g.,
notes.txt
→
notes.txt.txt
,
program.exe
→
program.exe.txt
, and
script.bat
→
script.bat.txt
).
7) Summary — short, provable reasons it's unsafe
- Unselective: It renames every
*.*
, including .exe
, .dll
, .bat
, .sys
-like names — which breaks executability and program behavior. (You can prove this by creating an .exe
file and observing it becomes non-executable.)
- Doubles
.txt
: Files already .txt
become *.txt.txt
, an obvious unwanted change you can reproduce instantly.
- Collisions: If
name.ext.txt
already exists, the rename fails — you get partial/uneven results that are hard to recover from.
- Self-targeting: The script can rename itself — this is demonstrable by running it in the same folder as the script and observing the file name change or error.
- No safeguards/logging/backups: There’s no dry-run, no check for existing targets, and no recovery plan — so mistakes are permanent unless you have backups.
8) How to prove it yourself in one minute (safe)
- Create a new folder
C:\temp\rename-test
.
- Put these files in it:
test.exe
, notes.txt
, doc.doc
.
- Run the dry-run batch I gave above (it only
echo
s the ren commands).
- Observe the planned renames:
test.exe
→ test.exe.txt
(broken), notes.txt
→ notes.txt.txt
(wrong), doc.doc
→ doc.doc.txt
(maybe desired).
- If you want to test actual rename, copy the folder first (backup), then run the real script in the copy and observe the destructive changes.