Rename Multiple file on using .cmd or .bat [closed] - windows

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have directory which contain no. of file like this
abac_273#jj.txt ,
hhh.78448#kkpp.txt ,
dgfhf#ytyt#llltyui.txt
I need to write batch script where I need to rename those file like this
jj.txt , kkpp.txt, llltyui.txt
In simple words, I need to find out # from end and return string after # as output.
Can you please help me out to solve this

for /f "tokens=1*delims=#" %%a in ('dir /b /a-d "*#*"') do echo(ren "%%a#%%b" "%%b"
should provide what you want - reduce each %% to % if you execute this from the prompt instead of as a batch line.
If it works correctly for you, change the echo(ren to ren to actually do the change - this code will simply report the proposed change to the screen.

Related

Script to list extensions [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I want to write a windows batch script that lists all extensions in a directory, recursively.
The desired behaviour is this:
You start the bat file in directory "a" which contains the following files: b.txt, c.png, d.txt, e.jpeg, f.jpg.
The script should output the following:
txt
png
jpeg
jpg
I would like the each extension to be in a new line, alphabetic ordering is not necessary.
The method you linked to is probably overkill for what you want.
Do a for /r loop to get all files recursively and set a variable named the same as the extension (the value isn't important, we need only the variable to be defined)
Then do a for /f loop to list the variables (with set . - all of them start with a dot conveniently because the %%~x modifier gets the extension with the dot (.txt)). Then just sort them alphabetically, if needed:
#echo off & setlocal
for /r %%a in (*) do set "%%~xa=X" 2>nul
for /f "delims==" %%a in ('set .') do echo %%a
(edit: removed the sort, because set . already sorts alphabetically - thank you #LotPings for the hint)

Removing certain characters of a certain file [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I'm trying to remove certain characters from multiple files which share the same extension. An example would be: filename = 01songname.mp3 to songname.mp3, but doing that command to all the mp3 files in the directory, not renaming to one name but removing the numbering.
Based on your existing examples this may work for you.
#echo off
FOR %%M IN (*.mp3) DO (
FOR /F "tokens=* delims=0123456789" %%G IN ("%%~M") DO ECHO RENAME "%%~M" "%%~G"
)
pause
Remove the word ECHO before the word RENAME if you feel the output on the screen looks correct.

How do you find the last modified folder in a directory with command prompt? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
In the end, I want to copy the last modified folder in a directory. In order to do this, I need to pass in the name of the last modified folder to xcopy.
How do you find the last modified folder, not file, in a directory with command prompt? I have found many scripts that will find the last modified file, but I cannot seem to find a command that will find the last modified folder.
Any help would be appreciated.
#echo off
for /f "delims=" %%a in (' dir /ad /od /b ') do set "folder=%%a"

Windows command prompt (Dos) copies all the files that start with the specified file name [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
In Dos if you type
copy c:\a.txt
it will copy a.txt* (a.txt1, a.txtb, etc)
how can I just copy a.txt?
Your question is not correct - copy c:\a.txt will only copy the single file to the current directory. It will ignore the other files like a.txt1 and a.txtb.
You must have tried copy c:\*.txt - that will copy all forms because the pattern matching searches both long and short (8.3) names.
You can eliminate the problem by using FINDSTR:
for /f "eol=: delims=" %F in ('dir /b /a-d c:\*.txt^|findstr /eli ".txt"') do #copy "c:\%F"

Batch Read Text From a Child Directory [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
i plan on releasing a tool to back up gamesaves for a certian game but i am having problems with batch telling it to get its text. i get returned with Wput but i want it to say ftp://SPECIFIED_USER_IN TEXT FILE:
Not quite sure if this is possible but i looked around(UPLOAD represents wput.exe) UPLOAD isnt the issue. the issue is telling it where to go.
#echo off
set /p user=./server_information/user.txt
set /p pass=./server_information/pass.txt
set /p host=./server_information/host.txt
ser world=worldname.txt
cd UploadingHandler
upload ftp://%user%:%pass#%host%:21/%world% %world%
pause
any help? Thanks.
edit:
if you need better understanding here is a treemap:
ROOT
UploadingHandler
epload.exe
-
Server_Information
Host.txt
user.txt
pass.txt
-
The SET /P command reads input from the console unless you redirect the input to be from another device, e.g. from a file. This is done using the < symbol:
SET /P variable=prompt text < filename
The prompt text part is optional. So, to give you an example using one of your files:
set /p user=<./server_information/user.txt
Not sure if this is what you wanted either, but to read a file using batch you could do this:
for %%a in (myfile.txt) do print %%a
or:
for %%a in (myfile.txt) do :adef
:adef
print %%a

Resources