1.

Solve : Using .bat to move a file with an unknown file name?

Answer»

System: Win2k3 Server

We are receiving a nightly FTP upload to a specific directory. The file's name changes based on several criterion; none of which I have control over. Basically, the date is PART of the file name, but there are other numbers that appear pretty random from the filesystem perspective.

Anyway, I want to accomplish a couple of things:
1. copy the file to a network share (\\ipaddress\share)
2. MOVE the file to a local directory so it can be decrypted (pgp); the file WOULD be renamed in the move

I'm hoping to put this into a sheduled task in win2k3 so that I don't have to intervene. What I'm struggling with is how to work with a file that I don't know it's file name? I only know the extension, but I'm certain I need the file's name in order to perform the copy/move/rename operations.

Any suggestions?

Thanks,
JonCode: [Select]@ECHO off
for /f "tokens=* delims=" %%v in ('dir /s /b c:\specificdirectory') do (
copy "%%v" \\ipaddress\share
move "%%v" c:\localdirectory
ren "%%v" newname
)

You'll need to change the directory and newname placeholders.

Quote from: Sidewinder on May 09, 2008, 05:12:40 AM

Code: [Select]@echo off
for /f "tokens=* delims=" %%v in ('dir /s /b c:\specificdirectory') do (
copy "%%v" \\ipaddress\share
move "%%v" c:\localdirectory
ren "%%v" newname
)

You'll need to change the directory and newname placeholders.


Awesome! I changed it slightly:
Code: [Select]@echo off
for /f "tokens=* delims=" %%v in ('dir /s /b c:\path\to\file') do (
copy "%%v" \\192.168.1.111\path\to\archive\directory
move "%%v" "C:\path\to\local\staging\newfilename.extension"
)

Thanks for such a fast reply


Discussion

No Comment Found