Reputation: 13
Firstly i am still a beginner at scripting so please be gentle. I am creating a back up script and I want to be able to search network for part of a file name (which located on a networked External HDD for Backup use), then return the dir to use later to back up the contents of a USB device. The folder name I am searching for consists of 4 elements as follows: Date-1234567-Type-User. The part i am looking to search for is the 7 digit id number which is unique where as the other elements may be duplicated a number of times. the current script i have been using is not returning anything it is giving file not found, could someone point me in the right direction my script is as follows, also i am working on windows 7.
@echo off
:start
set /p path=enter id no.:
for /r %%# in (.) do (
Echo %%~nx# | find "string" "%path%" 1>NUL && (
Echo Full Path: %%~nx#
Echo Filename : %%~nx#
Echo Directory: %%~p#
)
)
if defined p (
echo %p%
) else ( Echo file not found
)
pause
goto backup
:backup
if not exist "%p%"\"usb download" md "%p%"\"usb download"
if exist (
xcopy /y "USB" "%p%"\usb download
)
pause
goto start
the Xcopy lines work on their own creating a new folder and copying the contents however i have to write the complete file path manually which is quite extensive and laborious so if i could automate this it would help dramatically. I thank you for your help in advance, I have googled and searched my heart out, but as I said I am a beginner and my brain is melting. thanks all.
Upvotes: 1
Views: 3588
Reputation:
for /f "delims=" %A in ('dir /ad /b /s z:\*1234567*') do echo %A
This should find it.
Upvotes: 2