Mombu the Microsoft Forum

Go Back   Mombu the Microsoft Forum > Microsoft > move files
User Name
Password
REGISTER NOW! Mark Forums Read




Reply
1 25th October 16:22
doug howell
External User
 
Posts: 1
Default move files



I need a script that will check a given directory for .pdf and .xls
files that have exactly the same name. If a pair of .pdf and .xls
files with the same name are found, the script should move the .xls
file to another directory.

Any guidance would be appreciated.
  Reply With Quote


 


2 25th October 16:23
pegasus [mvp]
External User
 
Posts: 1
Default move files



You can easily do this with a humble batch file (see below). If you prefer a
VB Script then you should download the help file script56.chm from the
Microsoft site. It contains detailed examples for the "move" method of the
File System Object.

@echo off
set Source=D:\Fri 23
set Target=D:\Destination
if not exist "%Source%" echo Folder "%Source%" not found.
if not exist "%Target%" md "%Target%"
pushd "%Source%"
for %%a in (*.xls) do if exist "%%~na.pdf" move /Y "%%a" "%Target%"
popd
  Reply With Quote
Reply


Thread Tools
Display Modes




666