【问题标题】:USB Flash drive batch file letter assignmentUSB 闪存驱动器批处理文件字母分配
【发布时间】:2013-11-19 06:39:35
【问题描述】:

我想知道是否有人可以提供帮助。 我编写了一个在 USB 闪存驱动器上加载 .cvs 的 java 程序。该程序可能会在多个不同的 Windows 笔记本电脑上使用,但该程序使用固定文件位置,即:F 驱动器。

我想知道是否有办法在插入闪存驱动器时将字母分配固定为驱动器 :T 之类的东西,这样无论驱动器插入哪个端口或计算机,java 都可以自动读取它程序。我想在 USB 上的批处理文件中执行此操作,以便用户不必手动设置计算机来更改闪存驱动器。由于一些程序用户年龄很大,即使提供了分步说明,也不太可能做到这一点。

我以前从未写过批处理文件,所以任何帮助都会很棒

亲切的问候

【问题讨论】:

  • 有点,但看起来它只是寻找第一个空闲的驱动器号来分配驱动器,我想总是将此 USB 分配给一个固定的驱动器号而不是下一个可用的字母

标签: batch-file batch-processing batch-rename


【解决方案1】:

您可以使用subst 来执行此操作:

subst T: %~d0\

只要你知道 T: 没有被使用。由于您正在为某个位置对 Java 程序进行硬编码,因此我认为这不是问题。

【讨论】:

    【解决方案2】:

    此批处理将搜索包含“密钥”文件或文件夹的驱动器,并将驱动器#:(是的,这是一个有效的驱动器号,并且很少与任何东西冲突)到正确的驱动器。只需在您的程序中使用驱动器#:。如果批处理文件在其工作中退出,errorlevel 将为 0,否则 errorlevel 将为 1

    @echo off
    
        setlocal enableextensions
    
        rem if our special drive is assigned, release it
        if exist #:\ subst #: /d >nul
    
        rem if there are problems, exit
        if errorlevel 1 goto endSearch
    
        rem search drives for "key" file/folder
        set "keyFile=\data\mySpecialFile.csv"
        for %%d in (z y x w v u t s r q p o n m l k j i h g f e d c b a) do (
            vol %%d: >nul 2>nul && if exist "%%d:%keyFile%" (
                rem map our drive
                subst #: %%d:\ > nul 2> nul
                rem if everything ok end search
                if not errorlevel 1 goto endSearch
            )
        )
    
    :endSearch
        rem cleanup and return errorcode as necessary
        endlocal && if exist "#:%keyFile%" ( exit /b 0 ) else (exit /b 1)
    

    【讨论】:

      猜你喜欢
      • 2023-03-02
      • 1970-01-01
      • 2011-03-24
      • 1970-01-01
      • 1970-01-01
      • 2013-01-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多