Question There is a .batch file in each specific folder!

Sep 30, 2022
11
0
10
Hi everyone!

I took some games data from a friend, they are some .iso files which can be unpacked to games

But I found a file with .bat (batch) extension in each folder of these games folder and named with the same name of the folder

I opened one and a command prompt has started to copy files in the same drive which the file is located, then I noticed that each folder of the drive has a file named with the folder name and with .bat (batch) extension

Then I searched about any files with .bat (batch) extensions and I deleted all of them, and now everything is ok

When I used notepad edit to view the content of the .bat file, that is the content:


set h=For

%h% /R "D:\" /D %%a in (*) do copy %0 "%%~fa\%%~nxa.bat"


I want to know what that file is and why it came with all games folders, and is it harmful or not

Thanks in advance!
 
Hi everyone!

I took some games data from a friend, they are some .iso files which can be unpacked to games

But I found a file with .bat (batch) extension in each folder of these games folder and named with the same name of the folder

I opened one and a command prompt has started to copy files in the same drive which the file is located, then I noticed that each folder of the drive has a file named with the folder name and with .bat (batch) extension

Then I searched about any files with .bat (batch) extensions and I deleted all of them, and now everything is ok

When I used notepad edit to view the content of the .bat file, that is the content:


set h=For

%h% /R "D:\" /D %%a in (*) do copy %0 "%%~fa\%%~nxa.bat"



I want to know what that file is and why it came with all games folders, and is it harmful or not

Thanks in advance!
SET sets a variable for this bat. So set h=For means that anyplace there is an %h% it is substituted by For.
Since that only happens once and at the start of the following line I would say this is something your friend did to learn scripting or he tried to do something and this is the result.
/R means items on the root of the drive
"d:\" is the D drive and since not 100% of all systems out there have a D: drive this is another indication for your friend having done this.
/D stands for folders.
So until now we have 'take a list of all folders in the root of drive D:\ '

%%a is for the current item of the loop
in (*) would determine all the items that would be in the loop, the * being a wildcard it would mean anything you can find.

Do copy %0 means copy the current %%a, so the current folder name, and copy it with the name "%%~fa\%%~nxa.bat"
%%fa meaning full path name
\ being the thing that separates folders from files
and
%%~nxa means take only the file name

So the bat makes a list of all folders in the root and copies the folder name into the folder as foldername.bat.

Since it's completely useless it's only good for learning so that's another indication of your friend just trying to learn.

 
  • Like
Reactions: Ralston18