gpt4 book ai didi

windows - 批量重命名文件夹结构

转载 作者:可可西里 更新时间:2023-11-01 11:31:45 27 4
gpt4 key购买 nike

)

为了使公司(我工作的地方)更有条理、更高效地运作,我们为新项目创建了一个经过批准的文件夹结构。

New projectsLive projects 驻留在文件服务器上并且彼此处于同一级别。 (上线的项目都是通过策划完成的,新的项目有时只能到策划为止)

每次我们开始一个新项目时,项目文件夹结构都需要精心创建,因此我制作了一个 Windows 批处理文件来创建它。您可以在这里找到它:http://pastebin.com/mnSu5vnk这部分效果很好!

文件夹结构是:

F:\New Job\Project Name\Project Correspondence

F:\New Job\Project Name\Project Directory

F:\New Job\Project Name\Project Drawings

F:\New Job\Project Name\Project Images

F:\New Job\Project Name\Project Correspondence\Arboriculturalist

F:\New Job\Project Name\Project Correspondence\CGI

F:\New Job\Project Name\Project Correspondence\Client

F:\New Job\Project Name\Project Correspondence\Measured Survey

F:\New Job\Project Name\Project Correspondence\Planning

F:\New Job\Project Name\Project Correspondence\Post Planning Folders (Drop in as and when)

F:\New Job\Project Name\Project Correspondence\Client\Appointments

F:\New Job\Project Name\Project Correspondence\Client\Fees

F:\New Job\Project Name\Project Correspondence\Planning\LA Planning

F:\New Job\Project Name\Project Correspondence\Planning\Planning Consultants

F:\New Job\Project Name\Project Correspondence\Planning\LA Planning\Planning Application

F:\New Job\Project Name\Project Correspondence\Planning\LA Planning\Pre Application

F:\New Job\Project Name\Project Correspondence\Post Planning Folders (Drop in as and when)\Arboriculturalist

F:\New Job\Project Name\Project Correspondence\Post Planning Folders (Drop in as and when)\Contract Administrator

F:\New Job\Project Name\Project Correspondence\Post Planning Folders (Drop in as and when)\Contractor

F:\New Job\Project Name\Project Correspondence\Post Planning Folders (Drop in as and when)\LA Building Control

F:\New Job\Project Name\Project Correspondence\Post Planning Folders (Drop in as and when)\M&E Consultants

F:\New Job\Project Name\Project Correspondence\Post Planning Folders (Drop in as and when)\Structural Engineer

F:\New Job\Project Name\Project Correspondence\Post Planning Folders (Drop in as and when)\Tender, Specification

F:\New Job\Project Name\Project Drawings\CD Series (Construction Details)

F:\New Job\Project Name\Project Drawings\Drawing Register

F:\New Job\Project Name\Project Drawings\EW Series (External Works)

F:\New Job\Project Name\Project Drawings\Outgoing Drawings

F:\New Job\Project Name\Project Drawings\P Series (Planning)

F:\New Job\Project Name\Project Drawings\RL Drawings (Room Layouts)

F:\New Job\Project Name\Project Drawings\SK Series (Sketch Design)

F:\New Job\Project Name\Project Drawings\X Series (Existing)

F:\New Job\Project Name\Project Drawings\Outgoing Drawings\DWG FILES

F:\New Job\Project Name\Project Drawings\Outgoing Drawings\PDF FILES

问题是一些新项目从未进入“实时”状态;但是,那些确实获得了项目编号的项目因此需要在每个子文件夹前加上项目编号。在每个子文件夹前加上项目编号的原因是由于“”不小心将它们拖/复制/移动到另一个项目中,这会使事情变得非常困惑!

另一个问题是一些“新项目”已经存在了一段时间(1 年以上)并且没有文件夹结构,因此我需要制作一个批处理文件来检测“新项目”是否存在是否具有批准的文件夹结构,并根据需要重命名。

这就是我目前所拥有的,但我相信我的方法是完全错误的。

@Echo off
:start
set /P ProjNo=Project Number:
set /P ProjAd=Project Address:
cls

Echo New Project Name?
Echo Project Number=%ProjNo%
Echo Project Address= %ProjAd%

set /p proceed=Is this correct? [Y/N]
if /i {%proceed%}=={y} (goto :yes)
if /i {%proceed%}=={yes} (goto :yes)
if /i {%proceed%}=={n} (goto :no)
if /i {%proceed%}=={no} (goto :no)

:no
cls
goto :start

:yes
set "currentpath=%cd%"
set "projfolder=%ProjNo%-%ProjAd%"

:: check if 000-Project Address doesn't exists
echo Does the Project folder exist %currentpath%\%ProjNo%-%ProjAd%?
If NOT exist "%currentpath%\%ProjNo%-%ProjAd%\"
(
echo the folder does NOT exist
::check if project folder name doesn't existing
if NOT exist "%currentpath%\%ProjAd%\"
(
:: rename the folder to 000-Project Address
echo Renaming Project Folder
ren "%ProjAd%" "%ProjNo%-%ProjAd%"

call:TopLevel
)
::if project address name DOES exist
else
(
::enter the folder and check the structure.
echo Project Folder doesn't need renaming
call:TopLevel
)
)
::-----------------------------------------------------
:: if "000-Project Address" DOES exist
::-----------------------------------------------------

