显示文本文件中任何文件的当前位置路径(带有斜线) [英] Display Current Location Path (with slashes) of any file in a text file

查看:88
本文介绍了显示文本文件中任何文件的当前位置路径(带有斜线)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望批处理文件自动找到名为"file.txt"的文件的位置. 我希望批处理文件精确地逐字打印,以斜杠斜杠打印,这是我计算机上存在的文件的路径!!我的主要想法是,无论我的计算机在哪里,批处理文件都必须能够找到该文件的位置.

I want a batch file to automatically find the location of a file called "file.txt". I want the batch file to print exactly word to word, slash to slash, the path of a file present on my computer!! My MAIN idea is that the file's location must be able to be found by the batch file irrespective of wherever it is on my computer.

例如,如果文件的目录路径为" C:\ users \ desktop \ folder \ file.txt ",则我希望批处理文件自动找到该文件,然后复制其路径并将其原样发送到另一个名为"location.txt"的文本文件.我希望这个问题现在很清楚!

For eg, if the directory path of the file is " C:\users\desktop\folder\file.txt ", I want the batch file to automatically find this file, copy its path and send it exactly as it is to another text file called say "location.txt". I HOPE THE QUESTION IS CLEAR NOW!!

但是我认为以下内容仅适用于批处理文件的当前目录路径,而不适用于其他任何文件.

But the following I think is only for current directory path of the batch file and not any other file.

@echo off
setlocal enabledelayedexpansion
set "mypath=%cd%"
set "stringtoreplace=toto"
(for /f "delims=" %%a in ('type test.txt') do (
set "content=%%a"
set "content=!content:%stringtoreplace%=%mypath%!"
echo !content!
))>output.txt

推荐答案

当我正确理解您的修改后,您会尝试查找文件(位置未知)并获取其实际位置.

When I understand your edit correctly, you try to find a file (with unknown location) and get its actual location.

以下内容将在C:\users\中查找文件file.txt及其子文件夹,并将列表写入output.txt:

The following will look for the file(s) file.txt in C:\users\ and it's subfolders amd write the list to output.txt:

dir /s /b "C:\users\file.txt" >output.txt

修改

要在系统上的任何位置"查找文件,必须在每个驱动器上进行搜索.

To find a file "wherever it is on the system", you have to search on each drive.

for /f "tokens=2 delims==:" %%a in ('wmic logicaldisk where "drivetype=3" get caption /value') do (
  dir /s /b "%%a:\file.txt" >>output.txt
)

(drivetype=3将是您的所有硬盘驱动器.如果您也想检查拇指驱动器,请再次添加同一行,但是将3更改为2(如果更改则将第三行替换为5您也必须检查CD驱动器))

(drivetype=3 would be all your hard drives. If you want to check thumb drives too, add the same line a second time, but change 3 to 2 (and a third line with 5 if you have to check CD-drives too))

这篇关于显示文本文件中任何文件的当前位置路径(带有斜线)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