PDA

View Full Version : File Set Attributes using attrib



RobbyH
01-23-2003, 02:47 AM
I have a project that copies a bunch of files from the cd to a folder on the hard drive.

My problem is when it copies them, it puts the read only attribute on them. So, I wanted to change all of the attributes after they have been copied, but AMS will only do it one at a time. It says in the help file that I can use a file execute action to run the attrib command, and that I can use wildcards. I don't know much about the attrib command, but I tried to follow it's usage instructions, and didn't get anywhere. So my main questions are

1. What is the comand I would use to remove the read only attribute from all files in all folders contained in a folder?
Example attrib -r c:\games\Galactic Battlegrounds\*.* etc.
This is how I understood I should do it after reading the instructions when I typed attrib /? at the command prompt like the help suggested.
2. How do I run the attrib command from the file execute action, and where does all the -r /s etc. stuff go?
3. Can I use a variable in the path to the folder?

I checked a bunch of dos help sites, and tried all of their examples, but could not get it to work.

Thanks
Rob

RobbyH
01-23-2003, 05:12 AM
Ok, a short update
using my command line, I figured out how to use the attrib command. I have gotten it to work. Now I just need to know how to run the same command (attrib -r c:\folder\folder\*.* /s) from within autoplay, using a variable for the drive & path.
Anybody got any ideas?

kpsmith
01-23-2003, 07:17 AM
This seems to work but not if there are spaces in the directory Path. Not sure about long file names either. Just copy whats below and paste in your project:

<IR_CB_OBJECTS>
<SourcePageName>Start</SourcePageName>
<Object>
<Type>1</Type>
<Name>Text1</Name>
<VisibleAtDesignTime>1</VisibleAtDesignTime>
<VisibleAtRunTime>1</VisibleAtRunTime>
<Locked>0</Locked>
<LockSize>0</LockSize>
<ToolTip/>
<Cursor>1</Cursor>
<Coordinates>
<Top>205</Top>
<Bottom>229</Bottom>
<Left>233</Left>
<Right>325</Right>
</Coordinates>
<Hotkey>
<VirtualKey>0</VirtualKey>
<Modifiers>0</Modifiers>
</Hotkey>
<Event>
<Name>On Mouse Over</Name>
</Event>
<Event>
<Name>On Mouse Leave</Name>
</Event>
<Event>
<Name>On Mouse Click</Name>
<Action name="Set Value">
<Type>6</Type>
<Function>0</Function>
<DTIndentLevel>0</DTIndentLevel>
<Enabled>1</Enabled>
<ErrorHandling>
<UserNotificationMode>2</UserNotificationMode>
<CustomErrorMessage/>
<OnErrorAction>0</OnErrorAction>
<JumpToLabel/>
</ErrorHandling>
<Variable>%dirpath%</Variable>
<Value>C:\Test</Value>
<Evaluate>0</Evaluate>
</Action>
<Action name="Execute">
<Type>8</Type>
<Function>0</Function>
<DTIndentLevel>0</DTIndentLevel>
<Enabled>1</Enabled>
<ErrorHandling>
<UserNotificationMode>2</UserNotificationMode>
<CustomErrorMessage/>
<OnErrorAction>0</OnErrorAction>
<JumpToLabel/>
</ErrorHandling>
<FileName>attrib.exe</FileName>
<CommandLine>-r %dirpath%\*.* /s</CommandLine>
<WorkingDir/>
<RunMode>0</RunMode>
<WaitForReturn>0</WaitForReturn>
</Action>
</Event>
<Text>
<Body>attributes</Body>
<NormalColor format="decimal">0</NormalColor>
<HighlightColor format="decimal">16711680</HighlightColor>
<MouseDownColor format="decimal">255</MouseDownColor>
<FontName>Arial</FontName>
<StyleName>Regular</StyleName>
<CharacterSet>0</CharacterSet>
<Height>24</Height>
<Weight>400</Weight>
<Italic>0</Italic>
<Underline>0</Underline>
<StrikeOut>0</StrikeOut>
<Alignment>0</Alignment>
<AntiAlias>1</AntiAlias>
<VerticalCenter>0</VerticalCenter>
<MouseOverSound/>
<MouseOverIsExternal>0</MouseOverIsExternal>
<MouseClickSound/>
<MouseClickIsExternal>0</MouseClickIsExternal>
</Text>
</Object>
</IR_CB_OBJECTS>

Brett
01-23-2003, 07:22 AM
Just use the File.SetAttributes action in AMS. That is exactly what it is there for.

kpsmith
01-23-2003, 02:39 PM
RobbyH wanted to use a wildcard to set the Attributes for mutiple files in a folder in one action.

According to the AMS4 Help documentation the SetAttrib Action doesn't support Wildcards.

Of course I didn't try it ..... Maybe I should.

kaylward
02-07-2003, 07:11 AM
You could use a While loop to execute the File.SetAttributes command. See the "Searching the desktop for text files" help topic for an example of a while loop that processes a set of files. It's the "clean" way to programatically do this task. Should work just fine.

Lorne
02-07-2003, 09:14 AM
It will work fine using the File - Execute action.

File to execute: attrib.exe

(or %SysDir%\attrib.exe to make it slightly faster)

Command line arguments: -r "%dirpath%\*.*" /s

(Note the quotes.)

Replace %dirpath% with whatever variable the path is in...

RobbyH
02-07-2003, 07:59 PM
Lorne, your idea worked best. I considered the others, as they all would work, but using a .bat file was the easiest for a couple reasons.
1. If the .bat file is in the main folder of all the files that need the attributes set, it takes only three simple lines.
attrib -r *.* /s
cls
@exit
2. does not have to go into a lengthly loop if you have lots of
files
Couple of things to remember. If you are running windows 2000, and it tells you proper attrib usage can include /d, don't do it, doesn't work on machines running win98, and maybe others. Also, if you have AMS set to wait for the .bat file to finish before continuing, remember to put in the close command, or your user may be sitting there a long time before they figure out they need to close the dos window(s). Again, this seems to be a win98 thing, my win 2000, closes these windows automatically.
Rob