폴더를 일괄 생성 하시겠습니까?


1

일괄 처리 폴더를 만들고 하위 폴더를 만드는 방법을 찾고 있습니다.

나는 뭔가를보고있다.

c:\users\user\desktop\sample\1
c:\users\user\desktop\sample\2

기타

어떤 아이디어?

그렇게하려면 .cmd / PowerShell 메서드를 사용하는 것이 좋습니다.

터미널을 통해 그렇게 할 수있는 방법이 있다면, USB를 통해 Linux 라이브 디스크로 부팅하여 아이디어 / 솔루션을 시도해 볼 수 있습니다.


PowerShell을 선호한다면 왜 배치에 대한 참조가 더 많습니까? Powershell 스크립트는 사용자가 선호하는 스크립트라면 쉽게 작성할 수 있습니다.
Austin T French

답변:


3

다음과 같이 md 명령을 사용할 수 있습니다.

for /l %a in (1,1,2) do md "c:\users\user\desktop\sample\folder %a"

이 예제에서는 두 폴더를 만듭니다.


또한 이름에 공백이있는 디렉토리를 만들어야합니다. 나는 c : \ users \ user \ desktop \ folder 또는 c : \ users \ user \ folder 1과 같은 것에 대해 어떻게 갈 것인가?
Chris0089

@ Chris0089 요청에 따라 수정했습니다.
TwirlMandarin

@AlexanderCeed FOR %F IN ("folder one","folder two") DO (md %USERPROFILE%\Desktop\%F)
STTR

1

이 PowerShell 스크립트는 숫자 순차적 이름을 가진 디렉터리를 만듭니다.

function New-SequentialDirectory
{
Param
(
    [string] $Path = (Get-Location -PSProvider FileSystem).Path,
    [UInt32] $StartAt = 1,
    [UInt32] $EndAt
)

$Path = (Get-Location -PSProvider FileSystem).Path
if (-not (Test-Path -PathType Container $Path))
{
    $exception = New-Object System.IO.DirectoryNotFoundException "The specified directory does not exist: $Path"
    throw $exception
}

Write-Debug "Path: $Path"
foreach($number in $StartAt..$EndAt)
{
 $itemPath = Join-Path -Path $Path -ChildPath $number
 New-Item -Path $itemPath -ItemType Directory   
}
<#
.SYNOPSIS
Creates a series of directories with numerically sequential names.

.PARAMETER Path
The path at which the sequence should be created. This must be an existing directory.
.PARAMETER StartAt
The number at which the sequence should start. This value must be positive and may be greater than the value of the EndAt parameter.
.PARAMETER EndAt
The number at which the sequence should end. This value must be positive and may be less than the value of the StartAt parameter.

.EXAMPLE
New-SequentialDirectory -StartAt 1 -EndAt 10

 Directory: C:\Users\TestUser\Desktop\test


Mode                LastWriteTime     Length Name                                                                                                                                             
----                -------------     ------ ----                                                                                                                                             
d----        5/10/2014  2:18 p.m.            1                                                                                                                                                
d----        5/10/2014  2:18 p.m.            2                                                                                                                                                
d----        5/10/2014  2:18 p.m.            3                                                                                                                                                
d----        5/10/2014  2:18 p.m.            4                                                                                                                                                
d----        5/10/2014  2:18 p.m.            5                                                                                                                                                
d----        5/10/2014  2:18 p.m.            6                                                                                                                                                
d----        5/10/2014  2:18 p.m.            7                                                                                                                                                
d----        5/10/2014  2:18 p.m.            8                                                                                                                                                
d----        5/10/2014  2:18 p.m.            9                                                                                                                                                
d----        5/10/2014  2:18 p.m.            10                                                                                                                                               

This example shows the creation of a sequence of ten folders in the current directory.

.EXAMPLE

New-SequentialDirectory -StartAt 10 -EndAt 1


Directory: C:\Users\TestUser\Desktop\temp


Mode                LastWriteTime     Length Name                                                                                                                                             
----                -------------     ------ ----                                                                                                                                             
d----        5/10/2014  2:57 p.m.            10                                                                                                                                               
d----        5/10/2014  2:57 p.m.            9                                                                                                                                                
d----        5/10/2014  2:57 p.m.            8                                                                                                                                                
d----        5/10/2014  2:57 p.m.            7                                                                                                                                                
d----        5/10/2014  2:57 p.m.            6                                                                                                                                                
d----        5/10/2014  2:57 p.m.            5                                                                                                                                                
d----        5/10/2014  2:57 p.m.            4                                                                                                                                                
d----        5/10/2014  2:57 p.m.            3                                                                                                                                                
d----        5/10/2014  2:57 p.m.            2                                                                                                                                                
d----        5/10/2014  2:57 p.m.            1                                                                                                                                                

This example shows that the EndAt parameter can be less than the StartAt parameter.
#>   
}

아래 코드를 사용하려면 다음을 수행해야합니다.

  1. 위의 코드를 이름이 지정된 파일로 복사하십시오. New-SequentialDirectory.ps1
  2. 이 명령으로 세션에 함수를 추가하십시오. 1
    . <path-to-New-Sequential-Directory.ps1>
  3. 함수를 호출하십시오. 이 작업을 수행하는 방법에 대한 몇 가지 예가 다음 명령을 통해 사용할 수있는 명령에 대한 도움말에 나와 있습니다. Get-Help New-SequentialDirectory -Examples 명령을 사용하십시오.

1 기본적으로 PowerShell은 파일에서 스크립트를 실행할 수 없으므로 2 단계가 실패 할 수 있습니다. 이 문제를 해결하려면 실행 정책을 약간 덜 제한적인 것으로 변경해야합니다. 이에 대한 더 자세한 정보는 Get-Help about_Execution_Policies

당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.