?
Solved

Script to match and move Files and associated folder

Posted on 2007-10-16
10
Medium Priority
?
354 Views
Last Modified: 2013-12-01
Hello!

     I need some help, I need to be able by scripting to match a file "name.ext " and a folder "name" the description on the "name" is the same on the file and the folder, after I checked that I have the file and the folder on the following path "z:\products" I need to move this to a x:\backup folder.

To be able to monitor the files that have been modev to x:\backup i need to set a number of time that the script checks the files and folders.

Is this possible by script?
0
Comment
Question by:elburgundi666
  • 4
  • 4
9 Comments
 
LVL 9

Expert Comment

by:MSE-dwells
ID: 20089216
I'm having difficulty understanding what you want, can you give an example please.
0
 
LVL 1

Author Comment

by:elburgundi666
ID: 20089770
i.e. The folder x:\temp have several Subfolders and .DAT files that associated to the sub folder.
-temp
 -name1
 -name1.dat
 -name2
 - name2.dat
 - name3
 - name3.dat

What I'm looking for is to be able to match the "name1.dat" file  to the "name1" and if I have the two of them to move them in to a different folder.

What do you think?
0
 
LVL 9

Expert Comment

by:MSE-dwells
ID: 20093020
Is the name going to remain the same or similar or based on some known prefix or could it be anything at all?
0
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
LVL 1

Author Comment

by:elburgundi666
ID: 20094246
Hi!

   It can be anything, but it usually shows a 6 to 12 numbers on the name.

Thanks!
0
 
LVL 9

Expert Comment

by:MSE-dwells
ID: 20094422
So does the following adequately represent the required logic -

1. scan a given directory (not including its subdirectories) for all files
2. remove the extension from the filename and determine if a folder of that name exists in the same directory as the file
3. if so, move both the file and the folder to a different directory
0
 
LVL 1

Author Comment

by:elburgundi666
ID: 20095051
That's correct....
0
 
LVL 9

Accepted Solution

by:
MSE-dwells earned 200 total points
ID: 20095140
If you run the following one-liner having cd'd to the directory your interested in scanning, does it do what you want -

for /f "tokens=*" %D in ('dir /a-d /b') do @if exist "%~dpnD\" @echo move "%~dpnxD" [your target file here] && @echo move "%~dpnD" [your target folder here]

... copy the line verbatim (note, it's a single line command -- there's no line break in there) and running it from a suitable directory.  It won't do anything at this point, removing the echo prefix and replacing the obvious references with your specific directory structure will enable it.  If you decide to add it to a batch file, you must double the % symbols -

for /f "tokens=*" %%D in ('dir /a-d /b') do @if exist "%%~dpnD\" @echo move "%%~dpnxD" [your target file here] && @echo move "%%~dpnD" [your target folder here]
0
 
LVL 1

Author Comment

by:elburgundi666
ID: 20103226
Hello!

   How can we do this with all the files and folders on a specific folder?

Thanks!
0
 
LVL 1

Expert Comment

by:Computer101
ID: 20295185
Forced accept.

Computer101
EE Admin
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A Bare Metal Image backup allows for the restore of an entire system to a similar or dissimilar hardware. They are highly useful for migrations and disaster recovery. Bare Metal Image backups support Full and Incremental backups. Differential backup…
"Any files you do not have backed up in at least two [other] places are files you do not care about."
This tutorial will walk an individual through the steps necessary to enable the VMware\Hyper-V licensed feature of Backup Exec 2012. In addition, how to add a VMware server and configure a backup job. The first step is to acquire the necessary licen…
This tutorial will show how to configure a single USB drive with a separate folder for each day of the week. This will allow each of the backups to be kept separate preventing the previous day’s backup from being overwritten. The USB drive must be s…
Suggested Courses

750 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question