Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
JimmyTheDos
- Posts: 3
- Joined: 20 May 2018 20:28
#1
Post
by JimmyTheDos » 20 May 2018 21:24
Hi guys,
I am wondering if there is a way to:
Rename Folders that are empty or only contain Folders with "name + (Empty)" etc
So that if I am browsing through directories I can tell quickly if they're useful or dead legs. (I want to keep the folder structure as it is, to add things into the correct folders as projects develop.)
eg:
- E:\AS\A\A
E:\AS\A\A\C
E:\AS\A\B
E:\AS\A\B\Work.doc
E:\AS\B\A
E:\AS\B\B
E:\AS\B\B\C
Would rename to:
- E:\AS\A\A (Empty)
E:\AS\A\A (Empty)\C (Empty)
E:\AS\A\B
E:\AS\A\B\Work.doc
E:\AS\B (Empty)\A (Empty)
E:\AS\B (Empty)\B (Empty)
E:\AS\B (Empty)\B (Empty)\C (Empty)
My idea it is to use something like:
Code: Select all
@echo off
setlocal enabledelayedexpansion
cls
:input
set /p "input=1. Enter Source directory: "
if not exist "%input%" echo Invalid source: "%input%" enter valid path && goto :input
for /f "delims=" %%I in (' dir /s /b /o:n ') do (
set file="%%~I"
for %%J in ??? do set "file=???"
???
)
Where "???" I am not sure what to use.
-
penpen
- Expert
- Posts: 2009
- Joined: 23 Jun 2013 06:15
- Location: Germany
#2
Post
by penpen » 21 May 2018 19:24
I'm unsure how you might mean this "(Empty)" part:
If you only allow the default space character (U+0020), then (if i remember right) this task is impossible to solve, because that space isn't allowed to be the last character in a filename without extension.
But, if it suffices, you could use the non breaking space:
Code: Select all
@echo off
:: prepare codepages
set /A "utf7Cp=65000, utf8Cp=65001"
set "cp="
for /f "delims=." %%a in ('2^>nul chcp') do for %%b in (%%a) do set "cp=%%b"
if not defined cp for /f "tokens=2" %%a in ('2^>nul chcp') do set "cp=%%~a"
:: create file ['A', NBSP, 'A']; NBS := non breaking space
>nul chcp %utf8Cp%
>"dummy.txt" cmd /a /c^<nul set /p "=A+AKA-A"
>nul chcp %utf7Cp%
set "nbs="
<"dummy.txt" set /p "nbs="
set "nbs=%nbs:~1,1%"
:: rename "dummy.txt"
for %%a in ("dummy.txt") do ren "%%~a" "%%~a%nbs%."
for %%a in ("dummy.*") do echo("%%~a"
:: restore codepage
>nul chcp %cp%
goto :eof
penpen