问题描述:

I have made a batch script to move and rename a file by dragging and dropping a file onto the script. This will assume the source of the file is unknown, but the target directory is.

My solution was to CD to the target directory, reverse the source file name, use the for command with backslash as a delim to have the file name, then reverse it again then finally rename it.

Just wondering if there was an easier solution.

@echo off

echo %1

set newSong=%1

cd "C:\Riot Games\League of Legends\RADS\projects\lol_air_client\releases\0.0.0.230\deploy\assets\sounds\ambient"

if not exist LoginScreenIntro.mp3.bak rename LoginScreenIntro.mp3 LoginScreenIntro.mp3.bak

del LoginScreenIntro.mp3

copy %newSong% "%CD%"

Call :ReverseString %newSong%

Set ReverseString.Result="%ReverseString.Result%"

for /f "tokens=1 delims=\" %%a in (%ReverseString.Result%) do set reversesong=%%a

Call :ReverseString "%reversesong%"

set newSong=%ReverseString.Result%

rename "%newSong%" LoginScreenIntro.mp3

pause

:ReverseString

Set ReverseString.TempVar=%~1

Set ReverseString.Result=

:ReverseString.Loop

Set ReverseString.Result=%ReverseString.TempVar:~0,1%%ReverseString.Result%

Set ReverseString.TempVar=%ReverseString.TempVar:~1,999%

if not "%ReverseString.TempVar%"=="" goto ReverseString.Loop

Goto :Eof

网友答案:

How about this?

ren %1 NewName.ext
move %~dp1\NewName.ext NewDir
网友答案:

Heh, all I needed was

set newsong=%~n1%~x1
相关阅读:
Top