Windows 경로 대신 DOS 경로 가져 오기
DOS 창에서 내가있는 디렉토리의 전체 DOS 이름 / 짧은 이름을 어떻게 얻을 수 있습니까?
예를 들어, 디렉토리에있는 경우 C:\Program Files\Java\jdk1.6.0_22
짧은 이름을 표시하고 싶습니다 C:\PROGRA~1\Java\JDK16~1.0_2
.
실행 dir /x
하면 현재 디렉토리에있는 파일 / 디렉토리의 짧은 이름이 제공된다는 것을 알고 있지만 현재 디렉토리의 전체 경로를 짧은 이름 형식으로 표시하는 방법을 찾을 수 없었습니다. 나는 dir /x
각각 에서 실행되는 루트의 경로, 디렉토리 별 경로를 통해 작업해야합니다 .
이 작업을 수행하는 더 쉬운 방법이 있다고 확신합니까?
for %I in (.) do echo %~sI
더 간단한 방법이 있습니까?
CMD 창에 다음을 입력 할 수도 있습니다.
dir <ParentDirectory> /X
어디 <ParentDirectory>
항목을 포함하는 디렉토리의 전체 경로로 대체 당신의 이름을 싶습니다.
출력은 Timbo의 대답 만큼 간단하지는 않지만 지정된 디렉토리의 모든 항목을 실제 이름과 짧은 이름 (다른 경우)으로 나열합니다.
사용하는 경우를 파일 / 폴더의 전체 경로로 for %I in (.) do echo %~sI
대체하여 .
해당 파일 / 폴더의 짧은 이름을 가져올 수 있습니다 (그렇지 않으면 현재 폴더의 짧은 이름이 반환 됨).
Windows 7 x64에서 테스트되었습니다.
Windows 배치 스크립트에서 %~s1
경로 매개 변수를 짧은 이름으로 확장합니다 . 이 배치 파일을 만듭니다.
@ECHO OFF
echo %~s1
나는 내 shortNamePath.cmd
전화를 다음과 같이 부른다.
c:\>shortNamePath "c:\Program Files (x86)\Android\android-sdk"
c:\PROGRA~2\Android\ANDROI~1
편집 : 매개 변수가 제공되지 않은 경우 현재 디렉토리를 사용하는 버전은 다음과 같습니다.
@ECHO OFF
if '%1'=='' (%0 .) else echo %~s1
매개 변수없이 호출 :
C:\Program Files (x86)\Android\android-sdk>shortNamePath
C:\PROGRA~2\Android\ANDROI~1
프로그래머가되어이 10 분짜리 Winform 프로젝트를 만들었습니다. 나에게 유용했습니다. 이 앱을 파일 탐색기의 상황에 맞는 메뉴로 만들면 더 많은 클릭을 줄일 수 있습니다.
Form1.cs :
using System;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
namespace ToShortPath
{
public partial class Form1 : Form
{
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern int GetShortPathName(
[MarshalAs(UnmanagedType.LPTStr)]
string path,
[MarshalAs(UnmanagedType.LPTStr)]
StringBuilder shortPath,
int shortPathLength
);
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
// Show the dialog and get result.
var openFileDialog1 = new OpenFileDialog();
DialogResult result = openFileDialog1.ShowDialog();
if (result == DialogResult.OK) // Test result.
{
textBox1.Text = openFileDialog1.FileName;
}
}
private void button2_Click(object sender, EventArgs e)
{
var openFileDialog1 = new FolderBrowserDialog();
DialogResult result = openFileDialog1.ShowDialog();
if (result == DialogResult.OK) // Test result.
{
textBox1.Text = openFileDialog1.SelectedPath;
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
StringBuilder shortPath = new StringBuilder(65000);
GetShortPathName(textBox1.Text, shortPath, shortPath.Capacity);
textBox2.Text = shortPath.ToString();
}
}
}
Form1.Designer.cs :
namespace ToShortPath
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(69, 13);
this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(516, 53);
this.textBox1.TabIndex = 0;
this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(69, 72);
this.textBox2.Multiline = true;
this.textBox2.Name = "textBox2";
this.textBox2.ReadOnly = true;
this.textBox2.Size = new System.Drawing.Size(516, 53);
this.textBox2.TabIndex = 1;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(7, 35);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(56, 13);
this.label1.TabIndex = 2;
this.label1.Text = "Long Path";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(7, 95);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(57, 13);
this.label2.TabIndex = 3;
this.label2.Text = "Short Path";
//
// button1
//
this.button1.AutoSize = true;
this.button1.Location = new System.Drawing.Point(591, 13);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(40, 53);
this.button1.TabIndex = 4;
this.button1.Text = "File";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.AutoSize = true;
this.button2.Location = new System.Drawing.Point(637, 12);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(46, 53);
this.button2.TabIndex = 5;
this.button2.Text = "Folder";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(687, 135);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox1);
this.Name = "Form1";
this.Text = "Short Path";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
}
}
실행 cmd.exe
하고 다음을 수행하십시오.
> cd "long path name"
> command
그러면 command.com이 나타나 짧은 경로 만 표시합니다.
Kimbo의 답변은 일반 파일에 적합합니다.
for %I in (.) do echo %~sI
HardLinks의 MsDos 파일 이름
로 생성 된 하드 링크 mklink /H <link> <target>
에는 MsDos 짧은 파일 이름이 없습니다.
dir /X
닉네임 누락을 발견 한 경우 다음을 예상해야합니다.
d:\personal\photos-tofix\2013-proposed1-bad>dir /X
Volume in drive D has no label.
Volume Serial Number is 7C7E-04BA
Directory of d:\personal\photos-tofix\2013-proposed1-bad
03/02/2015 15:15 <DIR> .
03/02/2015 15:15 <DIR> ..
22/12/2013 12:10 1,948,654 2013-1~1.JPG 2013-12-22--12-10-42------Bulevardul-Petrochimiștilor.jpg
22/12/2013 12:10 1,899,739 2013-12-22--12-10-52------Bulevardul Petrochimiștilor.jpg
일반 파일
이 경우
> for %I in ("2013-12-22--12-10-42------Bulevardul-Petrochimiștilor.jpg") do echo %~sI
나는 내가 기대했던 것을 얻었다
d:\personal\PH124E~1\2013-P~3\2013-1~1.JPG
하드 링크 파일
이 경우
> for %I in ("2013-12-22--12-10-52------Bulevardul-Petrochimiștilor.jpg") do echo %~sI
일반 MsDos 경로가 있지만 일반 파일 이름이 있습니다.
d:\personal\PH124E~1\2013-P~3\2013-12-22--12-10-52------Bulevardul-Petrochimiștilor.jpg`
보다 직접적인 대답은 버그를 수정하는 것입니다.
% SPARK_HOME % \ bin \ spark-class2.cmd; 54 행
Broken: set RUNNER="%JAVA_HOME%\bin\java"
Windows Style: set "RUNNER=%JAVA_HOME%\bin\java"
그렇지 않으면 RUNNER는 따옴표로 "%RUNNER%" -Xmx128m ...
끝나고 명령 은 큰 따옴표로 끝납니다. 그 결과 프로그램과 파일이 별도의 매개 변수로 취급됩니다.
이 답변 과 유사 하지만 서브 루틴을 사용합니다.
@echo off
CLS
:: my code goes here
set "my_variable=C:\Program Files (x86)\Microsoft Office"
echo %my_variable%
call :_sub_Short_Path "%my_variable%"
set "my_variable=%_s_Short_Path%"
echo %my_variable%
:: rest of my code goes here
goto EOF
:_sub_Short_Path
set _s_Short_Path=%~s1
EXIT /b
:EOF
$fso = New-Object -com scripting.filesystemobject
$fso.GetFolder('c:\Program Files (x86)').ShortName()
PROGRA~2
이 링크를 사용하면 제공하는 모든 경로를 https://pathconverter-pp.azurewebsites.net 형식으로 자동 변환합니다.
참고 URL : https://stackoverflow.com/questions/4051088/get-dos-path-instead-of-windows-path
'Programming' 카테고리의 다른 글
프로그래밍 방식으로 HTML SELECT에 드롭 다운을 지시하는 방법 (예 : 마우스 오버로 인해) (0) | 2020.08.27 |
---|---|
유효한 국제 전화 번호와 일치하는 정규 표현식은 무엇입니까? (0) | 2020.08.27 |
ReferentialConstraint의 종속 속성은 저장소 생성 열에 매핑됩니다. (0) | 2020.08.27 |
전역 기능과 장치 기능의 차이점 (0) | 2020.08.27 |
Java에서 리플렉션을 통해 개인 필드에 액세스 할 수 있습니까? (0) | 2020.08.27 |