else
(
Echo There is no need to run this script!
goto:eof
)
)
::-----------------------------------------------------
:: Recurse Top level
::
:: If all the "Recommended" directory names exist
:: rename all sub-directories too!
:: Else create them all!
::-----------------------------------------------------
:TopLevel

CD projfolder
::check if there's a project correspondence
IF exist "Project Correspondence"
(
ren "Project Correspondence" "%ProjNo%-Project Correspondence"
::rename the child folders
cd "%ProjNo%-Project Correspondence"
for /f "tokens=*" %G in ('dir /b /a:d "*"') do ren "%G" "%ProjNo%-%G"
cd "%ProjNo%-client"
for /f "tokens=*" %G in ('dir /b /a:d "*"') do ren "%G" "%ProjNo%-%G"
cd ..\planning\


)
else
(
mkdir "%ProjNo%-Project Correspondence"
callto:
::function makeProjCorrespondence
call:makeProjCorrespondence %ProjNo%
)
:: check if there's a project directory
IF exist "Project Directory"
(
ren "Project Directory" "%ProjNo%-Project Directory"
)
else
(
mkdir "%ProjNo%-Project Directory"
)
if exist "Project Drawings"
(
ren "Project Drawings" "%ProjNo%-Project Drawings"
::go to project drawings function
)
goto:eof

:makeProjCorrespondence
cd "%ProjNo%-Project Correspondence"
mkdir "%ProjNo%-Planning"
mkdir "%ProjNo%-Arboriculturalist"
mkdir "%ProjNo%-CGI"
mkdir "%ProjNo%-Client"
mkdir "%ProjNo%-Measured Survey"
mkdir "%ProjNo%-Post Planning Folders (Drop in as and when)"

::Make folders under Planning
cd "%ProjNo%-Planning"
mkdir "%ProjNo%-LA Planning"
mkdir "%ProjNo%-Planning Consultants"
cd "..\"

::Make folders in Client
cd "%ProjNo%-Client"
mkdir "%ProjNo%-Appointments"
mkdir "%ProjNo%-Fees"
cd "..\"

::make Post Planning folders
cd "%ProjNo%-Post Planning Folders (Drop in as and when)"
mkdir "%ProjNo%-Arboriculturalist"
mkdir "%ProjNo%-Contract Administrator"
mkdir "%ProjNo%-Contractor"
mkdir "%ProjNo%-LA Building Control"
mkdir "%ProjNo%-M&E Consultants"
mkdir "%ProjNo%-Structural Engineer"
mkdir "%ProjNo%-Tender, Specification"
cd "..\..\"
goto:TopLevel

非常感谢提示和建议!

非常感谢

最佳答案

这被设计为递归通过名为 c:\database\project daredevil 的文件夹树,并将 001- 添加到树中每个文件夹名称的前面。

@echo off
set "num=001-"
for /d /r "c:\database\project daredevil" %%a in (*) do ren "%%a" "%num%%%~nxa"

此代码将报告丢失了哪些文件夹,并将创建丢失的文件夹。
您可以使 num 等于无以创建一组新的文件夹。

编辑2:

@echo off
set "num=001-"
set "project=c:\database\project daredevil"

for %%a in (
"Project Correspondence"
"Project Directory"
"Project Drawings"
"Project Images"
"Project Correspondence\%num%Arboriculturalist"
"Project Correspondence\%num%CGI"
"Project Correspondence\%num%Client"
"Project Correspondence\%num%Measured Survey"
"Project Correspondence\%num%Planning"
"Project Correspondence\%num%Post Planning Folders (Drop in as and when)"
"Project Correspondence\%num%Client\%num%Appointments"
"Project Correspondence\%num%Client\%num%Fees"
"Project Correspondence\%num%Planning\%num%LA Planning"
"Project Correspondence\%num%Planning\%num%Planning Consultants"
"Project Correspondence\%num%Planning\%num%LA Planning\%num%Planning Application"
"Project Correspondence\%num%Planning\%num%LA Planning\%num%Pre Application"
"Project Correspondence\%num%Post Planning Folders (Drop in as and when)\%num%Arboriculturalist"
"Project Correspondence\%num%Post Planning Folders (Drop in as and when)\%num%Contract Administrator"
"Project Correspondence\%num%Post Planning Folders (Drop in as and when)\%num%Contractor"
"Project Correspondence\%num%Post Planning Folders (Drop in as and when)\%num%LA Building Control"
"Project Correspondence\%num%Post Planning Folders (Drop in as and when)\%num%M&E Consultants"
"Project Correspondence\%num%Post Planning Folders (Drop in as and when)\%num%Structural Engineer"
"Project Correspondence\%num%Post Planning Folders (Drop in as and when)\%num%Tender, Specification"
"Project Drawings\%num%CD Series (Construction Details)"
"Project Drawings\%num%Drawing Register"
"Project Drawings\%num%EW Series (External Works)"
"Project Drawings\%num%Outgoing Drawings"
"Project Drawings\%num%P Series (Planning)"
"Project Drawings\%num%RL Drawings (Room Layouts)"
"Project Drawings\%num%SK Series (Sketch Design)"
"Project Drawings\%num%X Series (Existing)"
"Project Drawings\%num%Outgoing Drawings\%num%DWG FILES"
"Project Drawings\%num%Outgoing Drawings\%num%PDF FILES"
) do (
if not exist "%project%\%num%%%~a\" (
echo "%project%\%num%%%~a\" is missing
md "%project%\%num%%%~a\"
)
)
pause

关于windows - 批量重命名文件夹结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18987109/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com