Page 1 of 1

Command-Line usage on only ONE specific file

PostPosted: Sat Jan 25, 2020 3:26 am
by dnngll
Good morning,

I just stumbled across this beautiful piece of software and am looking forward to using it in the future. I have one question though:

Is there a way to rename only one specific file? The reason being: I often have to rename files to "MODIFIED DATE - ORIGINAL FILENAME". This is usually done on a "by-file-base". So I created a batch (Win10x64pro) file, in which I only have to drag in the file which has to be renamed:

Code: Select all
@echo off

:start
cls
set /p input="Drop File... -> "
if not exist %input% goto endFAILURE
echo.
echo ---



echo.
rem -----
rem https://stackoverflow.com/a/37449850
for %%A in (%input%) do (set defilepathname=%%~fA)
for %%A in (%input%) do (set defilepath=%%~dA%%~pA)
for %%A in (%input%) do (set defilename=%%~nA%%~xA)
rem -----
echo Dropped:        %input%
echo deFilePathName:  %defilepathname%
echo deFilePath:      %defilepath%
echo deFileName:      %defilename%
echo.
echo ---



B:\ren\BRC64.exe /DIR:"%defilepath%" /INCLH /INCLR /PATTERN:"%defilename%" /APPENDDATE:M:P:::10:%%Y.%%m.%%d", "%%H.%%M.%%S" ("%%a") - " /TIDYDS /TRIM /NODUP
goto end



:endFAILURE
echo.
echo.
echo FAILURE!
echo.
echo.
echo Press any key to exit . . .
echo.
pause > nul
goto end


:end
echo off | clip
timeout -t 3

However, if the filenames are similar the program wants to rename all of them. My testfiles are:

    test
    test.txt
    test test.txt
    1000.01.25, 02.39 - test test.txt

The batch works fine for the first 2, the second 2 don't work. Every filename containing spaces is giving me trouble : (
Drop File... -> "B:\- ! private\Desktop\test test.txt"

---

Dropped: "B:\- ! private\Desktop\test test.txt"
deFilePathName: B:\- ! private\Desktop\test test.txt
deFilePath: B:\- ! private\Desktop\
deFileName: test test.txt

---


Processing Folder B:\- ! private\Desktop\
Filename test would be renamed to 2020.01.25, 02.32.39 (Sat) - test
Filename test.txt would be renamed to 2020.01.25, 02.32.39 (Sat) - test.txt

Waiting for 2 seconds, press a key to continue ...

Anyone having that problem as well?

Kind regards
Dennis

Re: Command-Line usage on only ONE specific file

PostPosted: Sat Jan 25, 2020 3:31 am
by dnngll
* the colors in my quote were wrong, they should have been like so:
Drop File... -> "B:\- ! private\Desktop\test test.txt"

---

Dropped: "B:\- ! private\Desktop\test test.txt"
deFilePathName: B:\- ! private\Desktop\test test.txt
deFilePath: B:\- ! private\Desktop\
deFileName: test test.txt

---


Processing Folder B:\- ! private\Desktop\
Filename test would be renamed to 2020.01.25, 02.32.39 (Sat) - test
Filename test.txt would be renamed to 2020.01.25, 02.32.39 (Sat) - test.txt


Waiting for 2 seconds, press a key to continue ...


:roll:

Re: Command-Line usage on only ONE specific file

PostPosted: Sat Jan 25, 2020 3:58 pm
by bru
Unfortunately /Pattern uses space (even quoted ones) as a filespec separator.
As a bulk renamer, I guess renaming only-1-file wasnt given much prioriority.
Personally, I'd prefer /Pattern:file1 /Pattern:file2 over /Pattern:"file1 file2".

After the FOR command, you could use: SET defilename=%defilename: =?%
That converts spaces into ? to achieve something like /Pattern:"test?test.txt"
Its no 1-file-guarantee, but definitely better than adding a filespec for each space.